Initial import into curated projects

master
nathan 2016-03-12 03:05:16 +01:00
parent b514954f58
commit 66d6485f21
12 changed files with 502 additions and 318 deletions

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/.svn/*" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

6
.gitignore vendored
View File

@ -1,6 +0,0 @@
*.jar
*.class
*.log
*.tar.gz
target/
*.DS_Store

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>minlog</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

11
LICENSE Normal file
View File

@ -0,0 +1,11 @@
- MinLogToSLF4j - BSD 3-clause License
https://github.com/dorkbox
https://github.com/EsotericSoftware/minlog
Copyright 2008, Nathan Sweet
Dan Brown
dorkbox, llc
- SLF4J - MIT License
http://www.slf4j.org
Copyright 2004-2008, QOS.ch

26
LICENSE.BSD3 Normal file
View File

@ -0,0 +1,26 @@
BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <ORGANIZATION> nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <ORGANIZATION> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

21
LICENSE.MIT Normal file
View File

@ -0,0 +1,21 @@
MIT License
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.

View File

@ -1,19 +1,28 @@
Drop-in replacement for [minlog](http://code.google.com/p/minlog), forked from http://minlog.googlecode.com/svn using `git svn`.
Drop-in replacement for [minlog](https://github.com/EsotericSoftware/minlog).
* Logs through slf4j instead of printing directly to stdout
* Suppresses no log levels at compile time so you can control them in your logging config instead
```xml
<dependency>
<groupId>com.esotericsoftware.minlog</groupId>
<artifactId>minlog</artifactId>
<version>1.2-slf4j-jdanbrown-0</version>
</dependency>
...
<repository>
<id>premise</id>
<url>http://premise.artifactoryonline.com/premise/public</url>
</repository>
<h4>We now release to maven!</h4>
```
<dependency>
<groupId>com.dorkbox</groupId>
<artifactId>MinLog-SLF4J</artifactId>
<version>1.2</version>
</dependency>
```
Or if you don't want to use Maven, you can access the files directly here:
https://oss.sonatype.org/content/repositories/releases/com/dorkbox/MinLog-SLF4J/
https://repo1.maven.org/maven2/org/slf4j/slf4j-api/
<h2>License</h2>
This project is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further references.

View File

@ -1,10 +0,0 @@
Copyright (c) 2008, Nathan Sweet
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

69
pom.xml
View File

@ -1,69 +0,0 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.esotericsoftware.minlog</groupId>
<artifactId>minlog</artifactId>
<version>1.2-slf4j-jdanbrown-0</version>
<packaging>jar</packaging>
<name>MinLog</name>
<description>Minimal overhead Java logging</description>
<url>http://code.google.com/p/minlog/</url>
<licenses>
<license>
<name>New BSD License</name>
<url>http://www.opensource.org/licenses/bsd-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>http://minlog.googlecode.com/svn/</url>
<connection>scm:svn:http://minlog.googlecode.com/svn/</connection>
</scm>
<developers>
<developer>
<id>nathan.sweet</id>
<name>Nathan Sweet</name>
<email>nathan.sweet@gmail.com</email>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
<build>
<!-- Set nonstandard source dir -->
<sourceDirectory>src</sourceDirectory>
<plugins>
<!-- Disable resources (project has none) -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-resources</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testResources</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1 +0,0 @@
version: 1.2

217
src/MinLog-SLF4J.iml Normal file
View File

@ -0,0 +1,217 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/..">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="logging slf4j-api (1.7.5)" level="application" />
</component>
<component name="org.twodividedbyzero.idea.findbugs">
<option name="_basePreferences">
<map>
<entry key="property.analysisEffortLevel" value="default" />
<entry key="property.analyzeAfterAutoMake" value="false" />
<entry key="property.analyzeAfterCompile" value="false" />
<entry key="property.annotationGutterIconEnabled" value="true" />
<entry key="property.annotationSuppressWarningsClass" value="edu.umd.cs.findbugs.annotations.SuppressFBWarnings" />
<entry key="property.annotationTextRangeMarkupEnabled" value="true" />
<entry key="property.exportAsHtml" value="true" />
<entry key="property.exportAsXml" value="true" />
<entry key="property.exportBaseDir" value="" />
<entry key="property.exportCreateArchiveDir" value="false" />
<entry key="property.exportOpenBrowser" value="true" />
<entry key="property.minPriorityToReport" value="Medium" />
<entry key="property.runAnalysisInBackground" value="false" />
<entry key="property.showHiddenDetectors" value="false" />
<entry key="property.toolWindowToFront" value="true" />
</map>
</option>
<option name="_detectors">
<map>
<entry key="AppendingToAnObjectOutputStream" value="true" />
<entry key="AtomicityProblem" value="true" />
<entry key="BadAppletConstructor" value="false" />
<entry key="BadResultSetAccess" value="true" />
<entry key="BadSyntaxForRegularExpression" value="true" />
<entry key="BadUseOfReturnValue" value="true" />
<entry key="BadlyOverriddenAdapter" value="true" />
<entry key="BooleanReturnNull" value="true" />
<entry key="BuildInterproceduralCallGraph" value="false" />
<entry key="BuildObligationPolicyDatabase" value="true" />
<entry key="BuildStringPassthruGraph" value="true" />
<entry key="CallToUnsupportedMethod" value="false" />
<entry key="CalledMethods" value="true" />
<entry key="CheckCalls" value="false" />
<entry key="CheckExpectedWarnings" value="false" />
<entry key="CheckImmutableAnnotation" value="true" />
<entry key="CheckRelaxingNullnessAnnotation" value="true" />
<entry key="CheckTypeQualifiers" value="true" />
<entry key="CloneIdiom" value="true" />
<entry key="ComparatorIdiom" value="true" />
<entry key="ConfusedInheritance" value="true" />
<entry key="ConfusionBetweenInheritedAndOuterMethod" value="true" />
<entry key="CovariantArrayAssignment" value="false" />
<entry key="CrossSiteScripting" value="true" />
<entry key="DefaultEncodingDetector" value="true" />
<entry key="DoInsideDoPrivileged" value="true" />
<entry key="DontCatchIllegalMonitorStateException" value="true" />
<entry key="DontIgnoreResultOfPutIfAbsent" value="true" />
<entry key="DontUseEnum" value="true" />
<entry key="DroppedException" value="true" />
<entry key="DumbMethodInvocations" value="true" />
<entry key="DumbMethods" value="true" />
<entry key="DuplicateBranches" value="true" />
<entry key="EmptyZipFileEntry" value="false" />
<entry key="EqualsOperandShouldHaveClassCompatibleWithThis" value="true" />
<entry key="ExplicitSerialization" value="true" />
<entry key="FieldItemSummary" value="true" />
<entry key="FinalizerNullsFields" value="true" />
<entry key="FindBadCast2" value="true" />
<entry key="FindBadForLoop" value="true" />
<entry key="FindBugsSummaryStats" value="true" />
<entry key="FindCircularDependencies" value="false" />
<entry key="FindComparatorProblems" value="true" />
<entry key="FindDeadLocalStores" value="true" />
<entry key="FindDoubleCheck" value="true" />
<entry key="FindEmptySynchronizedBlock" value="true" />
<entry key="FindFieldSelfAssignment" value="true" />
<entry key="FindFinalizeInvocations" value="true" />
<entry key="FindFloatEquality" value="true" />
<entry key="FindFloatMath" value="false" />
<entry key="FindHEmismatch" value="true" />
<entry key="FindInconsistentSync2" value="true" />
<entry key="FindJSR166LockMonitorenter" value="true" />
<entry key="FindLocalSelfAssignment2" value="true" />
<entry key="FindMaskedFields" value="true" />
<entry key="FindMismatchedWaitOrNotify" value="true" />
<entry key="FindNakedNotify" value="true" />
<entry key="FindNoSideEffectMethods" value="true" />
<entry key="FindNonSerializableStoreIntoSession" value="false" />
<entry key="FindNonSerializableValuePassedToWriteObject" value="false" />
<entry key="FindNonShortCircuit" value="true" />
<entry key="FindNullDeref" value="true" />
<entry key="FindNullDerefsInvolvingNonShortCircuitEvaluation" value="true" />
<entry key="FindOpenStream" value="true" />
<entry key="FindPuzzlers" value="true" />
<entry key="FindRefComparison" value="true" />
<entry key="FindReturnRef" value="true" />
<entry key="FindRoughConstants" value="true" />
<entry key="FindRunInvocations" value="true" />
<entry key="FindSelfComparison" value="true" />
<entry key="FindSelfComparison2" value="true" />
<entry key="FindSleepWithLockHeld" value="true" />
<entry key="FindSpinLoop" value="true" />
<entry key="FindSqlInjection" value="true" />
<entry key="FindTwoLockWait" value="true" />
<entry key="FindUncalledPrivateMethods" value="true" />
<entry key="FindUnconditionalWait" value="true" />
<entry key="FindUninitializedGet" value="true" />
<entry key="FindUnrelatedTypesInGenericContainer" value="true" />
<entry key="FindUnreleasedLock" value="true" />
<entry key="FindUnsatisfiedObligation" value="true" />
<entry key="FindUnsyncGet" value="true" />
<entry key="FindUseOfNonSerializableValue" value="true" />
<entry key="FindUselessControlFlow" value="true" />
<entry key="FindUselessObjects" value="true" />
<entry key="FormatStringChecker" value="true" />
<entry key="FunctionsThatMightBeMistakenForProcedures" value="true" />
<entry key="HugeSharedStringConstants" value="true" />
<entry key="IDivResultCastToDouble" value="true" />
<entry key="IncompatMask" value="true" />
<entry key="InconsistentAnnotations" value="true" />
<entry key="InefficientIndexOf" value="false" />
<entry key="InefficientInitializationInsideLoop" value="false" />
<entry key="InefficientMemberAccess" value="false" />
<entry key="InefficientToArray" value="false" />
<entry key="InfiniteLoop" value="true" />
<entry key="InfiniteRecursiveLoop" value="true" />
<entry key="InheritanceUnsafeGetResource" value="true" />
<entry key="InitializationChain" value="true" />
<entry key="InitializeNonnullFieldsInConstructor" value="true" />
<entry key="InstantiateStaticClass" value="true" />
<entry key="IntCast2LongAsInstant" value="true" />
<entry key="InvalidJUnitTest" value="true" />
<entry key="IteratorIdioms" value="true" />
<entry key="LazyInit" value="true" />
<entry key="LoadOfKnownNullValue" value="true" />
<entry key="LostLoggerDueToWeakReference" value="true" />
<entry key="MethodReturnCheck" value="true" />
<entry key="Methods" value="true" />
<entry key="MultithreadedInstanceAccess" value="true" />
<entry key="MutableEnum" value="true" />
<entry key="MutableLock" value="true" />
<entry key="MutableStaticFields" value="true" />
<entry key="Naming" value="true" />
<entry key="Noise" value="false" />
<entry key="NoiseNullDeref" value="false" />
<entry key="NoteAnnotationRetention" value="true" />
<entry key="NoteCheckReturnValueAnnotations" value="true" />
<entry key="NoteDirectlyRelevantTypeQualifiers" value="true" />
<entry key="NoteJCIPAnnotation" value="true" />
<entry key="NoteNonNullAnnotations" value="false" />
<entry key="NoteNonnullReturnValues" value="false" />
<entry key="NoteSuppressedWarnings" value="true" />
<entry key="NoteUnconditionalParamDerefs" value="true" />
<entry key="NumberConstructor" value="true" />
<entry key="OptionalReturnNull" value="true" />
<entry key="OverridingEqualsNotSymmetrical" value="true" />
<entry key="PreferZeroLengthArrays" value="true" />
<entry key="PublicSemaphores" value="false" />
<entry key="QuestionableBooleanAssignment" value="true" />
<entry key="ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass" value="true" />
<entry key="ReadReturnShouldBeChecked" value="true" />
<entry key="RedundantConditions" value="true" />
<entry key="RedundantInterfaces" value="true" />
<entry key="ReflectiveClasses" value="true" />
<entry key="RepeatedConditionals" value="true" />
<entry key="ResolveAllReferences" value="false" />
<entry key="RuntimeExceptionCapture" value="true" />
<entry key="SerializableIdiom" value="true" />
<entry key="StartInConstructor" value="true" />
<entry key="StaticCalendarDetector" value="true" />
<entry key="StringConcatenation" value="true" />
<entry key="SuperfluousInstanceOf" value="true" />
<entry key="SuspiciousThreadInterrupted" value="true" />
<entry key="SwitchFallthrough" value="true" />
<entry key="SynchronizationOnSharedBuiltinConstant" value="true" />
<entry key="SynchronizeAndNullCheckField" value="true" />
<entry key="SynchronizeOnClassLiteralNotGetClass" value="true" />
<entry key="SynchronizingOnContentsOfFieldToProtectField" value="true" />
<entry key="TestASM" value="false" />
<entry key="TestDataflowAnalysis" value="false" />
<entry key="TestingGround" value="false" />
<entry key="TestingGround2" value="false" />
<entry key="TrainFieldStoreTypes" value="true" />
<entry key="TrainLongInstantfParams" value="true" />
<entry key="TrainNonNullAnnotations" value="true" />
<entry key="TrainUnconditionalDerefParams" value="true" />
<entry key="URLProblems" value="true" />
<entry key="UncallableMethodOfAnonymousClass" value="true" />
<entry key="UnnecessaryMath" value="true" />
<entry key="UnreadFields" value="true" />
<entry key="UselessSubclassMethod" value="false" />
<entry key="VarArgsProblems" value="true" />
<entry key="VolatileUsage" value="true" />
<entry key="WaitInLoop" value="true" />
<entry key="WrongMapIterator" value="true" />
<entry key="XMLFactoryBypass" value="true" />
</map>
</option>
<option name="_reportCategories">
<map>
<entry key="BAD_PRACTICE" value="true" />
<entry key="CORRECTNESS" value="true" />
<entry key="EXPERIMENTAL" value="true" />
<entry key="I18N" value="true" />
<entry key="MALICIOUS_CODE" value="true" />
<entry key="MT_CORRECTNESS" value="true" />
<entry key="PERFORMANCE" value="true" />
<entry key="SECURITY" value="true" />
<entry key="STYLE" value="true" />
</map>
</option>
</component>
</module>

View File

@ -1,197 +1,206 @@
package com.esotericsoftware.minlog;
/**
* A low overhead, lightweight logging system.
* @author Nathan Sweet <misc@n4te.com>
*/
public class Log {
/** No logging at all. */
static public final int LEVEL_NONE = 6;
/** Critical errors. The application may no longer work correctly. */
static public final int LEVEL_ERROR = 5;
/** Important warnings. The application will continue to work correctly. */
static public final int LEVEL_WARN = 4;
/** Informative messages. Typically used for deployment. */
static public final int LEVEL_INFO = 3;
/** Debug messages. This level is useful during development. */
static public final int LEVEL_DEBUG = 2;
/** Trace messages. A lot of information is logged, so this level is usually only needed when debugging a problem. */
static public final int LEVEL_TRACE = 1;
/**
* The level of messages that will be logged. Compiling this and the booleans below as "final" will cause the compiler to
* remove all "if (Log.info) ..." type statements below the set level.
*/
static private int level = LEVEL_TRACE; // Log everything to delegate control to slf4j
/** True when the ERROR level will be logged. */
static public boolean ERROR = level <= LEVEL_ERROR;
/** True when the WARN level will be logged. */
static public boolean WARN = level <= LEVEL_WARN;
/** True when the INFO level will be logged. */
static public boolean INFO = level <= LEVEL_INFO;
/** True when the DEBUG level will be logged. */
static public boolean DEBUG = level <= LEVEL_DEBUG;
/** True when the TRACE level will be logged. */
static public boolean TRACE = level <= LEVEL_TRACE;
/**
* Sets the level to log. If a version of this class is being used that has a final log level, this has no affect.
*/
static public void set (int level) {
// Comment out method contents when compiling fixed level JARs.
Log.level = level;
ERROR = level <= LEVEL_ERROR;
WARN = level <= LEVEL_WARN;
INFO = level <= LEVEL_INFO;
DEBUG = level <= LEVEL_DEBUG;
TRACE = level <= LEVEL_TRACE;
}
static public void NONE () {
set(LEVEL_NONE);
}
static public void ERROR () {
set(LEVEL_ERROR);
}
static public void WARN () {
set(LEVEL_WARN);
}
static public void INFO () {
set(LEVEL_INFO);
}
static public void DEBUG () {
set(LEVEL_DEBUG);
}
static public void TRACE () {
set(LEVEL_TRACE);
}
/**
* Sets the logger that will write the log messages.
*/
static public void setLogger (Logger logger) {
Log.logger = logger;
}
static private Logger logger = new Logger();
static public void error (String message, Throwable ex) {
if (ERROR) logger.log(LEVEL_ERROR, null, message, ex);
}
static public void error (String category, String message, Throwable ex) {
if (ERROR) logger.log(LEVEL_ERROR, category, message, ex);
}
static public void error (String message) {
if (ERROR) logger.log(LEVEL_ERROR, null, message, null);
}
static public void error (String category, String message) {
if (ERROR) logger.log(LEVEL_ERROR, category, message, null);
}
static public void warn (String message, Throwable ex) {
if (WARN) logger.log(LEVEL_WARN, null, message, ex);
}
static public void warn (String category, String message, Throwable ex) {
if (WARN) logger.log(LEVEL_WARN, category, message, ex);
}
static public void warn (String message) {
if (WARN) logger.log(LEVEL_WARN, null, message, null);
}
static public void warn (String category, String message) {
if (WARN) logger.log(LEVEL_WARN, category, message, null);
}
static public void info (String message, Throwable ex) {
if (INFO) logger.log(LEVEL_INFO, null, message, ex);
}
static public void info (String category, String message, Throwable ex) {
if (INFO) logger.log(LEVEL_INFO, category, message, ex);
}
static public void info (String message) {
if (INFO) logger.log(LEVEL_INFO, null, message, null);
}
static public void info (String category, String message) {
if (INFO) logger.log(LEVEL_INFO, category, message, null);
}
static public void debug (String message, Throwable ex) {
if (DEBUG) logger.log(LEVEL_DEBUG, null, message, ex);
}
static public void debug (String category, String message, Throwable ex) {
if (DEBUG) logger.log(LEVEL_DEBUG, category, message, ex);
}
static public void debug (String message) {
if (DEBUG) logger.log(LEVEL_DEBUG, null, message, null);
}
static public void debug (String category, String message) {
if (DEBUG) logger.log(LEVEL_DEBUG, category, message, null);
}
static public void trace (String message, Throwable ex) {
if (TRACE) logger.log(LEVEL_TRACE, null, message, ex);
}
static public void trace (String category, String message, Throwable ex) {
if (TRACE) logger.log(LEVEL_TRACE, category, message, ex);
}
static public void trace (String message) {
if (TRACE) logger.log(LEVEL_TRACE, null, message, null);
}
static public void trace (String category, String message) {
if (TRACE) logger.log(LEVEL_TRACE, category, message, null);
}
private Log () {
}
/**
* Performs the actual logging. Default implementation logs to slf4j. Extended and use {@link Log#logger} set to handle
* logging differently.
*/
static public class Logger {
// Log as "com.esotericsoftware.minlog"
public final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Logger.class.getPackage().getName());
public void log (int level, String category, String message, Throwable ex) {
if (level == LEVEL_NONE) {
return;
}
StringBuilder builder = new StringBuilder(256);
if (category != null) {
builder.append(category);
builder.append(": ");
}
builder.append(message);
String line = builder.toString();
switch (level) {
case LEVEL_ERROR: logger.error (line, ex); break;
case LEVEL_WARN: logger.warn (line, ex); break;
case LEVEL_INFO: logger.info (line, ex); break;
case LEVEL_DEBUG: logger.debug (line, ex); break;
case LEVEL_TRACE: logger.trace (line, ex); break;
}
}
}
}
package com.esotericsoftware.minlog;
/**
* A low overhead, lightweight logging system.
* @author Nathan Sweet <misc@n4te.com>
*/
public class Log {
/** No logging at all. */
static public final int LEVEL_NONE = 6;
/** Critical errors. The application may no longer work correctly. */
static public final int LEVEL_ERROR = 5;
/** Important warnings. The application will continue to work correctly. */
static public final int LEVEL_WARN = 4;
/** Informative messages. Typically used for deployment. */
static public final int LEVEL_INFO = 3;
/** Debug messages. This level is useful during development. */
static public final int LEVEL_DEBUG = 2;
/** Trace messages. A lot of information is logged, so this level is usually only needed when debugging a problem. */
static public final int LEVEL_TRACE = 1;
/**
* The level of messages that will be logged. Compiling this and the booleans below as "final" will cause the compiler to
* remove all "if (Log.info) ..." type statements below the set level.
*/
static private int level = LEVEL_TRACE; // Log everything to delegate control to slf4j
/** True when the ERROR level will be logged. */
static public boolean ERROR = level <= LEVEL_ERROR;
/** True when the WARN level will be logged. */
static public boolean WARN = level <= LEVEL_WARN;
/** True when the INFO level will be logged. */
static public boolean INFO = level <= LEVEL_INFO;
/** True when the DEBUG level will be logged. */
static public boolean DEBUG = level <= LEVEL_DEBUG;
/** True when the TRACE level will be logged. */
static public boolean TRACE = level <= LEVEL_TRACE;
/**
* Gets the version number.
*/
public static
String getVersion() {
return "1.2";
}
/**
* Sets the level to log. If a version of this class is being used that has a final log level, this has no affect.
*/
static public void set (int level) {
// Comment out method contents when compiling fixed level JARs.
Log.level = level;
ERROR = level <= LEVEL_ERROR;
WARN = level <= LEVEL_WARN;
INFO = level <= LEVEL_INFO;
DEBUG = level <= LEVEL_DEBUG;
TRACE = level <= LEVEL_TRACE;
}
static public void NONE () {
set(LEVEL_NONE);
}
static public void ERROR () {
set(LEVEL_ERROR);
}
static public void WARN () {
set(LEVEL_WARN);
}
static public void INFO () {
set(LEVEL_INFO);
}
static public void DEBUG () {
set(LEVEL_DEBUG);
}
static public void TRACE () {
set(LEVEL_TRACE);
}
/**
* Sets the logger that will write the log messages.
*/
static public void setLogger (Logger logger) {
Log.logger = logger;
}
static private Logger logger = new Logger();
static public void error (String message, Throwable ex) {
if (ERROR) logger.log(LEVEL_ERROR, null, message, ex);
}
static public void error (String category, String message, Throwable ex) {
if (ERROR) logger.log(LEVEL_ERROR, category, message, ex);
}
static public void error (String message) {
if (ERROR) logger.log(LEVEL_ERROR, null, message, null);
}
static public void error (String category, String message) {
if (ERROR) logger.log(LEVEL_ERROR, category, message, null);
}
static public void warn (String message, Throwable ex) {
if (WARN) logger.log(LEVEL_WARN, null, message, ex);
}
static public void warn (String category, String message, Throwable ex) {
if (WARN) logger.log(LEVEL_WARN, category, message, ex);
}
static public void warn (String message) {
if (WARN) logger.log(LEVEL_WARN, null, message, null);
}
static public void warn (String category, String message) {
if (WARN) logger.log(LEVEL_WARN, category, message, null);
}
static public void info (String message, Throwable ex) {
if (INFO) logger.log(LEVEL_INFO, null, message, ex);
}
static public void info (String category, String message, Throwable ex) {
if (INFO) logger.log(LEVEL_INFO, category, message, ex);
}
static public void info (String message) {
if (INFO) logger.log(LEVEL_INFO, null, message, null);
}
static public void info (String category, String message) {
if (INFO) logger.log(LEVEL_INFO, category, message, null);
}
static public void debug (String message, Throwable ex) {
if (DEBUG) logger.log(LEVEL_DEBUG, null, message, ex);
}
static public void debug (String category, String message, Throwable ex) {
if (DEBUG) logger.log(LEVEL_DEBUG, category, message, ex);
}
static public void debug (String message) {
if (DEBUG) logger.log(LEVEL_DEBUG, null, message, null);
}
static public void debug (String category, String message) {
if (DEBUG) logger.log(LEVEL_DEBUG, category, message, null);
}
static public void trace (String message, Throwable ex) {
if (TRACE) logger.log(LEVEL_TRACE, null, message, ex);
}
static public void trace (String category, String message, Throwable ex) {
if (TRACE) logger.log(LEVEL_TRACE, category, message, ex);
}
static public void trace (String message) {
if (TRACE) logger.log(LEVEL_TRACE, null, message, null);
}
static public void trace (String category, String message) {
if (TRACE) logger.log(LEVEL_TRACE, category, message, null);
}
private Log () {
}
/**
* Performs the actual logging. Default implementation logs to slf4j. Extended and use {@link Log#logger} set to handle
* logging differently.
*/
static public class Logger {
// Log as "com.esotericsoftware.minlog"
public final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Logger.class.getPackage().getName());
public void log (int level, String category, String message, Throwable ex) {
if (level == LEVEL_NONE) {
return;
}
StringBuilder builder = new StringBuilder(256);
if (category != null) {
builder.append(category);
builder.append(": ");
}
builder.append(message);
String line = builder.toString();
switch (level) {
case LEVEL_ERROR: logger.error (line, ex); break;
case LEVEL_WARN: logger.warn (line, ex); break;
case LEVEL_INFO: logger.info (line, ex); break;
case LEVEL_DEBUG: logger.debug (line, ex); break;
case LEVEL_TRACE: logger.trace (line, ex); break;
}
}
}
}