Skip to content

v1.2

Choose a tag to compare

@andriishin andriishin released this 11 Nov 01:09
· 91 commits to main since this release

Nanolog 1.2 makes the library easier to use and to debug in agent-driven development, where a coding agent edits, runs and reads the output in a short loop. The public API only grows, and every change below is covered by tests under a 100% pitest mutation threshold.

New

  • SLF4J argument order. A trailing Throwable that no {} placeholder consumes becomes the exception of the entry, so LOG.error("Failed", e) and LOG.error("Failed {}", id, e) log the stack trace. Before, the exception was silently dropped as an unused argument.
  • Call site. LogEntry.getCaller() returns the frame of the logging call, and ConsoleLogger.setShowLocation(true) prints it as [PaymentService.charge(PaymentService.java:87)], a link in IDEs and terminals. It comes from the stack walk that already detects the source class, so it costs nothing extra.
  • Levels and options without code. ConsoleLogger reads nanolog.level, per-package or per-class rules (nanolog.level.com.acme.payments=DEBUG, nanolog.levels) and the nanolog.console.* display options. A package rule beats the global level, even one set in code.
  • Environment variables. Every setting, nanolog.logger and nanolog.config included, can be set as an environment variable (NANOLOG_LEVEL, NANOLOG_LOGGER). Precedence: -D, environment, nanolog.properties.
  • JsonLogger. One JSON object per line with ts, level, logger, thread, message, template, args, caller and exception, selectable with -Dnanolog.logger=com.nanolaba.logging.JsonLogger. LogEntry.getTimestamp() and LogEntry.getThreadName() record when and where an entry was created.
  • MemoryLogger and CompositeLogger. try (MemoryLogger log = MemoryLogger.install()) { ... } captures entries in a test and puts the previous logger back afterwards; CompositeLogger sends entries to several loggers.
  • nanolog.strict=true. Reports calls whose {} placeholders and arguments do not match, once per template and with the call site. Meant for test runs.

Fixes

  • Slf4jLogger: Logback, Log4j 2 and other location-aware backends report the code that called LOG in %file:%line and %l, instead of Slf4jLogger.log.
  • ConsoleLogger: a throwable whose toString() throws no longer escapes from the logging call; it is printed as [FAILED printStackTrace()].

Documentation and build

  • Javadoc for the whole public API; the build fails on a missing comment.
  • llms.txt and the agent skill skills/nanolog/SKILL.md give coding agents the rules of the library. Both are generated together with the README and checked for drift in CI.
  • README: a new section on agent-driven development, in English and Russian.

Installation

<dependency>
    <groupId>com.nanolaba</groupId>
    <artifactId>nanolog</artifactId>
    <version>1.2</version>
</dependency>
implementation("com.nanolaba:nanolog:1.2")

Requires Java 8 or later. slf4j-api is needed only when Slf4jLogger is used.

Full changelog: v1.1...v1.2