logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1149) PatternLayout predefined date pattern with time zone always renders default date format
Date Mon, 04 Jan 2016 22:17:39 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15081912#comment-15081912

Remko Popma commented on LOG4J2-1149:

{{FixedDateFormat#createIfSupported}} returns {{null}}, that is correct. If you continue following
the flow of execution you will see that the caller (the {{DatePatternConverter}} constructor)
will then call {{DatePatternConverter#createFormatter}}, where the presence of a time zone
is handled with this code

// LOG4J2-1149: patternOption may be a name (if a time zone was specified)
final FixedDateFormat.FixedFormat fixedFormat = FixedDateFormat.FixedFormat.lookup(patternOption);
final String pattern = fixedFormat == null ? patternOption : fixedFormat.getPattern();

// if the option list contains a TZ option, then set it.
TimeZone tz = null;
if (options.length > 1 && options[1] != null) {
    tz = TimeZone.getTimeZone(options[1]);

try {
    final FastDateFormat tempFormat = FastDateFormat.getInstance(pattern, tz);
    return new PatternFormatter(tempFormat);
} catch (final IllegalArgumentException e) {
    LOGGER.warn("Could not instantiate FastDateFormat with pattern " + pattern, e);

    // default to the DEFAULT format
    return createFormatter(FixedDateFormat.create(FixedFormat.DEFAULT));

This should correctly handle time zones.

It sounds like you expect the string result of rendering the date in the specified format
to end in the character "Z". I'm not sure if it should. If you look at the %d section of the
documentation for [PatternLayout|http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout],
you will see that the examples do not end in "Z".

> PatternLayout predefined date pattern with time zone always renders default date format
> ---------------------------------------------------------------------------------------
>                 Key: LOG4J2-1149
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1149
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Pattern Converters
>    Affects Versions: 2.4
>            Reporter: Matt Barron
>            Assignee: Remko Popma
>             Fix For: 2.4.1
> The date pattern
> {code}
> "%d{ISO8601}{UTC}"
> {code}
> is rendered as the default date format (yyyy-MM-dd HH:mm:ss,SSS) instead.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message