QOS.ch JIRA

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • logback-core
  • LBCORE-108

Enable TimeBasedRollingPolicy, FileNamePattern, and DateTokenConverter subclassing by supporting protected access

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 0.9.15
  • Fix Version/s: None
  • Component/s: Pattern, Rolling
  • Labels:
    None

Description

We needed to change our log file names to use GMT-based naming patterns (LBCORE-85 addresses this potential improvement). The only way to do this is to access package-scoped fields in TimeBasedRollingPolicy and FileNamePattern.

The options we considered were:
1. Copying and tweaking all of TimeBasedRollingPolicy and FileNamePattern and related classes. We'd then have to stay on top of and merge in any bug fixes or improvements in new versions of logback.
2. Write our subclasses in the ch.qos.logback.core.rolling and ch.qos.logback.core.rolling.helper packages, which required un-sealing our jar.

The request is to either change the fields from package-scoped to protected; or add protected getters and setters for accessing them. These are the fields we use:

* TimeBasedRollingPolicy
** activeFileNamePattern

* FileNamePattern
** headTokenConverter

* DateTokenConverter
** sdf

Here's our source code:

{code}
public class TimeBasedRollingPolicyWithTimeZone<E> extends TimeBasedRollingPolicy<E> {
    
    private String m_timeZone = "GMT";
    
    public void setTimeZone(String timeZone) {
        m_timeZone = timeZone;
    }
    
    public String getTimeZone() {
        return m_timeZone;
    }

    @Override
    public void start() {
        super.start();
        activeFileNamePattern = new FileNamePatternWithTimeZone(activeFileNamePattern, TimeZone.getTimeZone(getTimeZone()));
    }

}
{code}

{code}
public class FileNamePatternWithTimeZone extends FileNamePattern {

    public FileNamePatternWithTimeZone(FileNamePattern noZonePattern, TimeZone timeZone) {
        super(noZonePattern.getPattern(), noZonePattern.getContext());
        Converter<Object> conv = headTokenConverter;
        while (conv != null) {
            if (conv instanceof DateTokenConverter) {
                ((DateTokenConverter) conv).sdf.setTimeZone(timeZone);
            }
            conv = conv.getNext();
        }
    }
}
{code}

Activity

  • All
  • Comments
  • History
  • Activity
Hide
Permalink
John Crim added a comment - 08/Jul/09 9:47 PM
Note: If LBCORE-85 is addressed, my company wouldn't care so much about supporting this extensibility.
Show
John Crim added a comment - 08/Jul/09 9:47 PM Note: If LBCORE-85 is addressed, my company wouldn't care so much about supporting this extensibility.

People

  • Assignee:
    Logback dev list
    Reporter:
    John Crim
Vote (2)
Watch (2)

Dates

  • Created:
    08/Jul/09 9:45 PM
    Updated:
    08/Jul/09 9:47 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for logback. Try JIRA - bug tracking software for your team.