diff options
author | mksh <mkulish@atlassian.com> | 2015-11-20 19:04:17 +0200 |
---|---|---|
committer | mksh <mkulish@atlassian.com> | 2015-11-20 19:04:17 +0200 |
commit | eeba6ccbf9216e31a15de1b670c8e9f966c3bf1d (patch) | |
tree | b9761e6d0408161446e3e84b1e82af3746df530b /src/net/java/sip/communicator | |
parent | 53907a91343d266830117f8e55486d0741332760 (diff) | |
download | jitsi-eeba6ccbf9216e31a15de1b670c8e9f966c3bf1d.zip jitsi-eeba6ccbf9216e31a15de1b670c8e9f966c3bf1d.tar.gz jitsi-eeba6ccbf9216e31a15de1b670c8e9f966c3bf1d.tar.bz2 |
Implemented program name property loading from logging.properties file and prepending it to each log message in case of existence
Diffstat (limited to 'src/net/java/sip/communicator')
-rw-r--r-- | src/net/java/sip/communicator/util/ScLogFormatter.java | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/net/java/sip/communicator/util/ScLogFormatter.java b/src/net/java/sip/communicator/util/ScLogFormatter.java index ad2129b..7ecb389 100644 --- a/src/net/java/sip/communicator/util/ScLogFormatter.java +++ b/src/net/java/sip/communicator/util/ScLogFormatter.java @@ -33,11 +33,43 @@ import java.util.logging.*; public class ScLogFormatter extends java.util.logging.Formatter { + + /** + * Program name logging property name + */ + private static final String PROGRAM_NAME_PROPERTY = ".programname"; + + + /** + * Line separator used by current platform + */ private static String lineSeparator = System.getProperty("line.separator"); + + /** + * Two digit <tt>DecimalFormat</tt> instance, used to format datetime + */ private static DecimalFormat twoDigFmt = new DecimalFormat("00"); + + /** + * Three digit <tt>DecimalFormat</tt> instance, used to format datetime + */ private static DecimalFormat threeDigFmt = new DecimalFormat("000"); /** + * The application name used to generate this log + */ + private static String programName; + + /** + * The default constructor for <tt>ScLogFormatter</tt> which loads + * program name property from logging.properties file, if it exists + */ + public ScLogFormatter() + { + loadProgramNameProperty(); + } + + /** * Format the given LogRecord. * @param record the log record to be formatted. * @return a formatted log record @@ -46,6 +78,15 @@ public class ScLogFormatter public synchronized String format(LogRecord record) { StringBuffer sb = new StringBuffer(); + + + if (programName != null) + { + // Program name + sb.append(programName); + + sb.append(' '); + } //current time Calendar cal = Calendar.getInstance(); @@ -146,7 +187,8 @@ public class ScLogFormatter } ix++; } - // Now search for the first frame before the SIP Communicator Logger class. + // Now search for the first frame + // before the SIP Communicator Logger class. while (ix < stack.length) { StackTraceElement frame = stack[ix]; @@ -164,4 +206,16 @@ public class ScLogFormatter return lineNumber; } + + /** + * Load the programname property to be used in logs to identify Jitsi-based + * application which produced the logs + */ + private void loadProgramNameProperty() + { + LogManager manager = LogManager.getLogManager(); + String cname = this.getClass().getName(); + programName = manager.getProperty(cname + PROGRAM_NAME_PROPERTY); + } + } |