Skip to content

Commit

Permalink
Allow auto-update check period to be customized with system property.
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoathaydes committed Apr 11, 2020
1 parent 5b15196 commit b8cacc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/main/java/com/athaydes/logfx/config/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class Properties {

public static final Path LOGFX_DIR;
public static final long UPDATE_CHECK_PERIOD_MS;

private static volatile LogLevel logLevel = null;
private static volatile LogTarget logTarget = null;
Expand Down Expand Up @@ -51,7 +52,8 @@ public class Properties {
logLevel = LogLevel.valueOf( logLevelValue.trim().toUpperCase() );
} catch ( IllegalArgumentException e ) {
System.err.println( "Invalid value for 'logfx.log.level' system property: " + logLevelValue );
System.err.println( "Valid values for 'logfx.log.level' are: TRACE, DEBUG, INFO (default), WARN, ERROR" );
System.err.println( "Valid values for 'logfx.log.level' are: TRACE, DEBUG, INFO (default), WARN, " +
"ERROR" );
}
}

Expand All @@ -76,6 +78,18 @@ public class Properties {

customStylesheet = System.getProperty( "logfx.stylesheet.file" );
refreshStylesheet = System.getProperty( "logfx.stylesheet.norefresh" ) == null;

String autoUpdatePeriod = System.getProperty( "logfx.auto_update.check_period" );
Long autoUpdatePeriodMs = null;
if ( autoUpdatePeriod != null ) {
try {
autoUpdatePeriodMs = Long.parseLong( autoUpdatePeriod );
} catch ( NumberFormatException e ) {
System.err.printf( "Invalid value for system property logfx.auto_update.check_period: %s (%s)\n",
autoUpdatePeriod, e.toString() );
}
}
UPDATE_CHECK_PERIOD_MS = autoUpdatePeriodMs == null ? 24 * 60 * 60 * 1000 : autoUpdatePeriodMs;
}

public static Optional<LogLevel> getLogLevel() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/athaydes/logfx/update/LogFXUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public final class LogFXUpdater {
private static final Logger log = LoggerFactory.getLogger( LogFXUpdater.class );
private static final long UPDATE_CHECK_PERIOD_MS = 24 * 60 * 60 * 1000;

private static final String LOGFX_UPDATE_CHECK = "logfx-update-check";

public static final String LOGFX_UPDATE_ZIP = "logfx-update.zip";
Expand Down Expand Up @@ -118,7 +118,7 @@ private static boolean shouldCheckForUpdates() {
} catch ( IOException e ) {
log.warn( "Could not update logfx-update-check file timestamp" );
}
return now - lastCheck > UPDATE_CHECK_PERIOD_MS;
return now - lastCheck > Properties.UPDATE_CHECK_PERIOD_MS;
} else {
log.info( "Creating logfx-update-check file. Will check for LogFX updates daily." );
try {
Expand Down

0 comments on commit b8cacc6

Please sign in to comment.