- Level hierarchy, including custom levels
- Console output separation between STDERR and STDOUT depending on severity
- File output
- Rolling appender with file compression
- Basic inheritance
- ANSI color printing
- Logging per site as an extension
The configuration file follows INI format:
[symbolic-name]
name = org.some.package
level = ERROR
max_length = 10000
date_zone = UTC+6
file_out = main.package.log
file_enabled = true
file_rolling_size=1048576
file_rolling_enabled=false
[mongodb]
name = org.nosql.impl
inherit = main.packageEach logger declaration has its own symbolic name enclosed in square brackets.
Every key is followed by = followed by value. Two key-value pairs are not allowed on the same line.
Values are not enclosed in quotation marks. Comments are allowed but must be preceded with a #.
The order of declarations does not matter. Only single-level inheritance is allowed, and it is performed in no particular order.
The config file no4j.ini must be in the root directory of the project or in src/main/resources.
To prevent collisions, the configuration does not inherit properties such as the file output path.
| Key | Meaning | Default value | Type |
|---|---|---|---|
name |
logger name | String | |
level |
logging level | OFF | Level |
max_length |
cap log message length | Integer.MAX_Value - 32 | int |
max_stack_trace_depth |
max stack trace depth in log message | 64 | int |
level_padding |
desired level length in log message | 14 | int |
method_padding |
desired method length in log message | 30 | int |
include_method |
include method in log message | true | boolean |
include_line_number |
include line number in log message | true | boolean |
include_package |
include package prefix in log message | false | boolean |
stderr_level |
STDERR logging level | ERROR | Level |
file_out |
log file path | null | Path |
file_rolling_size |
file size to reach before rolling | 4194304 | long |
file_enabled |
write logs to file | false | boolean |
file_rolling_enabled |
roll log files | false | boolean |
console_enabled |
write to console | true | boolean |
date_pattern |
date format pattern | yyyy-MM-dd HH:mm:ss | DateTimeFormatter |
date_zone |
UTC/GMT/UT zone | UTC+0 | ZoneId |
inherit |
symbolic logger name to inherit from | N/A | N/A |
import no4j.core.No4JConfiguration;
class Test {
public static void main(String[] args) {
try {
No4JConfiguration.configure();
} catch (IOException e) {
/* Handle exception */
}
}
}import no4j.core.FileAppender;
import no4j.core.Level;
import no4j.core.Logger;
import no4j.extensions.LoggerBuilder;
class Test {
public static void main(String[] args) {
Logger log = LoggerBuilder.error("main.package")
.file("main.package.log")
.rollAtMegabytes(2)
.maxMessageLength(5000)
.getLogger();
// USAGE
log.debug("DEBUG");
log.info("INFO");
log.warn("WARNING");
log.fatal("FATAL");
log.unreachable("UNREACHABLE");
log.exception(new RuntimeException("Exception thrown!"));
}
}Generally supported within all Linux terminals
Windows cmd or powershell generally do not support ANSI.
It is possible to enable ANSI in Windows 10 and later by creating a DWORD(32-bit) VirtualTerminalLevel with value 1
at HKEY_CURRENT_USER\Console in registry
Alternative terminals for Windows that support ANSI
- Git Bash
- Cmder
- IntelliJ console
<dependency>
<groupId>com.github.FriskIsGit</groupId>
<artifactId>no4j-logger</artifactId>
<version>main-SNAPSHOT</version>
</dependency>By default, all POMs implicitly inherit from a super-POM: https://maven.apache.org/ref/3.0.4/maven-model-builder/super-pom.html When an external repository is specified the default repository needs to be respecified:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://maven.org/maven2</url>
</repository>
</repositories>Include at root level in build.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}Add the dependency:
dependencies {
implementation 'com.github.FriskIsGit:no4j-logger:main-SNAPSHOT'
}
