coteafs-logger is a Java wrapper library build on top of log4j2. This library was created to simplify the logging as there is no need to add two dependency of log4j2. Also, the logger can be configured using different config formats ( Yaml, JSON, XML and properties)
By default, if you don't provide the logger config, then it will not log anything, but, if the logger file is provided, it will log as per the config setting. To know more about the behavior of config file, check out it's repository here
This library provides a utility class known as Loggy
which simplifies the logging. Check the sample code below:
final Loggy log = Loggy.init ();
log.enter ("Code start");
log.i ("Testing info...");
log.w ("Testing warn...");
log.e ("Testing error...");
log.d ("Testing debug...");
log.c (ex);
log.t ("Testing trace...");
log.f ("Testing fatal...");
log.th (new Exception("Custom exception"));
log.exit ("Code completed.");
Will output the logs as:
[18:20:28.172] [TRACE] - Enter Entered method (TestLogging:126)
[18:20:28.175] [INFO ] - Testing info... (TestLogging:207)
[18:20:28.186] [WARN ] - Testing warn... (TestLogging:290)
[18:20:28.188] [ERROR] - Catching (TestLogging:45) File Not found
[18:20:28.188] [ERROR] - Testing error... (TestLogging:115)
[18:20:28.189] [DEBUG] - Testing debug... (TestLogging:80)
[18:20:28.190] [TRACE] - Testing trace... (TestLogging:242)
[18:20:28.191] [FATAL] - Testing fatal... (TestLogging:172)
[18:20:28.192] [TRACE] - Exit: Exit method (TestLogging:137)
[18:20:28.193] [ERROR] - Throwing (TestLogging:255) Custom exception
The config file should be placed in src/test/resources
and file name must be logger-config
. Following is the sample
logger config which will create 1 rolling log file and also output the logs to console:
new-log-main.log
The above generated files will be archived as per the configuration:
- Every next day.
- Log file size exceeds 5 mb.
- On Every Automation Run.
logger-config.yml
status: WARN
log_dir: /logs
loggers:
- name: console-log
type: CONSOLE
message_pattern: "[%d{HH:mm:ss.SSS}] [%-5level] - %msg (%logger{1}:%L) %throwable{short.message}%n"
level: DEBUG
- name: test-log-appender
type: FILE
file_name: new-log-main
path_pattern: my-log-main-%d{yyyy-MM-dd}.log
message_pattern: "[%d{HH:mm:ss.SSS}] [%-5level] - %msg (%logger{1}:%L) %throwable{short.message}%n"
level: INFO
archive:
after_days: 1
after_size: 5
on_every_run: true
You can use the following dependency into your pom.xml
to use this library.
<dependency>
<groupId>com.github.wasiqb.coteafs</groupId>
<artifactId>logger</artifactId>
<version>2.5.0</version>
</dependency>
- Directly chat with me on my site and I'll revert to you as soon as possible.
- Discuss your queries by writing to me @ wasbhamla2005@gmail.com
- If you find any issue which is bottleneck for you, search the issue tracker to see if it is already raised.
- If not raised, then you can create a new issue with required details as mentioned in the issue template.
- Spread the word with your network.
- Star the project to make the project popular.
- Stay updated with the project progress by Watching it.
- Contribute to fix open issues, documentations or add new features. To know more, see our contributing page.
- I would be delighted if you can Sponsor this project and provide your support to open source development by clicking on the Sponsor button on the top of this repository.