Logback project - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Logback project

Description:

It can do partial replay. It is generic (can be used in your own projects) 7 ... Errors in action. Internal state available via StatusManager ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 27
Provided by: Ceki6
Category:

less

Transcript and Presenter's Notes

Title: Logback project


1
Logback project
  • Ceki Gülcü Sébastien Pennec

2
  • No revolution, only evolution.
  • The same basic plumbing only done better.
  • Faster, smaller, higher gas mileage, and
    generally more bang for the buck.

3
Modular architecture
  • logback-core
  • Joran, Status,
  • Context, pattern parsing
  • logback-classic
  • developer logging
  • logback-access
  • container (access) logging

4
Access Logging
  • Definition Access log
  • The log generated when a user accesses a
    web-page on a web server.
  • Logback-access integrates seamlessly with Jetty
    and Tomcat

5
logback-classic speaks SLF4J (as mother tongue)
  • Logback offers a native implementation of the
    SLF4J API gt Logback exposes its logging API
    through SLF4J.
  • SLF4J can delegate to log4j, logback,
    java.util.logging or JCL
  • SLF4J can bridge log4j and JCL .

6
Joran a bowl of fresh air
  • Given rules (patterns actions) it can configure
    any object.
  • Joran can learn new rules on the fly.
  • With its implicit rules, you dont even have to
    write rules.
  • It can do partial replay.
  • It is generic (can be used in your own projects)

7
Configuration example
  • ltappender name"FILE"
  • class"ch.qos.logback.core.rolling.RollingFil
    eAppender"gt
  • ltFilegtlogFile.loglt/Filegt
  • ltrollingPolicy
  • class"ch.qos.logback.core.rolling.TimeBasedRo
    llingPolicy"gt
  • ltFileNamePatterngt
  • logFile.dyyyy-MM-dd.log.zip
  • lt/FileNamePattergt
  • lt/rollingPolicygt
  • ltlayout class"ch.qos.logback.classic.PatternLay
    out"gt
  • ltPatterngt
  • dHHmmss,SSS thread -5level
    logger22 - msgn
  • lt/Patterngt
  • lt/layoutgt
  • lt/appendergt

8
Logback-access configuration
  • ltappender name"FILE"
  • class"c.q.l.c.r.RollingFileAppender"gt
  • ltFilegtaccess.log"lt/Filegt
  • ltrollingPolicy
  • class"c.q.l.c.r.TimeBasedRollingPolicy"gt
  • ltFileNamePatterngt
  • access.dyyyy-MM-dd.log.zip
  • lt/FileNamePatterngt
  • lt/rollingPolicygt
  • ltlayout class"c.q.l.access.PatternLayout"gt
  • ltPattern"gtcombinedlt/Pattern"gt
  • lt/layoutgt
  • lt/appendergt

9
Another example
  • lttestShell name"test1"gt
  • ltperiodgt5 minuteslt/periodgt
  • lt!-- we need to configure a totally new test
  • object for each run of the test --gt
  • lttest class"com.wombat.myTest"gt
  • ltDataSource class"c.w.JNDIDS"gt
  • lturlgtjndi//com.wombat/ds"lt/urlgt
  • lt/DataSourcegt
  • lt/testgt
  • lttestShellgt
  • lttestShell name"test2"gt
  • ltperiodgt60 secondslt/periodgt
  • lttest class"com.wombat.myTest2"gt
  • ltfilegtc/wombat/foo.propertieslt/filegt
  • lt/testgt
  • lt/testShellgt

10
Is Joran for me?
  • Joran is ideal for building frameworks which need
    to support arbitrary user-developed plug-ins.

11
Internal error reporting
  • Who shall guard the guards?
  • Logback modules cannot use logging to report
    their own state.
  • Something more generic is needed.

12
Status API
  • public interface Status
  • public final int INFO 0
  • public final int WARN 1
  • public final int ERROR 2
  • int getLevel()
  • int getEffectiveLevel()
  • Object getOrigin()
  • String getMessage()
  • Throwable getThrowable()
  • public boolean hasChildren()
  • public void add(Status child)
  • public boolean remove(Status child)
  • public IteratorltStatusgt iterator()

13
Errors in action
  • Internal state available via StatusManager
  • Exceptions and status messages accompanied by
    references, i.e. URLs, to external documents

14
Documentation
  • Major area of effort.
  • Complete manual (work in progress)
  • A short introduction to access logging with
    logback-access and Jetty
  • A introduction to Joran
  • javadoc, FAQ, error codes,

15
Filters, Filters. Filters everywhere
  • Filters attachable to any Appender and most
    contexts
  • Evaluator filters
  • Janino filters for evaluation based on java
    expressions
  • TurboFilters for optimized global processing

16
EvaluatorFilter Janino
  • ltappender name"CYCLIC"
  • class"c.q.l.core.read.CyclicBufferAppen
    der"gt
  • ltfilter class"c.q.l.core.filter.EvaluatorFilter
    "gt
  • ltevaluator name"loggingTaskEval"gt
  • ltexpressiongt
  • logger.getName().contains("LoggingTask")
  • message.contains("Howdydy-diddly-ho")
  • (timeStamp - event.getStartTime()) gt
    20000
  • lt/expressiongt
  • lt/evaluatorgt
  • ltOnMatchgtDENYlt/OnMatchgt
  • lt/filtergt
  • ltMaxSizegt512lt/MaxSizegt
  • lt/appendergt

17
TurboFilters
  • ltturboFilter
  • class"c.q.l.classic.turbo.MDCFilter"gt
  • ltMDCKeygtusernamelt/MDCKeygt
  • ltValuegtsebastienlt/Valuegt
  • ltOnMatchgtACCEPTlt/OnMatchgt
  • lt/turboFiltergt

18
Parameterized logging
  • Integer entry new Interger(50)
  • logger.debug("The entry is "entry".")
  • can be optimized as
  • if(logger.isDebugEnabled())
  • logger.debug("The entry is "entry".")
  • or better yet
  • logger.debug("The entry is .", entry)

19
Markers for specialized handling
  • Markers are metadata for logging statements,
    coloring them for specialized processing

20
JMX
  • Logback components can be configured using JMX
  • Statistical results exposed via JMX

21
Tested Ready
  • Battery of over 400 unit tests
  • Tests written concomitantly with the code

22
Package versions in stack traces
  • java.lang.NullPointerException
  • at com.xyz.Wombat(Wombat.java57)
    wombat-1.3.jar1.3
  • at com.xyz.Wombat(Wombat.java76)
    wombat-1.3.jar1.3
  • at sun.reflect.NativeMethodAccessorImpl.invoke0(N
    ative) na1.5.0_06
  • at java.lang.reflect.Method.invoke(Method.java58
    5) na1.5.0_06
  • at junit.runners.TestMethod.invoke(TestMethod.jav
    a59) junit-4.4.jarna
  • etc..

23
logger name abbreviation
24
Odds and ends
  • RollingFileAppender automatic file compression
    the background
  • 10 fold improvement in the speed of transporting
    logging events over the wire
  • SMTPAppender subject line in outgoing email

25
Conclusion
  • Logback is the successor of log4j.

26
Questions?
  • read the docs at http//logback.qos.ch/
  • study the code at http//svn.qos.ch
  • write to us at logback-user_at_qos.ch
  • file a bug report at http//jira.qos.ch/
  • chat with us at irc.freenode.netqos
  • talk to us at 41 21 312 32 26
Write a Comment
User Comments (0)
About PowerShow.com