# HG changeset patch # User Jiri Vanek # Date 1445948573 -3600 # Node ID 8bbb1c9daa4dcc838394ffeea1673dc4263a591c # Parent 33bca916e032505cb26405d81fb53777556e13b6 Added and by default disabled logging to files for client applications. diff -r 33bca916e032 -r 8bbb1c9daa4d ChangeLog --- a/ChangeLog Tue Oct 27 11:02:45 2015 +0100 +++ b/ChangeLog Tue Oct 27 13:22:53 2015 +0100 @@ -1,3 +1,20 @@ +2015-10-27 Jiri Vanek + + Added and by default disabled logging to files for client applications. + * netx/net/sourceforge/jnlp/config/Defaults.java: KEY_ENABLE_APPLICATION_LOGGING_TOFILE + added and set by default to false + * netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java: declared + KEY_ENABLE_APPLICATION_LOGGING_TOFILE + * netx/net/sourceforge/jnlp/util/logging/FileLog.java: next to createFileLog + can now does also createAppFileLog + * netx/net/sourceforge/jnlp/util/logging/LogConfig.java: made aware of + KEY_ENABLE_APPLICATION_LOGGING_TOFILE + * netx/net/sourceforge/jnlp/util/logging/OutputController.java: if logging + to file is enabled and logging to file for client applications is enabled + then output of client app is sent also to special file. Added new singleton of + AppFileLogHolder to keep instance of file log for client app. proceedHeader + extracted as separate method to be reused. + 2015-10-15 Jiri Vanek Added to enable and write logs directly to file without java.util.logging diff -r 33bca916e032 -r 8bbb1c9daa4d netx/net/sourceforge/jnlp/config/Defaults.java --- a/netx/net/sourceforge/jnlp/config/Defaults.java Tue Oct 27 11:02:45 2015 +0100 +++ b/netx/net/sourceforge/jnlp/config/Defaults.java Tue Oct 27 13:22:53 2015 +0100 @@ -339,6 +339,11 @@ BasicValueValidators.getBooleanValidator(), String.valueOf(false) }, + { + DeploymentConfiguration.KEY_ENABLE_APPLICATION_LOGGING_TOFILE, + BasicValueValidators.getBooleanValidator(), + String.valueOf(false) + }, { DeploymentConfiguration.KEY_ENABLE_LEGACY_LOGBASEDFILELOG, BasicValueValidators.getBooleanValidator(), diff -r 33bca916e032 -r 8bbb1c9daa4d netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java --- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java Tue Oct 27 11:02:45 2015 +0100 +++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java Tue Oct 27 13:22:53 2015 +0100 @@ -178,7 +178,8 @@ public static final String KEY_ENABLE_LOGGING = "deployment.log"; //same as verbose or ICEDTEAPLUGIN_DEBUG=true public static final String KEY_ENABLE_LOGGING_HEADERS = "deployment.log.headers"; //will add header OutputContorll.getHeader To all messages public static final String KEY_ENABLE_LOGGING_TOFILE = "deployment.log.file"; - public static final String KEY_ENABLE_LEGACY_LOGBASEDFILELOG = "deployment.log.file.legacylog"; + public static final String KEY_ENABLE_APPLICATION_LOGGING_TOFILE ="deployment.log.file.clientapp"; //also client app will log to its separate file + public static final String KEY_ENABLE_LEGACY_LOGBASEDFILELOG = "deployment.log.file.legacylog"; public static final String KEY_ENABLE_LOGGING_TOSTREAMS = "deployment.log.stdstreams"; public static final String KEY_ENABLE_LOGGING_TOSYSTEMLOG = "deployment.log.system"; diff -r 33bca916e032 -r 8bbb1c9daa4d netx/net/sourceforge/jnlp/util/logging/FileLog.java --- a/netx/net/sourceforge/jnlp/util/logging/FileLog.java Tue Oct 27 11:02:45 2015 +0100 +++ b/netx/net/sourceforge/jnlp/util/logging/FileLog.java Tue Oct 27 13:22:53 2015 +0100 @@ -73,14 +73,22 @@ public static final SimpleDateFormat pluginSharedFormatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZ yyyy"); public static final String defaultloggerName = TextsProvider.ITW + " file-logger"; + + public static SingleStreamLogger createFileLog() { + return createFileLog("javantx"); + } - public static SingleStreamLogger createFileLog() { + public static SingleStreamLogger createAppFileLog() { + return createFileLog("clienta"); + } + + private static SingleStreamLogger createFileLog(String id) { SingleStreamLogger s; try { - if (LogConfig.getLogConfig().isLegacyLogBasedFileLog()){ - s = new LogBasedFileLog(defaultloggerName, getFileName(), false); + if (LogConfig.getLogConfig().isLegacyLogBasedFileLog()) { + s = new LogBasedFileLog(defaultloggerName, getFileName(id), false); } else { - s = new WriterBasedFileLog(defaultloggerName, getFileName(), false); + s = new WriterBasedFileLog(defaultloggerName, getFileName(id), false); } } catch (Exception ex) { //we do not wont to block whole logging just because initialization error in "new FileLog()" @@ -90,8 +98,8 @@ return s; } - private static String getFileName() { - return LogConfig.getLogConfig().getIcedteaLogDir() + "itw-javantx-" + getStamp() + ".log"; + private static String getFileName(String id) { + return LogConfig.getLogConfig().getIcedteaLogDir() + "itw-"+id+"-" + getStamp() + ".log"; } diff -r 33bca916e032 -r 8bbb1c9daa4d netx/net/sourceforge/jnlp/util/logging/LogConfig.java --- a/netx/net/sourceforge/jnlp/util/logging/LogConfig.java Tue Oct 27 11:02:45 2015 +0100 +++ b/netx/net/sourceforge/jnlp/util/logging/LogConfig.java Tue Oct 27 13:22:53 2015 +0100 @@ -52,6 +52,7 @@ private boolean enableLogging; private boolean enableHeaders; private boolean logToFile; + private boolean logClientAppToFile; private boolean logToStreams; private boolean logToSysLog; private boolean legacyLogaAsedFileLog; @@ -67,6 +68,7 @@ logToStreams = Boolean.parseBoolean(config.getProperty(DeploymentConfiguration.KEY_ENABLE_LOGGING_TOSTREAMS)); logToSysLog = Boolean.parseBoolean(config.getProperty(DeploymentConfiguration.KEY_ENABLE_LOGGING_TOSYSTEMLOG)); legacyLogaAsedFileLog = Boolean.parseBoolean(config.getProperty(DeploymentConfiguration.KEY_ENABLE_LEGACY_LOGBASEDFILELOG)); + logClientAppToFile = Boolean.parseBoolean(config.getProperty(DeploymentConfiguration.KEY_ENABLE_APPLICATION_LOGGING_TOFILE)); // Get log directory, create it if it doesn't exist. If unable to create and doesn't exist, don't log. icedteaLogDir = PathsAndFiles.LOG_DIR.getFullPath(); @@ -161,4 +163,12 @@ return legacyLogaAsedFileLog = b; } + void serLogToFileForClientApp(boolean b) { + logClientAppToFile = b; + } + + boolean isLogToFileForClientApp() { + return logClientAppToFile; + } + } diff -r 33bca916e032 -r 8bbb1c9daa4d netx/net/sourceforge/jnlp/util/logging/OutputController.java --- a/netx/net/sourceforge/jnlp/util/logging/OutputController.java Tue Oct 27 11:02:45 2015 +0100 +++ b/netx/net/sourceforge/jnlp/util/logging/OutputController.java Tue Oct 27 13:22:53 2015 +0100 @@ -102,8 +102,8 @@ private static final String NULL_OBJECT = "Trying to log null object"; private PrintStreamLogger outLog; private PrintStreamLogger errLog; - private List messageQue = new LinkedList(); - private MessageQueConsumer messageQueConsumer = new MessageQueConsumer(); + private final List messageQue = new LinkedList<>(); + private final MessageQueConsumer messageQueConsumer = new MessageQueConsumer(); Thread consumerThread; //bounded to instance @@ -150,6 +150,9 @@ } //clients app's messages are reprinted only to console if (s.getHeader().isClientApp){ + if (LogConfig.getLogConfig().isLogToFile() && LogConfig.getLogConfig().isLogToFileForClientApp()) { + getAppFileLog().log(proceedHeader(s)); + } return; } if (!JNLPRuntime.isDebug() && (s.getHeader().level == Level.MESSAGE_DEBUG @@ -159,14 +162,7 @@ //must be here to prevent deadlock, casued by exception form jnlpruntime, loggers or configs themselves return; } - String message = s.getMessage(); - if (LogConfig.getLogConfig().isEnableHeaders()) { - if (message.contains("\n")) { - message = s.getHeader().toString() + "\n" + message; - } else { - message = s.getHeader().toString() + " " + message; - } - } + String message = proceedHeader(s); if (LogConfig.getLogConfig().isLogToStreams()) { if (s.getHeader().level.isOutput()) { outLog.log(message); @@ -189,6 +185,18 @@ } + private String proceedHeader(MessageWithHeader s) { + String message = s.getMessage(); + if (LogConfig.getLogConfig().isEnableHeaders()) { + if (message.contains("\n")) { + message = s.getHeader().toString() + "\n" + message; + } else { + message = s.getHeader().toString() + " " + message; + } + } + return message; + } + private OutputController() { this(System.out, System.err); } @@ -339,6 +347,18 @@ private SingleStreamLogger getFileLog() { return FileLogHolder.INSTANCE; } + + + private static class AppFileLogHolder { + + //https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java + //https://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom + private static volatile SingleStreamLogger INSTANCE = FileLog.createAppFileLog(); + } + + private SingleStreamLogger getAppFileLog() { + return AppFileLogHolder.INSTANCE; + } private static class SystemLogHolder { @@ -398,6 +418,10 @@ void setFileLog(SingleStreamLogger fileLog) { FileLogHolder.INSTANCE = fileLog; } + + void setAppFileLog(SingleStreamLogger fileLog) { + AppFileLogHolder.INSTANCE = fileLog; + } void setOutLog(PrintStreamLogger outLog) { this.outLog = outLog;