tinylog-org / tinylog Goto Github PK
View Code? Open in Web Editor NEWtinylog is a lightweight logging framework for Java, Kotlin, Scala, and Android
Home Page: https://tinylog.org
License: Apache License 2.0
tinylog is a lightweight logging framework for Java, Kotlin, Scala, and Android
Home Page: https://tinylog.org
License: Apache License 2.0
Hi, no real specific issue here. I just stumbled on this tool from https://github.com/akullpp/awesome-java#logging
This tool seems really nice as of 1.1 (what with the excellent documentation, RollingFileWriter, and the SLF4J binding)!
I was just wondering whether there are still plans to continue maintenance of 1.x and 2.0 development?
Either way, this looks great!
I am getting too much verbosity out of the apache packages when I set the logging level to Level.DEBUG, I tried to disable the logging on the apache stuff, but doesn't seem to work?
Configurator c = Configurator.currentConfig();
c.level(Level.DEBUG); // set everything to debug by default
// Trying to turn off other debug that I don't care
//c.level("org.apache.http.client", Level.OFF);
//c.level("org.apache.http.client.*", Level.OFF);
//c.level("org.apache.http.impl.client", Level.OFF);
//c.level("org.apache.commons.logging.simplelog.log.org.apache.http", Level.OFF);
//c.level("org.apache.commons.logging.simplelog.log.org.apache.http.wire", Level.OFF);
//c.level("org.apache.commons.logging.simplelog.log.org.apache.http.impl.conn", Level.OFF);
//c.level("org.apache.commons.logging.simplelog.log.org.apache.http.impl.client", Level.OFF);
//c.level("org.apache.commons.logging.simplelog.log.org.apache.http.client", Level.OFF);
c.level("org.apache.http.impl.client", Level.OFF);
c.formatPattern("{date:HH:mm:ss} {level|min-size=8} {message}");
c.activate();
Is this a bug? Or does the "package" only works for tinylog's package? What is the proper way to make it work?
If a file logger's filename contains a directory, creating the logger crashes if that directory does not exist.
For example:
tinylog.writer2 = rollingfile
tinylog.writer2.filename = logs/log.txt
tinylog.writer2.backups = 10
If I run this in a directory which does not yet contain a logs/ folder, the program crashes.
Given that the logfile itself is created at start-up, it seems reasonable that any folders in the filename should also be created.
Currently the console writer writes all log entries with severity levels trace, debug and info to the "standard" output stream (System.out
). Log entries with severity levels warning and error are written to the "standard" error output stream (System.err
).
The threshold for using the "standard" error output stream should be configurable. For example, if the threshold is trace, all log entries should be written to System.err
. If the threshold is off, all log entries should be written to System.out
. The default threshold is warning to be compatible with previous tinylog versions (severity levels trace, debug and info to System.out
and accordingly warning and error to System.err
).
Hi,
I have a big project with logback and slf4j and as a first step of converting it to tinylog I didn't want to use the static logger. Using the sfl4j-facade you provided makes it seem like a drop in replacement. The only issue/question I have is when I'm specifying a custom format I need access to the placeholder variable for the "logger":
tinylog.format = [{{level}|min-size=7}] [{date:MMMM dd, YYYY HH:mm:ss.SSS z}] [{thread}] [{logger}] {message}\n
In case of the static logger I could just go for class, method etc, but it's not a static one, so if I were to use class.method I'd get sth like (I'm using scala btw, but it wasn't an issue with logback etc):
net.liftweb.common.Logger$class.warn()
To be clear the class you see in there is not mine :)
So is there a way to get to the logger instance? like {logger} or {source} or {src}...
Cheers
Reimplementation of bridge to JBoss logging based application and web servers for tinylog 2.0:
We have a wrapper around TinyLog library, and when using our methods that delegate to TinyLog, the information that appears in the log for the placeholders {class}, {class_name} and {method} is the one of our wrapper.
Is it possible to select the "call stack level" to use for logging?
I don't know how to tag this as a feature request and not a bug, but I was wondering if it would be possible to trim or remove the anonymous class portion from the classname written by the logger?
For example,
In tinylog.writer1.format I have:
tinylog.writer1.format = {date:hh:mm:ss.SSS} | {level} | {class}: {message}
In my source file, WikiParser I use extensive logging using some java 8 streams and junk. Unfortunately, the messages are formatted as:
03:45:54.177 | INFO | edu.utdallas.hltri.copa.wiki.WikiParser$$anonfun$2$$anonfun$apply$2$$anonfun$apply$4$$anonfun$apply$6$$anonfun$apply$8$$anonfun$apply$10: [Parsing XML] Saved "Mekong"
What I would like to see:
03:45:54.177 | INFO | edu.utdallas.hltri.copa.wiki.WikiParser: [Parsing XML] Saved "Mekong"
It seems, naively, that it might be as simple as triming everything in the classpath after (and including) the first '$'. I would have done this myself, but I can't figure out how to implement a custom format and I can't override the existing behavior because everything is final.
Hello,
I try to setup a jdbcwriter but I got following errors:
LOGGER ERROR: Failed to activate configuration (java.sql.SQLException: No suitable driver found for jdbc:mysql://10.211.55.5:3306/XXXXXX)
However the mysql driver is in project path (class path) as well as in server lib (Tomcat). My application can access the mysql database.
Any suggestion? Did I miss a configuration?
Thx
Implementation of tinylog 1.x API for tinylog 2.0:
Reimplementation of bridge to java.util.logging based application and web servers for tinylog 2.0:
First of all, thank you very much for this useful log library! We are using it in kamon-agent.
For some integration tests we need to load tinylog
with the BootstrapClassLoader
, and this is when this problem manifests itself.
The problem happens when it tries to do things like this:
Configurator.class.getClassLoader().getResourceAsStream(file);
The calling Configurator.class.getClassLoader()
returns null since this is the way to say that it was loaded by the bootstrap class loader.
The fix is very simple. For example introducing a method like this:
private static InputStream getResourceFromFile(String file) {
final ClassLoader classLoader = Configurator.class.getClassLoader();
if (classLoader == null) {
return ClassLoader.getSystemResourceAsStream(file);
} else {
return classLoader.getResourceAsStream(file);
}
}
And call it from any place where the resource is required.
Let me know if you are agreed with this change and I'll be happy to send a PR.
It is not possible to add Tinylog 1.2 to a Maven-based project since Maven does not set dependencies to the classpath correctly when they are in .zip format.
Would it be possible to upload a .jar to Maven Central please?
Thanks for the project and your time.
Running SharedFileWriterTest on Linux I get test failures as described here: https://github.com/jotomo/tinylog/commit/0b41014894d5986d163e266411d993abaa1ca9ee, indicating a problem when writing to a log file concurrently.
@pmwmedia I'm assuming you're running Windows. TravisCI would run the tests on Linux - I've seen you tested TravisCI but dropped it again. Remember why?
Updated: running a Linux system natively, or a Linux VM on a Linux hosts, there are intermittend build failures in tests that inherit from AbstractTimeBasedPolicy (mostly in WeeklyPolicyTest). These failures occur 1-3 times out of 10 on an Arch Linux system (as December 2015). It seems that the SystemTimeMock is not thread-safe and occassionally returns the actual system time, leading to test failures.
Without having indent set in the formatting specs, a stacktrace logs like this:
02:11:41 DEBUG [ForkJoinPool-1-worker-9 ] Batch :75 : java.net.SocketTimeoutException: Read timed out
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
[...] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
[...]
Setting the formatting to something like ...{message|indent=2} yields this output:
02:00:07 DEBUG [ForkJoinPool-1-worker-15 ] Batch :75 : java.net.SocketTimeoutException: Read timed out
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
[...]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
[...]
Note how the cause exception header is indented by two spaces in the second example, as are all other lines. This removes the visual clue that allows to quickly jump between exceptions when reading through a stracktrace. Is this by design (indent hard-aligns everything by amount specificed), cause I find the visual clue very helpful ...
not sure where to report website issues, but, there seems to be error in the website example:
Configurator.defaultConfig()
.writer(new FileWriter("log.txt"))
.level(LoggingLevel.WARNING)
.activate();
I guess it should be:
Configurator.defaultConfig()
.writer(new FileWriter("log.txt"))
.level(Level.WARNING)
.activate();
Reimplementation of Apache Commons Logging (JCL) binding for tinylog 2.0:
Hi tinylog-creators,
with the jdbc configuation below I get the following output:
LOGGER WARNING: Unknown value type: "CONTEXT"
LOGGER ERROR: Failed to activate configuration (java.sql.SQLException: Number of columns and values must be equal, but columns = 8 and values = 7)
JDBC config:
tinylog.writer = jdbc
tinylog.writer.url = jdbc:mysql://localhost:3306/<db_name>
tinylog.writer.table = log_entries_table
tinylog.writer.columns = context, level, message, class, line, date, method, exception
tinylog.writer.values = CONTEXT, LEVEL, MESSAGE, CLASS, LINE, DATE, METHOD, EXCEPTION
For the context column I took a text datatype in the database (MySQL).
Everything other than CONTEXT works fine. How can I make this work?
Best regards
I'm using tinylog in my application with this configuration file
tinylog.level = warning
tinylog.writer = console
tinylog.format = {date:yyyy-MM-dd HH:mm:ss} {thread} {class}.{method} {line} {level}: {message}
but the item tinylog.format
is not used, but if I set it with -D"tinylog.format = {date:yyyy-MM-dd HH:mm:ss} {thread} {class}.{method} {line} {level}: {message}"
it works correctly. I'm using Logger.info
and Logger.error
directly without any other instantiation of tinylog
Reimplementation of rolling file writer for tinylog 2.0:
writer.file = logs/{date:YYYY}/{pid}.log
)I noticed a problem in how tinylog processes Java system properties. When (the equivilant of) -Dtinylog.level=debug is passed in on the command line, it does not appear to be processed correctly. Here is a test that reproduces the problem.
package org.tinylog.bugreport;
import org.junit.Test;
import org.pmw.tinylog.Logger;
import static org.junit.Assert.assertEquals;
public class SystemPropertyTest {
@Test
public void loggers() {
String tinylog_level = System.getProperty("tinylog.level");
Logger.info("tinylog.level=" + tinylog_level);
Logger.debug("Log level debug");
assertEquals(tinylog_level,Logger.getLevel().name());
}
}
Here is the gradle script that I used to compile and run the test.
apply plugin: 'java'
String _logLevel = hasProperty('logLevel') ? project.properties.get('logLevel'): 'info'
repositories {
jcenter()
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.tinylog:tinylog:1.0.1'
}
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
// Pass in upshifted logging level as a Java System Property to the test.
systemProperty 'tinylog.level', _logLevel.toUpperCase()
}
Using the above here is the result of the test when logLevel info is passed in, followed by logLevel debug.
tinylog.level=info
gradle -PlogLevel=info clean test
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
org.tinylog.bugreport.SystemPropertyTest > loggers STANDARD_OUT
2015-09-29 11:30:05 [Test worker] org.tinylog.bugreport.SystemPropertyTest.loggers()
INFO: tinylog.level=INFO
org.tinylog.bugreport.SystemPropertyTest > loggers PASSED
BUILD SUCCESSFUL
Total time: 1.523 secs
tinylog.level=debug
gradle -PlogLevel=debug clean test
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
org.tinylog.bugreport.SystemPropertyTest > loggers STANDARD_OUT
2015-09-29 11:31:07 [Test worker] org.tinylog.bugreport.SystemPropertyTest.loggers()
INFO: tinylog.level=DEBUG
org.tinylog.bugreport.SystemPropertyTest > loggers FAILED
org.junit.ComparisonFailure at SystemPropertyTest.java:15
1 test completed, 1 failed
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/michael.ottati/z-tmp/tinylog/build/reports/tests/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.57 secs
When I go back to the 0.8.1 version I had been using before (modifying the Logger.getLevel() call) this test works as expected, it passes at both tinylog.levels.
I could not step it though the initialization to see what happens there, it looks like this library ships without debug symbols.
Here are the first copule of lines of the failure exception in the gradle/JUnit html report that gets created by the build.
org.junit.ComparisonFailure: expected:<[DEBUG]> but was:<[INFO]>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at org.tinylog.bugreport.SystemPropertyTest.loggers(SystemPropertyTest.java:15)
Thanks for all the work that you do on this package, it has come in very handy where I work.
Reimplementation of Log4j 1.x API for tinylog 2.0:
See also Log4j 1.2 API for Apache Log4j 2.0:
https://github.com/apache/logging-log4j2/tree/master/log4j-1.2-api
Data sources are an alternative way to declare JDBC database connection for Java EE. On the most web servers, the classic way of creating database connections via DriverManager.getConnection()
works as well as via data sources. But tomcat, for example, doesn't support loading JDBC drivers as services out of the box. A clearcut solution would be to support data sources in JdbcWriter.
Data sources in Tomcat: https://wiki.apache.org/tomcat/UsingDataSources
Standard way: http://stackoverflow.com/questions/2279913/is-there-a-standard-way-to-define-a-jdbc-datasource-for-java-ee-containers#16261491
Reimplementation of shared file writer for tinylog 2.0:
On running tinylog with the -javaagent flag a NPE is thrown on the line https://github.com/pmwmedia/tinylog/blob/master/tinylog/src/main/java/org/pmw/tinylog/Logger.java#L45
The init() call cannot be run outside the package
FEATURE REQUEST
Please add a possibility for coloured console output.
Of course, coloured outputs could be deeply integrated into Tinylog. However, it also be simple with the following options:
I love tinylog and just migrated my whole project :-)
Would be great if you could consider my requerst.
Cheers,
Tobias
What is the rationale behind closing the prepared statements and re-building them either after each log message or after each batch execution? Could this be a performance bottleneck?
It would be great to compare tinylog's performance using log4j's own benchmarks
Hi, I recently started using tinylog and it's great.
However, I noticed that it outputs log files to the character set default of the platform (i.e. on OSX it's UTF-8 and on Windows it's ANSI).
It would be good if one could specify the output character set or otherwise enforce UTF-8 across the board (which is actually what I'm after)
Implement JMH benchmarks to compare tinylog 2.0 with other logging frameworks. Logging format pattern and stack trace depth should be configurable.
I am using tinylog for various features it has. My application needs a very fast asynchronous logging. I can able to log happily. I have only two issues.
All my error logs and the info, some debug logs are jumbled into a single file. How can I separate these, such that they come into a single file say "errors.log" and info strings come into another file say "messages.log"?
I want the timestamp to be in microseconds that mean like, data: Time in "HH:mm:ss:milli-seconds:Micro-seconds". Is there any way to do?
This is my properties file:
tinylog.writer = rollingfile
tinylog.writer.filename = MessageLogs.txt
tinylog.writer.backups = 1
tinylog.writer.label = timestamp
tinylog.writer.policies = daily, size: 1000KB
tinylog.writingthread = true
tinylog.writingthread.observe = null
tinylog.writingthread.priority = 2
tinylog.format = {date:yyyy-MM-dd HH:mm:ss:sss} {class}.{method}()\n{level}: {message}
Tasks:
I was getting error getMDCA not found in your StaticMDCBinder class.
and joy.
Still love your lib.
Cheers,
Vic
I like the idea of putting my log messages in a lambda, so that if a certain level is not configured to be output at all (not active), even the parts of the log message don't have to be looked for (or generated) in the calling thread in the first place. I think I have seen this in another logging framework (maybe Log4j).
Is this a possible improvement? And what would we have to consider about thread-safety and race conditions, especially with a separate Writer Thread?
NumberFormat
like formatting like {#.##} for placeholder arguments in log entries
All six code coverage reports can be uploaded successfully:
https://travis-ci.org/pmwmedia/tinylog/builds/157230235#L3777
But codecov.io fails to process the code coverage reports:
https://codecov.io/gh/pmwmedia/tinylog/commit/35b60112231696d48a112e82587f44b1fef4b902
well, sounds like a project from pre-maven ages
Hi,
it would be great if you could support a choice-syntax similar to {0,choice,0#Keinen|1#Einen|2#{0}}
from MessageFormat.format(...)
.
For the new tinylog-syntax it could be a little bit simpler, like {0#Keinen|1#Einen|2#{}}
๐
Best regards
Reimplementation of JDBC writer for tinylog 2.0:
I see log4j 1.
Is there are log4j 2 adapter?
The existing Checkstyle and FindBugs checks should be applied in the Travis CI script out of the box to all projects but the parent project.
I tested with felix 4.4.1 and the error.
Caused by: java.lang.NumberFormatException: For input string: "rc1"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at org.osgi.framework.Version.parseInt(Version.java:168)
does tinylog ready for a release version?
Tasks:
LogFactory
and Log
interfaces of Commons LoggingMore information about Commons Logging :
https://commons.apache.org/proper/commons-logging/guide.html
Example from SLF4J:
https://github.com/qos-ch/slf4j/tree/master/jcl-over-slf4j
Tasks:
Hi, as the subject already says I have a question about whether the jdbc connection is reestablished automatically after it gets disconnected?
I have experienced that I had to restart my server to get new log data from tinylog although the application has been in use by users in the meantime.
Best regards and thank you for your support
Hi,
This is NOT an issue, but just an advice taking for using tinylog in my android app.
So, I want to use this in my android app and wanted to write the application logs here. It will be common file created hourly. I want to keep it multithreaded.
tinylog.writer = sharedfile
tinylog.writer.filename = mylog.txt
tinylog.writer.append = true
tinylog.writer.backups = 100
tinylog.writer.label = timestamp
tinylog.writer.policies = hourly, size: 100KB
tinylog.writingthread = true
tinylog.writingthread.observe = null
tinylog.writingthread.priority = 1
any other suggestions are welcome.
Looking at the existing source, I don't think that's possible.
I'm wondering if tinylog can support custom levels such as DEBUG1, DEBUG2, DEBUG3, DEBUG4, DEBUG5?
Right now when I use tinylog, I mostly use this:
Configurator c = Configurator.currentConfig();
c.level(Level.DEBUG);
c.formatPattern("{date:HH:mm:ss} {level|min-size=8} {message}");
c.activate();
But it would be nice to be able to control how much debugging to print out.
I have a setup where I have two types of logging information. Something like system monitoring and something like session/user monitoring. And I want to log both but seperate the information into two log files.
Is this possible with tiynlog? I looked at RollingFileWriter but that seems to be useful in the case of multiple consecutive and not multiple parallel files.
Reimplementation of SLF4J binding for tinylog 2.0:
I have following dependencies in my pom.xml
.
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<!-- required for tomcat -->
<groupId>org.tinylog</groupId>
<artifactId>tinylog-jul</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-binding</artifactId>
<version>1.2</version>
</dependency>
When running test cases, everything works, but when I run the jsp inside tomcat8, I get following output:
java.lang.NoSuchMethodError: org.pmw.tinylog.Logger.output(ILorg/pmw/tinylog/Level;Ljava/lang/Throwable;Ljava/lang/Object;[Ljava/lang/Object;)V
org.pmw.tinylog.LogEntryForwarder.forward(Unknown Source)
org.slf4j.impl.TinylogBridge.log(Unknown Source)
Is it possible to detail the documentation with that regard?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.