use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class LogConfigTest method testDynamicChanges.
/**
* Tests runtime changes as they could happen via the {@linkplain LoggingConfigurable} API.
*/
public void testDynamicChanges() throws Exception {
logger.info("============ Running testDynamicChanges ============");
// the default log levels from schema defaults and optional env var setting
AcsLogLevelDefinition defaultMinLogLevel = logConfig.getDefaultMinLogLevel();
AcsLogLevelDefinition defaultMinLogLevelLocal = logConfig.getDefaultMinLogLevelLocal();
// change the default log levels
AcsLogLevelDefinition newDefaultLevel = defaultMinLogLevel.getNextHigherLevel();
assertNotNull(newDefaultLevel);
logConfig.setDefaultMinLogLevel(newDefaultLevel);
assertSame(newDefaultLevel, logConfig.getDefaultMinLogLevel());
assertSame(defaultMinLogLevelLocal, logConfig.getDefaultMinLogLevelLocal());
newDefaultLevel = newDefaultLevel.getNextHigherLevel();
assertNotNull(newDefaultLevel);
logConfig.setDefaultMinLogLevel(newDefaultLevel);
logConfig.setDefaultMinLogLevelLocal(newDefaultLevel);
assertSame(newDefaultLevel, logConfig.getDefaultMinLogLevel());
assertSame(newDefaultLevel, logConfig.getDefaultMinLogLevelLocal());
// restore initial values
logConfig.setDefaultMinLogLevel(defaultMinLogLevel);
logConfig.setDefaultMinLogLevelLocal(defaultMinLogLevelLocal);
// named logger levels
String knownLoggerName = "knownLogger";
// now the logger is known, even though it has default values
UnnamedLogger knownLoggerConfig = logConfig.getNamedLoggerConfig(knownLoggerName);
assertEquals(defaultMinLogLevel, AcsLogLevelDefinition.fromXsdLogLevel(knownLoggerConfig.getMinLogLevel()));
assertEquals(defaultMinLogLevelLocal, AcsLogLevelDefinition.fromXsdLogLevel(knownLoggerConfig.getMinLogLevelLocal()));
Set<String> loggerNames = logConfig.getLoggerNames();
assertEquals(1, loggerNames.size());
assertTrue(loggerNames.contains(knownLoggerName));
String unknownLoggerName = "unknownLogger";
// first encounter with this logger when setting its levels
logConfig.setMinLogLevel(AcsLogLevelDefinition.DEBUG, unknownLoggerName);
loggerNames = logConfig.getLoggerNames();
assertEquals(2, loggerNames.size());
assertTrue(loggerNames.contains(knownLoggerName));
assertTrue(loggerNames.contains(unknownLoggerName));
// make sure that returned objects are not "live" for the logConfig data
knownLoggerConfig = logConfig.getNamedLoggerConfig(knownLoggerName);
UnnamedLogger knownLoggerConfig2 = logConfig.getNamedLoggerConfig(knownLoggerName);
assertNotSame(knownLoggerConfig, knownLoggerConfig2);
newDefaultLevel = newDefaultLevel.getNextHigherLevel();
assertNotNull(newDefaultLevel);
knownLoggerConfig.setMinLogLevel(newDefaultLevel.toXsdLevel());
assertSame(defaultMinLogLevel, logConfig.getDefaultMinLogLevel());
newDefaultLevel = newDefaultLevel.getNextHigherLevel();
assertNotNull(newDefaultLevel);
logConfig.setDefaultMinLogLevel(newDefaultLevel);
assertEquals(defaultMinLogLevel, AcsLogLevelDefinition.fromXsdLogLevel(knownLoggerConfig2.getMinLogLevel()));
}
use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class LogTypeCellRenderer method getTableCellRendererComponent.
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected) {
levelCB.setBackground(table.getSelectionBackground());
levelCB.setForeground(table.getSelectionForeground());
} else {
levelCB.setBackground(table.getBackground());
levelCB.setForeground(table.getForeground());
}
// Set the text
//minimum.setText(value.toString());
levelCB.setFont(table.getFont());
// If the type of log is known, set the icon
LogTypeHelper logType;
try {
AcsLogLevelDefinition levelDef = AcsLogLevelDefinition.fromInteger(Integer.parseInt(value.toString()));
logType = LogTypeHelper.fromAcsCoreLevel(levelDef);
} catch (Exception e) {
System.err.println("Error parsing a log type: " + value.toString());
e.printStackTrace(System.err);
logType = null;
}
if (logType != null) {
levelCB.setSelectedIndex(logType.ordinal());
}
return levelCB;
}
use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class AcsBinLogFormatter method formatBinary.
LogBinaryRecord formatBinary(LogRecord logRecord) {
LogBinaryRecord rLog = new LogBinaryRecord();
// log level
AcsLogLevel acsLevel = AcsLogLevel.getNativeLevel(logRecord.getLevel());
if (acsLevel == null) {
return null;
}
final AcsLogLevelDefinition acsCoreLevel = acsLevel.getAcsLevel();
// get date
Date date = new Date(logRecord.getMillis());
String TimeStamp = IsoDateFormat.formatDate(date);
LogParameterUtil logParamUtil = new LogParameterUtil(logRecord);
rLog.type = (short) acsCoreLevel.value;
rLog.TimeStamp = TimeStamp;
String file = logRecord.getSourceClassName();
if (file == null) {
if (acsCoreLevel == AcsLogLevelDefinition.DEBUG)
rLog.File = "unknown";
} else
rLog.File = file;
long line = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_LINE, -1);
if (line < 0) {
if (acsCoreLevel == AcsLogLevelDefinition.TRACE || acsCoreLevel == AcsLogLevelDefinition.DEBUG)
rLog.Line = 0;
} else
rLog.Line = (int) line;
String Routine = logRecord.getSourceMethodName();
if (Routine == null) {
if (acsCoreLevel == AcsLogLevelDefinition.TRACE) {
rLog.Routine = "unknown";
}
} else {
rLog.Routine = Routine;
}
// host name: may be different from local host if ErrorTrace gets logged
String hostName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_HOSTNAME, null);
if (hostName == null || hostName.length() == 0) {
hostName = getLocalHostName();
}
rLog.Host = hostName;
// String process = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_PROCESSNAME, null);
// if (process != null)
// rLog.Process = process;
// else{
String process = logRecord.getLoggerName();
if (process != null)
rLog.Process = "LoggerName: " + process;
else
rLog.Process = "";
// }
// source object: the container name or component name
String sourceObject = logRecord.getLoggerName();
if (sourceObject != null) {
rLog.SourceObject = sourceObject;
} else
rLog.SourceObject = "";
// add thread ID, or name if given
String threadName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_THREAD_NAME, null);
if (threadName != null && threadName.length() > 0)
rLog.Thread = threadName;
else if (logRecord.getThreadID() >= 0)
rLog.Thread = "" + logRecord.getThreadID();
else
rLog.Thread = "";
// add context
String context = logParamUtil.extractStringProperty("Context", null);
if (context != null)
rLog.LogContext = context;
else
rLog.LogContext = "";
// add stack info
rLog.StackId = "";
rLog.StackLevel = 0;
if (acsCoreLevel.compareTo(AcsLogLevelDefinition.WARNING) >= 0) {
// add stack id
String stackId = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_STACK_ID, null);
if (stackId == null)
rLog.StackId = "unknown";
else
rLog.StackId = stackId;
// add stack idlevel
long stackLevel = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_STACK_LEVEL, -1);
if (stackLevel > 0)
rLog.StackLevel = (int) stackLevel;
}
// add log id
long logId = logRecord.getSequenceNumber();
if (logId >= 0)
rLog.LogId = "" + logId;
else
rLog.LogId = "";
// add URI
String uri = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_URI, null);
if (uri != null)
rLog.Uri = uri;
else
rLog.Uri = "";
// add priority
// to be written only different as entry priority
long priority = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_PRIORITY, acsCoreLevel.value);
if (priority != acsCoreLevel.value)
rLog.Priority = (int) priority;
else
rLog.Priority = -1;
// the log message becomes the text in our XML record
if (logRecord.getMessage() != null) {
rLog.MsgData = logRecord.getMessage();
} else
rLog.MsgData = "";
//add Audience, Array and Antenna, if applicable
if (logRecord instanceof AcsLogRecord) {
rLog.Audience = ((AcsLogRecord) logRecord).getAudience();
rLog.Array = ((AcsLogRecord) logRecord).getArray();
rLog.Antenna = ((AcsLogRecord) logRecord).getAntenna();
}
// <Data> elements: logged exception or error trace, and log parameters
//NameValue a;
//rLog.log_data = new NameValue[propertiesMap.size() + 1];
//TODO: see why there are not attributes here
rLog.attributes = new NameValue[0];
NameValue[] log_data = new NameValue[257];
//rLog.log_data = new NameValue[257];
int i = 0;
try {
// logged exception
Throwable loggedThrowable = logRecord.getThrown();
if (loggedThrowable != null) {
StringWriter exWriter = new StringWriter();
loggedThrowable.printStackTrace(new PrintWriter(exWriter));
log_data[i++] = new NameValue("LoggedException", exWriter.toString());
}
// log parameters (except for the special properties which were used already to set specific fields)
for (Object param : logParamUtil.getNonSpecialPropertiesMapParameters()) {
if (i >= 255)
break;
if (param instanceof Map) {
// any map that is not the special properties map we interpret as name-value pairs.
Map propertiesMap = (Map) param;
for (Object keyName : propertiesMap.keySet()) {
String value = propertiesMap.get(keyName).toString();
log_data[i++] = new NameValue(keyName.toString(), value);
}
} else {
// a single parameter was logged, but we have to fit it into our name-value scheme using a fake name
String value = param.toString();
log_data[i++] = new NameValue("LoggedParameter", value);
}
}
} catch (Exception e) {
// expected not to happen often at all, thus no try blocks inside every loop, so we may lose some <Data>
String value = e.toString();
log_data[i++] = new NameValue("DataConstructionError", value);
}
rLog.log_data = new NameValue[i];
for (int j = 0; j < i; j++) {
rLog.log_data[j] = log_data[j];
}
return rLog;
}
use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class AcsXMLLogFormatter method format.
/**
* Constructs the XML log message that can be sent to the ACS logging service.
* @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
*/
public String format(LogRecord logRecord) {
// log level
AcsLogLevel acsLevel = AcsLogLevel.getNativeLevel(logRecord.getLevel());
if (acsLevel == null) {
return "";
}
final AcsLogLevelDefinition acsCoreLevel = acsLevel.getAcsLevel();
final String levelName = acsLevel.getEntryName();
// get date
String TimeStamp = IsoDateFormat.formatDate(new Date(logRecord.getMillis()));
LogParameterUtil logParamUtil = new LogParameterUtil(logRecord);
StringBuffer sb = new StringBuffer("");
sb.append("<");
sb.append(levelName);
sb.append(" ");
sb.append("TimeStamp=\"" + TimeStamp + "\" ");
String file = logRecord.getSourceClassName();
if (file == null) {
if (acsCoreLevel == AcsLogLevelDefinition.DEBUG)
sb.append("File=\"unknown\" ");
} else {
sb.append("File=\"" + file + "\" ");
}
long line = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_LINE, -1);
if (line < 0) {
if (acsCoreLevel == AcsLogLevelDefinition.TRACE || acsCoreLevel == AcsLogLevelDefinition.DEBUG)
sb.append("Line=\"0\" ");
} else {
sb.append("Line=\"" + line + "\" ");
}
String Routine = logRecord.getSourceMethodName();
if (Routine == null) {
if (acsCoreLevel == AcsLogLevelDefinition.TRACE)
sb.append("Routine=\"unknown\" ");
} else {
sb.append("Routine=\"" + maskAttribute(Routine) + "\" ");
}
// host name: may be different from local host if ErrorTrace gets logged
String hostName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_HOSTNAME, null);
if (hostName == null || hostName.length() == 0) {
hostName = this.getLocalHostName();
}
//hostName = getLocalHostName();
sb.append("Host=\"" + hostName + "\" ");
String process = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_PROCESSNAME, null);
if (process != null) {
sb.append("Process=\"" + process + "\" ");
} else {
process = logRecord.getLoggerName();
if (process != null) {
sb.append("Process=\"" + process + "\" ");
}
}
String sourceObject = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_SOURCEOBJECT, null);
if (sourceObject != null) {
sb.append("SourceObject=\"" + sourceObject + "\" ");
} else {
sourceObject = logRecord.getLoggerName();
if (sourceObject != null) {
sb.append("SourceObject=\"" + sourceObject + "\" ");
}
}
// add thread ID, or name if given
String threadName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_THREAD_NAME, null);
if (threadName != null && threadName.length() > 0) {
sb.append("Thread=\"" + threadName + "\" ");
} else if (logRecord.getThreadID() >= 0) {
sb.append("Thread=\"" + logRecord.getThreadID() + "\" ");
}
// add context
String context = logParamUtil.extractStringProperty("Context", null);
if (context != null) {
sb.append("Context=\"" + context + "\" ");
}
// add stack info
if (acsCoreLevel.compareTo(AcsLogLevelDefinition.WARNING) >= 0) {
// add stack id
String stackId = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_STACK_ID, null);
if (stackId == null)
sb.append("StackId=\"unknown\" ");
else
sb.append("StackId=\"" + stackId + "\" ");
// add stack idlevel
long stackLevel = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_STACK_LEVEL, -1);
if (stackLevel < 0)
sb.append("StackLevel=\"0\" ");
else
sb.append("StackLevel=\"" + stackLevel + "\" ");
}
// add log id
long logId = logRecord.getSequenceNumber();
if (logId >= 0) {
sb.append("LogId=\"" + logId + "\" ");
}
// add URI
String uri = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_URI, null);
if (uri != null) {
sb.append("Uri=\"" + uri + "\" ");
}
// add priority
// to be written only different as entry priority
long priority = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_PRIORITY, acsCoreLevel.value);
if (priority != acsCoreLevel.value) {
sb.append("Priority=\"" + priority + "\" ");
}
//add Audience, if applicable(for typeSafeLogs/Operator logs)
if (logRecord instanceof AcsLogRecord) {
String audience = ((AcsLogRecord) logRecord).getAudience();
if (!audience.equals(""))
sb.append("Audience=\"" + audience + "\" ");
//add Array
String array = ((AcsLogRecord) logRecord).getArray();
if (!array.equals(""))
sb.append("Array=\"" + array + "\" ");
//add Antenna
String antenna = ((AcsLogRecord) logRecord).getAntenna();
if (!antenna.equals(""))
sb.append("Antenna=\"" + antenna + "\" ");
}
sb.setCharAt(sb.lastIndexOf("") - 1, '>');
// the log message becomes the text in our XML record
if (logRecord.getMessage() != null) {
sb.append(maskMessage(logRecord.getMessage()));
}
try {
// logged exception
Throwable loggedThrowable = logRecord.getThrown();
if (loggedThrowable != null) {
StringWriter exWriter = new StringWriter();
loggedThrowable.printStackTrace(new PrintWriter(exWriter));
sb.append("<Data Name=\"LoggedException\">" + maskMessage(exWriter.toString()) + "</Data>");
}
// log parameters (except for the special properties which were used already to set specific fields)
for (Object param : logParamUtil.getNonSpecialPropertiesMapParameters()) {
if (param instanceof Map) {
// any map that is not the special properties map we interpret as name-value pairs.
Map propertiesMap = (Map) param;
for (Object keyName : propertiesMap.keySet()) {
String value = maskEmptyDataContent(propertiesMap.get(keyName).toString());
sb.append("<Data Name=\"" + keyName.toString() + "\">" + maskMessage(value) + "</Data>");
}
} else {
// a single parameter was logged, but we have to fit it into our name-value scheme using a fake name
String value = maskEmptyDataContent(param.toString());
sb.append("<Data Name=\"LoggedParameter\">" + maskMessage(value) + "</Data>");
}
}
} catch (Exception e) {
// expected not to happen often at all, thus no try blocks inside every loop, so we may lose some <Data>
sb.append("<Data Name=\"DataConstructionError\">" + maskMessage(e.toString()) + "</Data>");
}
// end tag of XML record
sb.append("</" + levelName + ">");
String Log = sb.toString();
// System.out.println("Logging XML log entry " + Log);
return Log;
}
use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class StdOutConsoleHandler method configureLogging.
/**
* @see alma.acs.logging.config.LogConfigSubscriber#configureLogging(alma.acs.logging.config.LogConfig)
*/
public void configureLogging(LogConfig newLogConfig) {
// just in case some day LogConfig is no longer used as a singleton
this.logConfig = newLogConfig;
try {
AcsLogLevelDefinition minLogLevelACS = AcsLogLevelDefinition.fromXsdLogLevel(logConfig.getNamedLoggerConfig(loggerName).getMinLogLevelLocal());
setLevel(AcsLogLevel.getLowestMatchingJdkLevel(minLogLevelACS));
} catch (Exception ex) {
publish(new LogRecord(Level.WARNING, "Failed to configure stdout log handler: " + ex.toString()));
}
}
Aggregations