Skip to content

Commit

Permalink
HousekeepingFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
albertus82 committed Apr 14, 2024
1 parent ff119f6 commit 01bd012
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.albertus82.util.logging;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Observable;
Expand All @@ -25,20 +24,6 @@ public class HousekeepingFilter extends Observable implements Filter {

private String currentFileNamePart;

private final ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>() {
@Override
protected DateFormat initialValue() {
try {
return new SimpleDateFormat(datePattern);
}
catch (final RuntimeException e) {
final String defaultDatePattern = TimeBasedRollingFileHandlerConfig.DEFAULT_DATE_PATTERN;
log.log(Level.WARNING, JFaceMessages.get("err.logging.housekeeping.datePattern", datePattern, defaultDatePattern), e);
return new SimpleDateFormat(defaultDatePattern);
}
}
};

public HousekeepingFilter(final ILogFileManager logFileManager, final int maxHistory) {
this(logFileManager, maxHistory, TimeBasedRollingFileHandlerConfig.DEFAULT_DATE_PATTERN);
}
Expand All @@ -52,13 +37,14 @@ public HousekeepingFilter(final ILogFileManager logFileManager, final int maxHis
else {
this.maxHistory = maxHistory;
}
new SimpleDateFormat(datePattern); // Enforce pattern validity
this.datePattern = datePattern;
log.log(Level.FINE, "Created new {0}", this);
}

@Override
public boolean isLoggable(final LogRecord rec) {
final String newFileNamePart = dateFormat.get().format(new Date());
final String newFileNamePart = new SimpleDateFormat(datePattern).format(new Date());
if (!newFileNamePart.equals(currentFileNamePart)) {
int keep = this.maxHistory;
if (currentFileNamePart == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ err.delete.temp=Cannot delete temporary file \u0022{0}\u0022.
err.date.parse=Cannot parse date.
err.load.file=Cannot load file \u0022{0}\u0022.
err.cocoa.enhancer.platform=Cocoa platform not detected!
err.logging.housekeeping.datePattern=The provided datePattern argument \u0022{0}\u0022 is not a valid DateFormat pattern. Using default pattern: \u0022{1}\u0022.
err.logging.housekeeping.maxHistory=The maxHistory argument must be greather than zero. Applied the minimum allowed value ({0}).
msg.httpserver.bad.method=Method not allowed
msg.httpserver.request.headers=Request headers: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ err.delete.temp=No se puede borrar el fichero temporal \u0022{0}\u0022.
err.date.parse=No se puede parsear la fecha.
err.load.file=No se puede cargar el fichero \u0022{0}\u0022.
err.cocoa.enhancer.platform=La plataforma Cocoa no se ha detectado!
err.logging.housekeeping.datePattern=El patr\u00F3n para la fecha que se ha dado \u0022{0}\u0022 no es un patr\u00F3n v\u00E1lido. Se usar\u00E1 el patr\u00F3n por defecto: \u0022{1}\u0022.
err.logging.housekeeping.maxHistory=El argumento \u0022maxHistory\u0022 debe ser m\u00E1s grande que cero. Se aplica el m\u00EDnimo valor permitido ({0}).
msg.httpserver.bad.method=M\u00E9todo no permitido
msg.httpserver.request.headers=Requiriendo cabeceras: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ err.delete.temp=Impossibile eliminare il file temporaneo \u0022{0}\u0022.
err.date.parse=Impossibile decodificare la data.
err.load.file=Impossibile caricare il file \u0022{0}\u0022.
err.cocoa.enhancer.platform=Piattaforma Cocoa non rilevata!
err.logging.housekeeping.datePattern=Il parametro datePattern fornito \u0022{0}\u0022 non \u00E8 un pattern DateFormat valido. Applicato pattern predefinito: \u0022{1}\u0022.
err.logging.housekeeping.maxHistory=Il parametro maxHistory deve essere maggiore di zero. Applicato valore minimo consentito ({0}).
msg.httpserver.bad.method=Metodo non consentito
msg.httpserver.request.headers=Header richiesta: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public abstract class ScrollableConsoleExample<T extends Scrollable> {
};
// @formatter:on

@SuppressWarnings("java:S2925")
protected void run() {
final Display display = Display.getDefault();

Expand Down

0 comments on commit 01bd012

Please sign in to comment.