mirror of https://github.com/apache/openjpa.git
use Configuration.getId() as the default diagnostic context, if no diagnostic context is specified in the log configuration property.
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@475094 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
72741efc85
commit
330654d226
|
@ -25,6 +25,8 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.openjpa.lib.conf.Configurable;
|
||||||
|
import org.apache.openjpa.lib.conf.Configuration;
|
||||||
import org.apache.openjpa.lib.conf.GenericConfigurable;
|
import org.apache.openjpa.lib.conf.GenericConfigurable;
|
||||||
import org.apache.openjpa.lib.util.Files;
|
import org.apache.openjpa.lib.util.Files;
|
||||||
import org.apache.openjpa.lib.util.Localizer;
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
|
@ -38,7 +40,8 @@ import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
|
||||||
*
|
*
|
||||||
* @author Patrick Linskey
|
* @author Patrick Linskey
|
||||||
*/
|
*/
|
||||||
public class LogFactoryImpl implements LogFactory, GenericConfigurable {
|
public class LogFactoryImpl
|
||||||
|
implements LogFactory, GenericConfigurable, Configurable {
|
||||||
|
|
||||||
private static Localizer _loc = Localizer.forPackage(LogFactoryImpl.class);
|
private static Localizer _loc = Localizer.forPackage(LogFactoryImpl.class);
|
||||||
|
|
||||||
|
@ -78,7 +81,15 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
|
||||||
*/
|
*/
|
||||||
private PrintStream _out = System.err;
|
private PrintStream _out = System.err;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A token to add to all log messages. If <code>null</code>, the
|
||||||
|
* configuration's id will be used.
|
||||||
|
*/
|
||||||
private String _diagContext = null;
|
private String _diagContext = null;
|
||||||
|
private boolean _diagContextComputed = false;
|
||||||
|
|
||||||
|
private Configuration _conf;
|
||||||
|
|
||||||
|
|
||||||
public LogFactoryImpl() {
|
public LogFactoryImpl() {
|
||||||
initializationMillis = System.currentTimeMillis();
|
initializationMillis = System.currentTimeMillis();
|
||||||
|
@ -128,7 +139,7 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A string to prefix all log messages with. Set to
|
* A string to prefix all log messages with. Set to
|
||||||
* <code>null</code> for no prefix.
|
* <code>null</code> to use the configuration's Id property setting.
|
||||||
*/
|
*/
|
||||||
public void setDiagnosticContext(String val) {
|
public void setDiagnosticContext(String val) {
|
||||||
_diagContext = val;
|
_diagContext = val;
|
||||||
|
@ -136,9 +147,20 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A string to prefix all log messages with. Set to
|
* A string to prefix all log messages with. Set to
|
||||||
* <code>null</code> for no prefix.
|
* <code>null</code> to use the configuration's Id property setting.
|
||||||
*/
|
*/
|
||||||
public String getDiagnosticContext() {
|
public String getDiagnosticContext() {
|
||||||
|
if (!_diagContextComputed) {
|
||||||
|
// this initialization has to happen lazily because there is no
|
||||||
|
// guarantee that conf.getId() will be populated by the time that
|
||||||
|
// endConfiguration() is called.
|
||||||
|
if (_diagContext == null) {
|
||||||
|
_diagContext = _conf.getId();
|
||||||
|
}
|
||||||
|
if ("".equals(_diagContext))
|
||||||
|
_diagContext = null;
|
||||||
|
_diagContextComputed = true;
|
||||||
|
}
|
||||||
return _diagContext;
|
return _diagContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +239,18 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Configurable implementation ----------
|
||||||
|
|
||||||
|
public void setConfiguration(Configuration conf) {
|
||||||
|
_conf = conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startConfiguration() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endConfiguration() {
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- GenericConfigurable implementation ----------
|
// ---------- GenericConfigurable implementation ----------
|
||||||
|
|
||||||
public void setInto(Options opts) {
|
public void setInto(Options opts) {
|
||||||
|
@ -272,8 +306,8 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
|
||||||
|
|
||||||
buf.append(getOffset());
|
buf.append(getOffset());
|
||||||
buf.append(" ");
|
buf.append(" ");
|
||||||
if (_diagContext != null)
|
if (getDiagnosticContext() != null)
|
||||||
buf.append(_diagContext).append(" ");
|
buf.append(getDiagnosticContext()).append(" ");
|
||||||
buf.append(getLevelName(level));
|
buf.append(getLevelName(level));
|
||||||
if (level == INFO || level == WARN)
|
if (level == INFO || level == WARN)
|
||||||
buf.append(" ");
|
buf.append(" ");
|
||||||
|
|
Loading…
Reference in New Issue