/*
* ALMA - Atacama Large Millimiter Array
* (c) European Southern Observatory, 2004
* Copyright by ESO (in the framework of the ALMA collaboration),
* All rights reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package alma.acs.logging;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.LogRecord;
import alma.acs.util.StopWatch;
/**
* Class that encapsulates access to log record parameters, and handling of a special Property-Map parameter.
* Some conventions are necessary because we "smuggle" some extra information from the plain-JDK loggers
* to the ACS-aware log dispatcher. The alternative would be to expose ACS custom loggers to applications,
* which seems too ugly for the benefit it provides.
*
* The rules are:
*
*
Parameters of type Map are interpreted as name-value pairs
* and show up in the XML log output as <Data Name="key">value</Data>
*
Single-valued parameters show up in the XML log output as
* <Data Name="LoggedParameter">value</Data>
*
There is a special properties Map parameter that contains the key isAcsPropertiesMap.
* Those values are recognized by the log formatter and result in special fields being set, instead of
* <Data/> elements being constructed.
* When adding this map as a log parameter, it should be created using method {@link #createPropertiesMap()}.
*
* Note that this class is stateful: returned values come from the last given LogRecord,
* which can be set in the constructor or overwritten in {@link #setCurrentLogRecord(LogRecord)}.
*/
public class LogParameterUtil {
public static final String IS_ACS_PROPERTIES_MAP_KEYNAME = "isAcsPropertiesMap";
public static final String PARAM_THREAD_NAME = "ThreadName";
public static final String PARAM_LINE = "Line";
public static final String PARAM_HOSTNAME = "HostName";
public static final String PARAM_STACK_ID = "StackId";
public static final String PARAM_STACK_LEVEL = "StackLevel";
public static final String PARAM_PRIORITY = "Priority";
public static final String PARAM_URI = "Uri";
public static final String PARAM_PROCESSNAME = "ProcessName";
public static final String PARAM_SOURCEOBJECT = "SourceObject";
private static final String PARAM_STOPWATCH = "StopWatch";
private LogRecord currentLogRecord;
/**
* A Mapthat is used as an optional special log parameter.
* It transports information from the application to the log formatter
* which could otherwise not be transported using the JDK's LogRecord.
*/
private Map specialProperties;
private List