LOGGING-148 - LogFactory.diagnosticPrefix and diagnosticsStream could be final
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/logging/trunk@1363177 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -23,6 +23,7 @@ LOGGING-145 - LogFactoryImpl.setAttribute - possible NPE
|
|||||||
LOGGING-142 - Log4JLogger uses deprecated static members of Priority such as INFO
|
LOGGING-142 - Log4JLogger uses deprecated static members of Priority such as INFO
|
||||||
LOGGING-128 - Static analysis suggests a number of potential improvements
|
LOGGING-128 - Static analysis suggests a number of potential improvements
|
||||||
LOGGING-147 - SimpleLog.log - unsafe update of shortLogName
|
LOGGING-147 - SimpleLog.log - unsafe update of shortLogName
|
||||||
|
LOGGING-148 - LogFactory.diagnosticPrefix and diagnosticsStream could be final
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public abstract class LogFactory {
|
|||||||
* logDiagnostic method, so that users can clearly see which
|
* logDiagnostic method, so that users can clearly see which
|
||||||
* LogFactory class is generating the output.
|
* LogFactory class is generating the output.
|
||||||
*/
|
*/
|
||||||
private static String diagnosticPrefix;
|
private static final String diagnosticPrefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Setting this system property
|
* <p>Setting this system property
|
||||||
@@ -1587,55 +1587,33 @@ public abstract class LogFactory {
|
|||||||
* output by setting the system property named {@link #DIAGNOSTICS_DEST_PROPERTY} to
|
* output by setting the system property named {@link #DIAGNOSTICS_DEST_PROPERTY} to
|
||||||
* a filename, or the special values STDOUT or STDERR.
|
* a filename, or the special values STDOUT or STDERR.
|
||||||
*/
|
*/
|
||||||
private static void initDiagnostics() {
|
private static PrintStream initDiagnostics() {
|
||||||
String dest;
|
String dest;
|
||||||
try {
|
try {
|
||||||
dest = getSystemProperty(DIAGNOSTICS_DEST_PROPERTY, null);
|
dest = getSystemProperty(DIAGNOSTICS_DEST_PROPERTY, null);
|
||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
} catch(SecurityException ex) {
|
} catch(SecurityException ex) {
|
||||||
// We must be running in some very secure environment.
|
// We must be running in some very secure environment.
|
||||||
// We just have to assume output is not wanted..
|
// We just have to assume output is not wanted..
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dest.equals("STDOUT")) {
|
if (dest.equals("STDOUT")) {
|
||||||
diagnosticsStream = System.out;
|
return System.out;
|
||||||
} else if (dest.equals("STDERR")) {
|
} else if (dest.equals("STDERR")) {
|
||||||
diagnosticsStream = System.err;
|
return System.err;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
// open the file in append mode
|
// open the file in append mode
|
||||||
FileOutputStream fos = new FileOutputStream(dest, true);
|
FileOutputStream fos = new FileOutputStream(dest, true);
|
||||||
diagnosticsStream = new PrintStream(fos);
|
return new PrintStream(fos);
|
||||||
} catch(IOException ex) {
|
} catch(IOException ex) {
|
||||||
// We should report this to the user - but how?
|
// We should report this to the user - but how?
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In order to avoid confusion where multiple instances of JCL are
|
|
||||||
// being used via different classloaders within the same app, we
|
|
||||||
// ensure each logged message has a prefix of form
|
|
||||||
// [LogFactory from classloader OID]
|
|
||||||
//
|
|
||||||
// Note that this prefix should be kept consistent with that
|
|
||||||
// in LogFactoryImpl. However here we don't need to output info
|
|
||||||
// about the actual *instance* of LogFactory, as all methods that
|
|
||||||
// output diagnostics from this class are static.
|
|
||||||
String classLoaderName;
|
|
||||||
try {
|
|
||||||
ClassLoader classLoader = thisClassLoader;
|
|
||||||
if (thisClassLoader == null) {
|
|
||||||
classLoaderName = "BOOTLOADER";
|
|
||||||
} else {
|
|
||||||
classLoaderName = objectId(classLoader);
|
|
||||||
}
|
|
||||||
} catch(SecurityException e) {
|
|
||||||
classLoaderName = "UNKNOWN";
|
|
||||||
}
|
|
||||||
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1832,7 +1810,28 @@ public abstract class LogFactory {
|
|||||||
// note: it's safe to call methods before initDiagnostics (though
|
// note: it's safe to call methods before initDiagnostics (though
|
||||||
// diagnostic output gets discarded).
|
// diagnostic output gets discarded).
|
||||||
thisClassLoader = getClassLoader(LogFactory.class);
|
thisClassLoader = getClassLoader(LogFactory.class);
|
||||||
initDiagnostics();
|
// In order to avoid confusion where multiple instances of JCL are
|
||||||
|
// being used via different classloaders within the same app, we
|
||||||
|
// ensure each logged message has a prefix of form
|
||||||
|
// [LogFactory from classloader OID]
|
||||||
|
//
|
||||||
|
// Note that this prefix should be kept consistent with that
|
||||||
|
// in LogFactoryImpl. However here we don't need to output info
|
||||||
|
// about the actual *instance* of LogFactory, as all methods that
|
||||||
|
// output diagnostics from this class are static.
|
||||||
|
String classLoaderName;
|
||||||
|
try {
|
||||||
|
ClassLoader classLoader = thisClassLoader;
|
||||||
|
if (thisClassLoader == null) {
|
||||||
|
classLoaderName = "BOOTLOADER";
|
||||||
|
} else {
|
||||||
|
classLoaderName = objectId(classLoader);
|
||||||
|
}
|
||||||
|
} catch(SecurityException e) {
|
||||||
|
classLoaderName = "UNKNOWN";
|
||||||
|
}
|
||||||
|
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
|
||||||
|
diagnosticsStream = initDiagnostics();
|
||||||
logClassLoaderEnvironment(LogFactory.class);
|
logClassLoaderEnvironment(LogFactory.class);
|
||||||
factories = createFactoryStore();
|
factories = createFactoryStore();
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user