mirror of https://github.com/qos-ch/slf4j
implement android logging for slf4j
This commit is contained in:
parent
730ca751a9
commit
4f8fbf0d6b
|
|
@ -10,4 +10,8 @@ target
|
|||
integration/bundle/
|
||||
integration/felix-cache/
|
||||
runner
|
||||
.DS_Store
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
|
|
|
|||
1
pom.xml
1
pom.xml
|
|
@ -57,6 +57,7 @@
|
|||
<module>slf4j-jdk14</module>
|
||||
<module>slf4j-log4j12</module>
|
||||
<module>slf4j-jcl</module>
|
||||
<module>slf4j-android</module>
|
||||
<module>slf4j-ext</module>
|
||||
<module>jcl-over-slf4j</module>
|
||||
<module>log4j-over-slf4j</module>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
/target
|
||||
/.settings
|
||||
/.classpath
|
||||
/.project
|
||||
/gen
|
||||
.DS_Store
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.slf4j"
|
||||
android:versionCode="1" android:versionName="1.0">
|
||||
<application />
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
Copyright (c) 2004-2007 QOS.ch
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# SLF4J Android
|
||||
|
||||
The motivation for the SLF4J Android project was to ease using existing libraries
|
||||
which use SLF4J as their logging framework on the [Google Android platform](http://developer.android.com).
|
||||
|
||||
This project is a basic implementation that simply forwards all SLF4J log requests to the
|
||||
[logger](http://developer.android.com/reference/android/util/Log.html) provided by the Google Android platform.
|
||||
|
||||
As slf4j-jdk14, slf4j-log4j etc. slf4j-android is a maven module that depends on slf4j-api only
|
||||
so it can easily be built with maven and synced with [the original slf4j codebase](https://github.com/qos-ch/slf4j).
|
||||
|
||||
### Status
|
||||
The implementation is currently fully functional but has not yet been fully tested in a
|
||||
production environment. Let us know if you have used it in production!
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
android.library=true
|
||||
# Project target.
|
||||
target=android-3
|
||||
apk-configurations=
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
<project
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.4</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>slf4j-android</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<name>SLF4J Android Binding</name>
|
||||
<description>SLF4J Android Binding</description>
|
||||
<url>http://www.slf4j.org</url>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>nordligulv</id>
|
||||
<name>Andrey Korzhevskiy</name>
|
||||
<organization>Investment holding "FINAM" CJSC</organization>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<type>test-jar</type>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<version>1.5_r4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>false</addClasspath>
|
||||
<Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version>
|
||||
<Bundle-Description>${project.description}</Bundle-Description>
|
||||
<Implementation-Version>${project.version}</Implementation-Version>
|
||||
</manifest>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- Google Android requires class compatibility set to 5.0. -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,575 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2011 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
|
||||
import android.util.Log;
|
||||
import org.slf4j.helpers.FormattingTuple;
|
||||
import org.slf4j.helpers.MarkerIgnoringBase;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
/**
|
||||
* A simple implementation that delegates all log requests to the Google Android
|
||||
* logging facilities. Note that this logger does not support {@link org.slf4j.Marker}.
|
||||
* That is, methods taking marker data simply invoke the corresponding method
|
||||
* without the Marker argument, discarding any marker data passed as argument.
|
||||
* <p/>
|
||||
* The logging levels specified for SLF4J can be almost directly mapped to
|
||||
* the levels that exist in the Google Android platform. The following table
|
||||
* shows the mapping implemented by this logger.
|
||||
* <p/>
|
||||
* <table border="1">
|
||||
* <tr><th><b>SLF4J<b></th><th><b>Android</b></th></tr>
|
||||
* <tr><td>TRACE</td><td>{@link android.util.Log#VERBOSE}</td></tr>
|
||||
* <tr><td>DEBUG</td><td>{@link android.util.Log#DEBUG}</td></tr>
|
||||
* <tr><td>INFO</td><td>{@link android.util.Log#INFO}</td></tr>
|
||||
* <tr><td>WARN</td><td>{@link android.util.Log#WARN}</td></tr>
|
||||
* <tr><td>ERROR</td><td>{@link android.util.Log#ERROR}</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* @author Andrey Korzhevskiy
|
||||
*/
|
||||
public class AndroidLoggerAdapter extends MarkerIgnoringBase {
|
||||
private static final long serialVersionUID = -1227274521521287937L;
|
||||
|
||||
/**
|
||||
* Package access allows only {@link AndroidLoggerFactory} to instantiate
|
||||
* SimpleLogger instances.
|
||||
*/
|
||||
AndroidLoggerAdapter(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this logger instance enabled for the VERBOSE level?
|
||||
*
|
||||
* @return True if this Logger is enabled for level VERBOSE, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return Log.isLoggable(name, Log.VERBOSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message object at level VERBOSE.
|
||||
*
|
||||
* @param msg
|
||||
* - the message object to be logged
|
||||
*/
|
||||
@Override
|
||||
public void trace(final String msg) {
|
||||
Log.v(name, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level VERBOSE according to the specified format and
|
||||
* argument.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for level VERBOSE.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg
|
||||
* the argument
|
||||
*/
|
||||
@Override
|
||||
public void trace(final String format, final Object arg) {
|
||||
if (Log.isLoggable(name, Log.VERBOSE)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
Log.v(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level VERBOSE according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the VERBOSE level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg1
|
||||
* the first argument
|
||||
* @param arg2
|
||||
* the second argument
|
||||
*/
|
||||
@Override
|
||||
public void trace(final String format, final Object arg1, final Object arg2) {
|
||||
if (Log.isLoggable(name, Log.VERBOSE)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
|
||||
Log.v(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level VERBOSE according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the VERBOSE level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param argArray
|
||||
* an array of arguments
|
||||
*/
|
||||
@Override
|
||||
public void trace(final String format, final Object... argArray) {
|
||||
if (Log.isLoggable(name, Log.VERBOSE)) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
Log.v(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an exception (throwable) at level VERBOSE with an accompanying message.
|
||||
*
|
||||
* @param msg
|
||||
* the message accompanying the exception
|
||||
* @param t
|
||||
* the exception (throwable) to log
|
||||
*/
|
||||
@Override
|
||||
public void trace(final String msg, final Throwable t) {
|
||||
Log.v(name, msg, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this logger instance enabled for the DEBUG level?
|
||||
*
|
||||
* @return True if this Logger is enabled for level DEBUG, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return Log.isLoggable(name, Log.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message object at level DEBUG.
|
||||
*
|
||||
* @param msg
|
||||
* - the message object to be logged
|
||||
*/
|
||||
@Override
|
||||
public void debug(final String msg) {
|
||||
Log.d(name, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level DEBUG according to the specified format and argument.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for level DEBUG.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg
|
||||
* the argument
|
||||
*/
|
||||
@Override
|
||||
public void debug(final String format, final Object arg) {
|
||||
if (Log.isLoggable(name, Log.DEBUG)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
Log.d(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level DEBUG according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the DEBUG level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg1
|
||||
* the first argument
|
||||
* @param arg2
|
||||
* the second argument
|
||||
*/
|
||||
@Override
|
||||
public void debug(final String format, final Object arg1, final Object arg2) {
|
||||
if (Log.isLoggable(name, Log.DEBUG)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
|
||||
Log.d(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level DEBUG according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the DEBUG level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param argArray
|
||||
* an array of arguments
|
||||
*/
|
||||
@Override
|
||||
public void debug(final String format, final Object... argArray) {
|
||||
if (Log.isLoggable(name, Log.DEBUG)) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
Log.d(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an exception (throwable) at level DEBUG with an accompanying message.
|
||||
*
|
||||
* @param msg
|
||||
* the message accompanying the exception
|
||||
* @param t
|
||||
* the exception (throwable) to log
|
||||
*/
|
||||
@Override
|
||||
public void debug(final String msg, final Throwable t) {
|
||||
Log.d(name, msg, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this logger instance enabled for the INFO level?
|
||||
*
|
||||
* @return True if this Logger is enabled for the INFO level, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return Log.isLoggable(name, Log.INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message object at the INFO level.
|
||||
*
|
||||
* @param msg
|
||||
* - the message object to be logged
|
||||
*/
|
||||
@Override
|
||||
public void info(final String msg) {
|
||||
Log.i(name, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level INFO according to the specified format and argument.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the INFO level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg
|
||||
* the argument
|
||||
*/
|
||||
@Override
|
||||
public void info(final String format, final Object arg) {
|
||||
if (Log.isLoggable(name, Log.INFO)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
Log.i(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the INFO level according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the INFO level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg1
|
||||
* the first argument
|
||||
* @param arg2
|
||||
* the second argument
|
||||
*/
|
||||
@Override
|
||||
public void info(final String format, final Object arg1, final Object arg2) {
|
||||
if (Log.isLoggable(name, Log.INFO)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
|
||||
Log.i(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level INFO according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the INFO level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param argArray
|
||||
* an array of arguments
|
||||
*/
|
||||
@Override
|
||||
public void info(final String format, final Object... argArray) {
|
||||
if (Log.isLoggable(name, Log.INFO)) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
Log.i(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an exception (throwable) at the INFO level with an accompanying
|
||||
* message.
|
||||
*
|
||||
* @param msg
|
||||
* the message accompanying the exception
|
||||
* @param t
|
||||
* the exception (throwable) to log
|
||||
*/
|
||||
@Override
|
||||
public void info(final String msg, final Throwable t) {
|
||||
Log.i(name, msg, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this logger instance enabled for the WARN level?
|
||||
*
|
||||
* @return True if this Logger is enabled for the WARN level, false
|
||||
* otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return Log.isLoggable(name, Log.WARN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message object at the WARN level.
|
||||
*
|
||||
* @param msg
|
||||
* - the message object to be logged
|
||||
*/
|
||||
@Override
|
||||
public void warn(final String msg) {
|
||||
Log.w(name, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the WARN level according to the specified format and
|
||||
* argument.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the WARN level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg
|
||||
* the argument
|
||||
*/
|
||||
@Override
|
||||
public void warn(final String format, final Object arg) {
|
||||
if (Log.isLoggable(name, Log.WARN)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
Log.w(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the WARN level according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the WARN level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg1
|
||||
* the first argument
|
||||
* @param arg2
|
||||
* the second argument
|
||||
*/
|
||||
@Override
|
||||
public void warn(final String format, final Object arg1, final Object arg2) {
|
||||
if (Log.isLoggable(name, Log.WARN)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
|
||||
Log.w(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level WARN according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the WARN level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param argArray
|
||||
* an array of arguments
|
||||
*/
|
||||
@Override
|
||||
public void warn(final String format, final Object... argArray) {
|
||||
if (Log.isLoggable(name, Log.WARN)) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
Log.w(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an exception (throwable) at the WARN level with an accompanying
|
||||
* message.
|
||||
*
|
||||
* @param msg
|
||||
* the message accompanying the exception
|
||||
* @param t
|
||||
* the exception (throwable) to log
|
||||
*/
|
||||
@Override
|
||||
public void warn(final String msg, final Throwable t) {
|
||||
Log.w(name, msg, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this logger instance enabled for level ERROR?
|
||||
*
|
||||
* @return True if this Logger is enabled for level ERROR, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return Log.isLoggable(name, Log.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message object at the ERROR level.
|
||||
*
|
||||
* @param msg
|
||||
* - the message object to be logged
|
||||
*/
|
||||
@Override
|
||||
public void error(final String msg) {
|
||||
Log.e(name, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the ERROR level according to the specified format and
|
||||
* argument.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the ERROR level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg
|
||||
* the argument
|
||||
*/
|
||||
@Override
|
||||
public void error(final String format, final Object arg) {
|
||||
if (Log.isLoggable(name, Log.ERROR)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
Log.e(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the ERROR level according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the ERROR level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param arg1
|
||||
* the first argument
|
||||
* @param arg2
|
||||
* the second argument
|
||||
*/
|
||||
@Override
|
||||
public void error(final String format, final Object arg1, final Object arg2) {
|
||||
if (Log.isLoggable(name, Log.ERROR)) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
|
||||
Log.e(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at level ERROR according to the specified format and
|
||||
* arguments.
|
||||
*
|
||||
* <p>
|
||||
* This form avoids superfluous object creation when the logger is disabled
|
||||
* for the ERROR level.
|
||||
* </p>
|
||||
*
|
||||
* @param format
|
||||
* the format string
|
||||
* @param argArray
|
||||
* an array of arguments
|
||||
*/
|
||||
@Override
|
||||
public void error(final String format, final Object... argArray) {
|
||||
if (Log.isLoggable(name, Log.ERROR)) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
Log.e(name, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an exception (throwable) at the ERROR level with an accompanying
|
||||
* message.
|
||||
*
|
||||
* @param msg
|
||||
* the message accompanying the exception
|
||||
* @param t
|
||||
* the exception (throwable) to log
|
||||
*/
|
||||
@Override
|
||||
public void error(final String msg, final Throwable t) {
|
||||
Log.e(name, msg, t);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2011 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
|
||||
import android.util.Log;
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* AndroidLoggerFactory is an implementation of {@link ILoggerFactory} returning
|
||||
* the appropriately named {@link AndroidLoggerFactory} instance.
|
||||
*
|
||||
* @author Andrey Korzhevskiy
|
||||
*/
|
||||
public class AndroidLoggerFactory implements ILoggerFactory {
|
||||
private final Map<String, Logger> loggerMap;
|
||||
|
||||
static final int TAG_MAX_LENGTH = 23; // tag names cannot be longer on Android platform
|
||||
// see also android/system/core/include/cutils/property.h
|
||||
// and android/frameworks/base/core/jni/android_util_Log.cpp
|
||||
|
||||
public AndroidLoggerFactory() {
|
||||
loggerMap = new HashMap<String, Logger>();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.slf4j.ILoggerFactory#getLogger(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Logger getLogger(String name) {
|
||||
final String passedName = name;
|
||||
name = forceValidName(passedName); // fix for bug #173
|
||||
if (!passedName.equals(name)) {
|
||||
Log.i(AndroidLoggerFactory.class.getSimpleName(),
|
||||
"Logger name '" + passedName + "' exceeds maximum length of " + TAG_MAX_LENGTH +
|
||||
" characters, using '" + name + "' instead.");
|
||||
}
|
||||
Logger ulogger;
|
||||
// protect against concurrent access of loggerMap
|
||||
synchronized (this) {
|
||||
ulogger = loggerMap.get(name);
|
||||
if (ulogger == null) {
|
||||
ulogger = new AndroidLoggerAdapter(name);
|
||||
loggerMap.put(name, ulogger);
|
||||
}
|
||||
}
|
||||
return ulogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim name in case it exceeds maximum length of {@value #TAG_MAX_LENGTH} characters.
|
||||
*/
|
||||
private static String forceValidName(String name) {
|
||||
if (name != null && name.length() > TAG_MAX_LENGTH) {
|
||||
final StringTokenizer st = new StringTokenizer(name, ".");
|
||||
if (st.hasMoreTokens()) { // note that empty tokens are skipped, i.e., "aa..bb" has tokens "aa", "bb"
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
String token;
|
||||
do {
|
||||
token = st.nextToken();
|
||||
if (token.length() == 1) { // token of one character appended as is
|
||||
sb.append(token);
|
||||
sb.append('.');
|
||||
} else if (st.hasMoreTokens()) { // truncate all but the last token
|
||||
sb.append(token.charAt(0));
|
||||
sb.append("*.");
|
||||
} else { // last token (usually class name) appended as is
|
||||
sb.append(token);
|
||||
}
|
||||
} while (st.hasMoreTokens());
|
||||
|
||||
name = sb.toString();
|
||||
}
|
||||
|
||||
// Either we had no useful dot location at all or name still too long.
|
||||
// Take leading part and append '*' to indicate that it was truncated
|
||||
if (name.length() > TAG_MAX_LENGTH) {
|
||||
name = name.substring(0, TAG_MAX_LENGTH - 1) + '*';
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2011 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.spi.LoggerFactoryBinder;
|
||||
|
||||
/**
|
||||
* The binding of {@link LoggerFactory} class with an actual instance of
|
||||
* {@link ILoggerFactory} is performed using information returned by this class.
|
||||
*
|
||||
* @author Ceki Gülcü
|
||||
*/
|
||||
public class StaticLoggerBinder implements LoggerFactoryBinder {
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
|
||||
|
||||
/**
|
||||
* Return the singleton of this class.
|
||||
*
|
||||
* @return the StaticLoggerBinder singleton
|
||||
*/
|
||||
public static StaticLoggerBinder getSingleton() {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare the version of the SLF4J API this implementation is compiled against.
|
||||
* The value of this field is usually modified with each release.
|
||||
*/
|
||||
// to avoid constant folding by the compiler, this field must *not* be final
|
||||
public static String REQUESTED_API_VERSION = "1.6.99"; // !final
|
||||
|
||||
|
||||
private static final String loggerFactoryClassStr = AndroidLoggerFactory.class.getName();
|
||||
|
||||
/**
|
||||
* The ILoggerFactory instance returned by the {@link #getLoggerFactory} method
|
||||
* should always be the same object
|
||||
*/
|
||||
private final ILoggerFactory loggerFactory;
|
||||
|
||||
private StaticLoggerBinder() {
|
||||
loggerFactory = new AndroidLoggerFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
return loggerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoggerFactoryClassStr() {
|
||||
return loggerFactoryClassStr;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2011 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
|
||||
import org.slf4j.helpers.BasicMDCAdapter;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
|
||||
|
||||
/**
|
||||
* This implementation is bound to {@link BasicMDCAdapter}.
|
||||
*
|
||||
* @author Ceki Gülcü
|
||||
*/
|
||||
public class StaticMDCBinder {
|
||||
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
|
||||
|
||||
private StaticMDCBinder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently this method always returns an instance of
|
||||
* {@link BasicMDCAdapter}.
|
||||
*/
|
||||
public MDCAdapter getMDCA() {
|
||||
// note that this method is invoked only from within the static initializer of
|
||||
// the org.slf4j.MDC class.
|
||||
return new BasicMDCAdapter();
|
||||
}
|
||||
|
||||
public String getMDCAdapterClassStr() {
|
||||
return BasicMDCAdapter.class.getName();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2011 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
|
||||
import org.slf4j.IMarkerFactory;
|
||||
import org.slf4j.MarkerFactory;
|
||||
import org.slf4j.helpers.BasicMarkerFactory;
|
||||
import org.slf4j.spi.MarkerFactoryBinder;
|
||||
|
||||
/**
|
||||
*
|
||||
* The binding of {@link MarkerFactory} class with an actual instance of
|
||||
* {@link IMarkerFactory} is performed using information returned by this class.
|
||||
*
|
||||
* @author Ceki Gülcü
|
||||
*/
|
||||
public class StaticMarkerBinder implements MarkerFactoryBinder {
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
|
||||
|
||||
final IMarkerFactory markerFactory = new BasicMarkerFactory();
|
||||
|
||||
private StaticMarkerBinder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently this method always returns an instance of
|
||||
* {@link BasicMarkerFactory}.
|
||||
*/
|
||||
public IMarkerFactory getMarkerFactory() {
|
||||
return markerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently, this method returns the class name of
|
||||
* {@link BasicMarkerFactory}.
|
||||
*/
|
||||
public String getMarkerFactoryClassStr() {
|
||||
return BasicMarkerFactory.class.getName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Implementation-Title: slf4j-android
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-SymbolicName: slf4j.android
|
||||
Bundle-Name: slf4j-android
|
||||
Bundle-Vendor: SLF4J.ORG
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Export-Package: org.slf4j.impl;version=${parsedVersion.osgiVersion}
|
||||
Import-Package: org.slf4j;version=${parsedVersion.osgiVersion}, org.slf4j.spi;version=${parsedVersion.osgiVersion}, org.slf4j.helpers;version=${parsedVersion.osgiVersion}
|
||||
Fragment-Host: slf4j.api
|
||||
Loading…
Reference in New Issue