Skip to content

Commit 4085c4a

Browse files
Add configuration property for 'excludecategories' (#133)
Fixes #118
1 parent f7c07b5 commit 4085c4a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ decorator.datasource.p6spy.log-file=spy.log
116116
# Class file to use (only with logging=custom). The class must implement com.p6spy.engine.spy.appender.FormattedLogger
117117
decorator.datasource.p6spy.custom-appender-class=my.custom.LoggerClass
118118
# Custom log format, if specified com.p6spy.engine.spy.appender.CustomLineFormat will be used with this log format
119+
# see https://p6spy.readthedocs.io/en/latest/configandusage.html#customlogmessageformat
119120
decorator.datasource.p6spy.log-format=
120121
# Use regex pattern to filter log messages. If specified only matched messages will be logged.
121122
decorator.datasource.p6spy.log-filter.pattern=
123+
# Exclude certain categories from logging. If specified only matched messages will be logged.
124+
# see https://p6spy.readthedocs.io/en/latest/configandusage.html#excludecategories
125+
decorator.datasource.p6spy.exclude-categories=
122126
```
123127

124128
Also you can configure P6Spy manually using one of available configuration methods. For more information please refer to the [P6Spy Configuration Guide](http://p6spy.readthedocs.io/en/latest/configandusage.html)

datasource-decorator-spring-boot-autoconfigure/src/main/java/com/github/gavlyukovskiy/boot/jdbc/decorator/p6spy/P6SpyConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ else if (p6spy.isMultiline()) {
103103
if (!initialP6SpyOptions.containsKey("logfile")) {
104104
System.setProperty("p6spy.config.logfile", p6spy.getLogFile());
105105
}
106+
if (!p6spy.getExcludeCategories().isEmpty()) {
107+
System.setProperty("p6spy.config.excludecategories", String.join(",", p6spy.getExcludeCategories()));
108+
}
106109
if (p6spy.getLogFilter().getPattern() != null) {
107110
System.setProperty("p6spy.config.filter", "true");
108111
System.setProperty("p6spy.config.sqlexpression", p6spy.getLogFilter().getPattern().pattern());

datasource-decorator-spring-boot-autoconfigure/src/main/java/com/github/gavlyukovskiy/boot/jdbc/decorator/p6spy/P6SpyProperties.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.github.gavlyukovskiy.boot.jdbc.decorator.p6spy;
1818

19+
import java.util.ArrayList;
20+
import java.util.List;
1921
import java.util.regex.Pattern;
2022

2123
/**
@@ -45,6 +47,8 @@ public class P6SpyProperties {
4547
private String logFile = "spy.log";
4648
/**
4749
* Custom log format.
50+
*
51+
* @see <a href="https://p6spy.readthedocs.io/en/latest/configandusage.html#customlogmessageformat">P6Spy / customLogMessageFormat</a>
4852
*/
4953
private String logFormat;
5054

@@ -59,6 +63,13 @@ public class P6SpyProperties {
5963
*/
6064
private P6SpyLogFilter logFilter = new P6SpyLogFilter();
6165

66+
/**
67+
* Exclude categories from logging.
68+
*
69+
* @see <a href="https://p6spy.readthedocs.io/en/latest/configandusage.html#excludecategories">P6Spy / excludecategories</a>
70+
*/
71+
private List<String> excludeCategories = new ArrayList<>();
72+
6273
public boolean isEnableLogging() {
6374
return this.enableLogging;
6475
}
@@ -115,6 +126,14 @@ public void setLogFilter(P6SpyLogFilter logFilter) {
115126
this.logFilter = logFilter;
116127
}
117128

129+
public List<String> getExcludeCategories() {
130+
return excludeCategories;
131+
}
132+
133+
public void setExcludeCategories(List<String> excludeCategories) {
134+
this.excludeCategories = excludeCategories;
135+
}
136+
118137
public enum P6SpyLogging {
119138
SYSOUT,
120139
SLF4J,

0 commit comments

Comments
 (0)