11
Log4J Ivan Kocijan Koc

Infinum Android Talks #14 - Log4j

  • Upload
    infinum

  • View
    50

  • Download
    10

Embed Size (px)

Citation preview

Log4JIvan Kocijan Koc

Why?• It is possible to enable logging at runtime • It’s possible to change log levels at runtime • Log statements can stay in production ape without incurring a heavy performance

cost • It gives the developer detailed context for application failures • The target of the log output can be a file, an OutputStream, a java.io.Writer, a

remote log4j server… • Automatic backup

Android-logging-log4j

• We will not use log4J directly • Android-logging-log4j is a library build on top of log4j • Makes logging very simple while keeping all log4j features

How to add it in your project?

• Add two lines of code to your build.gradle file

Set manifest permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Configuration class

Log anything

!OUTPUT: 2014-07-02 18:34:52,762 - [ERROR::root::com.example.ivankocijan.log4jexample.MyActivity] - something

Custom logger

OUTPUT: 2014-07-02 18:34:52,769 - [ERROR::This is my logger:: com.example.ivankocijan.log4jexample.MyActivity] - something else

Log levels• OFF • FATAL • ERROR • WARN • INFO • DEBUG • TRACE • ALL

Log4j 2

• Still in beta • API Separation - core is separated from logger API • Improved Performance • Plugin Architecture • ….

Resources

• http://logging.apache.org/log4j/1.2/manual.html • https://code.google.com/p/android-logging-log4j/ • http://mindpipe.blogspot.com/2011/11/android-log4j-exception-properties.html • http://logging.apache.org/log4j/2.x/ • http://gradleplease.appspot.com/