org.jboss.logging.layout.PatternParserEx Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This 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 software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.logging.layout;
import org.apache.log4j.helpers.PatternConverter;
import org.apache.log4j.helpers.PatternParser;
/** A subclass of the log4j PatternParser that add the following conversion
characters:
Conversion Character
Effect
z
Used to output current thread NDC value. This can be used to obtain
an NDC to augment any NDC associated with the LoggingEvent. This might
be necessary if the LoggingEvent has been serialized between VMs.
Z
Used to output current thread MDC value. This can be used to obtain
an MDC to augment any MDC associated with the LoggingEvent. This might
be necessary if the LoggingEvent has been serialized between VMs.
The Z conversion character must be followed by the key for the map placed
between braces, as in %Z{theKey} where theKey is the key.
The value in the MDC corresponding to the key will be output.
* @author [email protected]
* @version $Revision: 2785 $
*/
public class PatternParserEx extends PatternParser
{
/** Creates a new instance of PatternParser
* @param pattern the patatern
*/
public PatternParserEx(String pattern)
{
super(pattern);
}
protected void finalizeConverter(char c)
{
PatternConverter pc = null;
switch(c)
{
case 'z':
pc = new ThreadNDCConverter(formattingInfo);
currentLiteral.setLength(0);
break;
case 'Z':
String key = extractOption();
pc = new ThreadMDCConverter(formattingInfo, key);
currentLiteral.setLength(0);
break;
default:
super.finalizeConverter(c);
return;
}
addConverter(pc);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy