Skip to content

Nanolog 1.4: fewer tokens for AI coding agents, LOG.dbg and wide events

Choose a tag to compare

@andriishin andriishin released this 19 Nov 08:29
· 38 commits to main since this release

When a coding agent runs your tests, Nanolog 1.4 keeps the console short: a failing mvn -q test printed 1,022 tokens instead of 13,577, a green one 142 instead of 16,550 (o200k_base; runs and script in Fewer tokens).

The public API only grows. Every change is covered by tests under a 100% pitest mutation threshold, run on JDK 8, 11, 17 and 21 and in native images built by GraalVM 21 and 25.

Changed

Things that behave differently from 1.3:

  • Under a coding agent the console is shorter. When AI_AGENT, CLAUDECODE or another agent variable is set, the default logger prints only WARN, ERROR and LOG.dbg to the console and writes everything to target/nanolog/latest.log. A test that reads what the default logger prints to the console sees less there: capture the entries with MemoryLogger, or set NANOLOG_AGENT=off for the test JVM. nanolog.agent=off turns agent mode off everywhere (#61).
  • Unknown settings are reported. A mistyped nanolog.* system property, NANOLOG_* variable or key of nanolog.properties prints one [NANOLOG] line with the key it was probably meant to be, instead of being ignored (#43).
  • Each diagnostic is printed once per JVM. nanolog.diagnostics=once is the default; all restores one line per occurrence, off silences them (#44).
  • Libraries that replace your logger are reported, with both call sites; so are several nanolog.properties on the classpath when one of them is in a jar (#47, #48).
  • MemoryLogger.assertNoDiagnostics() says Nanolog reported instead of strict mode reported (#60).
  • A part of a ConsoleLogger line that follows a line break no longer starts with a space (#70).
  • Caller detection on Java 8 is faster: about 5 µs instead of 20 near the top of the stack, 19 µs instead of 270 at 500 frames (#71).

New

  • Agent mode. When the environment names a coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI and others), the console keeps warnings, errors and LOG.dbg, one line per entry, with short stack traces and repeats collapsed into one line with a count (#61, #73).
  • Run summary. The run ends with the counts by level, each kind of warning and error with its call site, and the trace of the first error, printed last so that it survives when an agent keeps only the tail of the output (nanolog.summary, #62).
  • Run log. target/nanolog/latest.log holds every entry of the last run, latest.errors.log its warnings and errors, with the last 10 runs kept (nanolog.run, #63).
  • LOG.dbg(expression) prints the expression as written, its value and type, and the call site, and returns the value, like dbg! in Rust. Objects without a toString() of their own are printed field by field. When the JVM exits, the calls that printed are listed, and NanologChecks.assertNoDbgCalls("src/main/java") fails a test while one is left (#58, #59, #60).
  • Wide events. LOG.unit("checkout") writes one canonical log line per request or job when it ends: checkout ok 182 ms orderId=A-17 warn=1, with a stable error key for a failed unit and tail sampling of fast successful ones (#65).
  • Fields and context. LOG.kv("orderId", id) names an argument; LOG.context("requestId", id) tags every entry of a block, LOG.wrap(task) carries it to another thread, and context providers add trace IDs such as those of OpenTelemetry (#26, #27, #54).
  • Tests. NanologExtension prints the log of a test only when the test fails; MemoryLogger.capture() captures the entries of one thread, so parallel tests assert on their own log (#64, #51).
  • Safer payloads. LOG.secret(token) is written as *** by every logger, and keys named like secrets are masked; LOG.content(prompt) writes a prompt or a body as its length and hash unless nanolog.content shows it (#38, #67).
  • Breadcrumbs. nanolog.buffer=DEBUG holds DEBUG entries back and writes them only before the next ERROR (#66).
  • Tags. LOG.tag("audit").warn(...) with levels per tag, nanolog.tags=audit=WARN (#34).
  • Timing and exceptions. LOG.time(...) and LOG.timed(...) time a block; LOG.catching(...) logs and carries on; LOG.installUncaughtExceptionHandler() logs the exceptions that kill threads (#30, #31).
  • FileLogger appends to a file, with size rollover and buffered flushing (#55).
  • java.util.logging both ways. JulLogger writes to JUL, and NanologHandler turns JUL and System.Logger records into Nanolog entries (#36).
  • System.out and System.err into LOG with LOG.captureSystemStreams() (#52).
  • ConsoleLogger options: coloured levels on a terminal, entries kept on one line (nanolog.console.multiline), the source line under each entry (showSourceLine), abbreviated class names (sourceLength), a time zone for timestamps (timeZone) (#28, #33, #70, #29, #53).
  • LOG.lazy(...) computes one argument only when the level is enabled (#32).
  • Logging helpers are skipped by caller detection: nanolog.caller.skip, LOG.skipCaller(...) (#25).
  • Strict mode reports an exception message logged next to the exception and templates built from data (#23).
  • Platforms. The jar is a real module on Java 9+, works in a jlink image of java.base alone, and carries the metadata of a GraalVM native image and rules for R8 and ProGuard (#45, #46).

Documentation and build

  • The README leads with what agent mode saves; src/tokens holds the four measured runs and the script that repeats them (#82).
  • Related projects compares Nanolog with tinylog, jcabi-log, minlog, Timber, SLF4J with Logback, Log4j 2, java.util.logging, Flogger and JBoss Logging (#57, #72); Logging LLM calls shows a LangChain4j listener and a Spring AI advisor (#68).
  • Coding agents: the agent skill installs in one command or as a Claude Code plugin (/plugin marketplace add nanolaba/nanolog), and context7.json makes Context7 find this Nanolog rather than the C++ NanoLog (#79, #78).
  • CI also tests SLF4J 1.7, compiles the calls from Kotlin, builds a jlink image and GraalVM native images; CodeQL analyses every push; the project has the OpenSSF Best Practices passing badge (#49, #50, #45, #46, #81).
  • Issue forms, Discussions, and SUPPORT, CONTRIBUTING and SECURITY in English and Russian, with private vulnerability reporting (#74, #75).

Installation

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

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

Full changelog: v1.3...v1.4

Feedback