[logback-dev] [JIRA] Commented: (LBGENERAL-41) Provide a way for localtime date pattern

Ceki Gulcu (JIRA) noreply-jira at qos.ch
Thu Apr 15 14:27:16 CEST 2010


    [ http://jira.qos.ch/browse/LBGENERAL-41?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=11723#action_11723 ] 

Ceki Gulcu commented on LBGENERAL-41:
-------------------------------------

What do you mean by "without dynamic log configuration via XML"? In  Is out-of-the-box working logback.xml configuration an example of dynamic log configuration via XML or not? 

Given that the timestamp printed by the %d converter is already relative to the current locale by default, I presume that your are looking to print the current timezone id in each printed line of log. If that is indeed your goal, you could create an out-of-the-box working logback.xml configuration for all locales by first setting a property containing the current timezone and using it in your appender. Here is an example:

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  <encoder>
    <pattern>${TIMEZONE} %d  [%thread] %-5level %logger{35} - %msg%n</pattern>
  </encoder>
</appender>

You can set the TIMEZONE property either before invoking JoranConfigurator, or if you rely on logback automatically picking up logback.xml, then you can set the value of TIMEZONE within the configuration file itself. See http://logback.qos.ch/manual/configuration.html#definingPropsOnTheFly for more documentation.

You would need to add the following line at the top of your config file:

<define name="TIMEZONE"   class="com.someCompany.TimeZonePropertyDefiner">

Here is a sample implementation of TimeZonePropertyDefiner:

package com.someCompany;
import java.util.TimeZone;
public class TimeZonePropertyDefiner extends ContextAwareBase implements PropertyDefiner  {
  public String getPropertyValue() {
    TimeZone tz = TimeZone.getDefault();
    return tz.getID();
  }
}





> Provide a way for localtime date pattern
> ----------------------------------------
>
>                 Key: LBGENERAL-41
>                 URL: http://jira.qos.ch/browse/LBGENERAL-41
>             Project: logback-general
>          Issue Type: New Feature
>            Reporter: Andreas Sahlbach
>            Assignee: Logback dev list
>
> I am providing a client library for customers all over the world. The client library is using slf4j. It also comes with a preconfigured logback version that provides logging for the commandline interface of the library and as an example working logging solution for my client library. I am also providing an out-of-the-box working logback.xml configuration.
> I now would like to have a possibility to log the current local time of the client in the log file. I currently can only specify no time zone that defaults back to GMT which will for sure raise lots of support calls to me, because lots of my clients don't even know what GMT is nor how to spell it...
> But I also can't specify a specific time zone, because I am in Europe and some of my customers are in China, so that would be awkward for them, too.
> So please provide a way for me to log the current localtime of the running program. (without dynamic log configuration via xml please). Using a special timezone value or something.
> This would be great, thanks!

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list