Skip to content

Commit

Permalink
Upgrade to Logback 1.4.13 #66
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Nov 30, 2023
1 parent a22c126 commit 5f18412
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 48 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0-M3

* #66 Upgrade to Logback 1.4.13

## 3.0.M2

* #63 Upgrade Logback to 1.4.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,68 +28,84 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.bootique.annotation.BQConfig;
import io.bootique.annotation.BQConfigProperty;
import io.bootique.value.Duration;

/**
* A factory that can be used to setup "fixed window" log rolling policy. The
* policy is triggered by the main log file reaching a certain size and will
* keep up to "historySize" rotated files. Follow the logback link below for
* file name pattern rules, etc.
*
*
* @see <a href=
* "http://logback.qos.ch/manual/appenders.html#FixedWindowRollingPolicy">
* Logback documentation</a>
* "http://logback.qos.ch/manual/appenders.html#FixedWindowRollingPolicy">
* Logback documentation</a>
*/
@JsonTypeName("fixedWindow")
@BQConfig
public class FixedWindowPolicyFactory extends RollingPolicyFactory {

private String fileSize;
private String fileSize;
private Duration checkIncrement;

/**
* Sets a maximum size of a single log file. Exceeding this size causes
* rotation.
*
* @param fileSize maximum size of a single log file expressed in bytes,
* kilobytes, megabytes or gigabytes by suffixing a numeric value
* with KB, MB and respectively GB. For example: 5000000, 5000KB,
* 5MB and 2GB.
*/
// TODO: convert to Bytes value object from String
@BQConfigProperty
public void setFileSize(String fileSize) {
this.fileSize = fileSize;
}

/**
* @since 3.0
*/
@BQConfigProperty
public void setCheckIncrement(Duration checkIncrement) {
this.checkIncrement = checkIncrement;
}

@Override
protected FixedWindowRollingPolicy instantiatePolicy(LoggerContext context) {
FixedWindowRollingPolicy policy = new FixedWindowRollingPolicy();
policy.setFileNamePattern(getFileNamePattern());
if (getHistorySize() > 0) {
policy.setMinIndex(1);
policy.setMaxIndex(getHistorySize());
}
policy.setContext(context);
return policy;
}

@Override
public TriggeringPolicy<ILoggingEvent> createTriggeringPolicy(LoggerContext context) {
SizeBasedTriggeringPolicy<ILoggingEvent> policy = new SizeBasedTriggeringPolicy<ILoggingEvent>();

/**
* Sets a maximum size of a single log file. Exceeding this size causes
* rotation.
*
* @param fileSize
* maximum size of a single log file expressed in bytes,
* kilobytes, megabytes or gigabytes by suffixing a numeric value
* with KB, MB and respectively GB. For example: 5000000, 5000KB,
* 5MB and 2GB.
*/
@BQConfigProperty
public void setFileSize(String fileSize) {
this.fileSize = fileSize;
}
if (fileSize != null && fileSize.length() > 0) {
policy.setMaxFileSize(FileSize.valueOf(fileSize));
}

@Override
protected FixedWindowRollingPolicy instantiatePolicy(LoggerContext context) {
FixedWindowRollingPolicy policy = new FixedWindowRollingPolicy();
policy.setFileNamePattern(getFileNamePattern());
if (getHistorySize() > 0) {
policy.setMinIndex(1);
policy.setMaxIndex(getHistorySize());
}
policy.setContext(context);
return policy;
}
if (checkIncrement != null) {
policy.setCheckIncrement(new ch.qos.logback.core.util.Duration(checkIncrement.getDuration().toMillis()));
}

@Override
public TriggeringPolicy<ILoggingEvent> createTriggeringPolicy(LoggerContext context) {
SizeBasedTriggeringPolicy<ILoggingEvent> policy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
if (fileSize != null && fileSize.length() > 0) {
policy.setMaxFileSize(FileSize.valueOf(fileSize));
}
policy.setContext(context);
return policy;
}
policy.setContext(context);
return policy;
}

@Override
protected FileNamePatternValidator getFileNamePatternValidator(LoggerContext context) {
@Override
protected FileNamePatternValidator getFileNamePatternValidator(LoggerContext context) {

return new FileNamePatternValidator(context, getFileNamePattern(), FixedWindowRollingPolicy.class.getSimpleName()) {
@Override
protected void validate() {
checkPattern(false, true);
}
};
}
return new FileNamePatternValidator(context, getFileNamePattern(), FixedWindowRollingPolicy.class.getSimpleName()) {
@Override
protected void validate() {
checkPattern(false, true);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ log:
fileNamePattern: "target/logs/logfile-%i.log"
historySize: 2
fileSize: 20
checkIncrement: 50ms
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<properties>
<bootique.version>${project.version}</bootique.version>
<logback.version>1.4.5</logback.version>
<logback.version>1.4.13</logback.version>
<logback.sentry.version>5.5.2</logback.sentry.version>
<logback.contrib.version>0.1.5</logback.contrib.version>
</properties>
Expand Down

0 comments on commit 5f18412

Please sign in to comment.