ch.qos.logback.classic.android
Class LogcatAppender

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.AppenderBase<ILoggingEvent>
          extended by ch.qos.logback.classic.android.LogcatAppender
All Implemented Interfaces:
Appender<ILoggingEvent>, ContextAware, FilterAttachable<ILoggingEvent>, LifeCycle

public class LogcatAppender
extends AppenderBase<ILoggingEvent>

An appender that wraps the native Android logging mechanism (logcat); redirects all logging requests to logcat

Note:
By default, this appender pushes all messages to logcat regardless of logcat's own filter settings (i.e., everything is printed). To disable this behavior and enable filter-checking, use setCheckLoggable(boolean). See the Android Developer Guide for details on adjusting the logcat filter.

Author:
Fred Eisele, Anthony Trinh
See Also:
http://developer.android.com/guide/developing/tools/adb.html#filteringoutput

Field Summary
 
Fields inherited from class ch.qos.logback.core.AppenderBase
name, started
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
LogcatAppender()
          As in most cases, the default constructor does nothing.
 
Method Summary
 void append(ILoggingEvent event)
          Writes an event to Android's logging mechanism (logcat)
 boolean getCheckLoggable()
          Gets the enable status of the isLoggable()-check that is called before logging
 PatternLayoutEncoder getEncoder()
          Gets the pattern-layout encoder for this appender's logcat message
 PatternLayoutEncoder getTagEncoder()
          Gets the pattern-layout encoder for this appender's logcat tag
 void setCheckLoggable(boolean enable)
          Sets whether to ask Android before logging a message with a specific tag and priority (i.e., calls isLoggable()).
 void setEncoder(PatternLayoutEncoder encoder)
          Sets the pattern-layout encoder for this appender's logcat message
 void setTagEncoder(PatternLayoutEncoder encoder)
          Sets the pattern-layout encoder for this appender's logcat tag
 void start()
          Checks that required parameters are set, and if everything is in order, activates this appender.
 
Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, stop, toString
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
 

Constructor Detail

LogcatAppender

public LogcatAppender()
As in most cases, the default constructor does nothing.

Method Detail

start

public void start()
Checks that required parameters are set, and if everything is in order, activates this appender.

Specified by:
start in interface LifeCycle
Overrides:
start in class AppenderBase<ILoggingEvent>

append

public void append(ILoggingEvent event)
Writes an event to Android's logging mechanism (logcat)

Specified by:
append in class AppenderBase<ILoggingEvent>
Parameters:
event - the event to be logged

getEncoder

public PatternLayoutEncoder getEncoder()
Gets the pattern-layout encoder for this appender's logcat message

Returns:
the pattern-layout encoder

setEncoder

public void setEncoder(PatternLayoutEncoder encoder)
Sets the pattern-layout encoder for this appender's logcat message

Parameters:
encoder - the pattern-layout encoder

getTagEncoder

public PatternLayoutEncoder getTagEncoder()
Gets the pattern-layout encoder for this appender's logcat tag

Returns:
the pattern encoder

setTagEncoder

public void setTagEncoder(PatternLayoutEncoder encoder)
Sets the pattern-layout encoder for this appender's logcat tag

The expanded text of the pattern must be less than 23 characters as limited by Android. Layouts that exceed this limit are truncated, and a star is appended to the tag to indicate this.

The tagEncoder result is limited to 22 characters plus a star to indicate truncation (%logger{0} has no length limit in logback, but LogcatAppender limits the length internally). For example, if the tagEncoder evaluated to foo.foo.foo.foo.foo.bar.Test, the tag seen in Logcat would be: foo.foo.foo.foo.foo.ba*. Note that %logger{23} yields more useful results (in this case: f.f.foo.foo.bar.Test).

Parameters:
encoder - the pattern-layout encoder; specify null to automatically use the logger's name as the tag

setCheckLoggable

public void setCheckLoggable(boolean enable)
Sets whether to ask Android before logging a message with a specific tag and priority (i.e., calls isLoggable()).

Parameters:
enable - true to enable; false to disable

getCheckLoggable

public boolean getCheckLoggable()
Gets the enable status of the isLoggable()-check that is called before logging

Returns:
true if enabled; false otherwise


Copyright © 2005-2013 QOS.ch. All Rights Reserved.