Repository navigation
Nanolog 1.4: fewer tokens for AI coding agents, LOG.dbg and wide events
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,CLAUDECODEor another agent variable is set, the default logger prints onlyWARN,ERRORandLOG.dbgto the console and writes everything totarget/nanolog/latest.log. A test that reads what the default logger prints to the console sees less there: capture the entries withMemoryLogger, or setNANOLOG_AGENT=offfor the test JVM.nanolog.agent=offturns agent mode off everywhere (#61). - Unknown settings are reported. A mistyped
nanolog.*system property,NANOLOG_*variable or key ofnanolog.propertiesprints 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=onceis the default;allrestores one line per occurrence,offsilences them (#44). - Libraries that replace your logger are reported, with both call sites; so are several
nanolog.propertieson the classpath when one of them is in a jar (#47, #48). MemoryLogger.assertNoDiagnostics()saysNanolog reportedinstead ofstrict mode reported(#60).- A part of a
ConsoleLoggerline 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.logholds every entry of the last run,latest.errors.logits 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, likedbg!in Rust. Objects without atoString()of their own are printed field by field. When the JVM exits, the calls that printed are listed, andNanologChecks.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.
NanologExtensionprints 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 unlessnanolog.contentshows it (#38, #67). - Breadcrumbs.
nanolog.buffer=DEBUGholdsDEBUGentries back and writes them only before the nextERROR(#66). - Tags.
LOG.tag("audit").warn(...)with levels per tag,nanolog.tags=audit=WARN(#34). - Timing and exceptions.
LOG.time(...)andLOG.timed(...)time a block;LOG.catching(...)logs and carries on;LOG.installUncaughtExceptionHandler()logs the exceptions that kill threads (#30, #31). FileLoggerappends to a file, with size rollover and buffered flushing (#55).java.util.loggingboth ways.JulLoggerwrites to JUL, andNanologHandlerturns JUL andSystem.Loggerrecords into Nanolog entries (#36).System.outandSystem.errintoLOGwithLOG.captureSystemStreams()(#52).ConsoleLoggeroptions: 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
jlinkimage ofjava.basealone, 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/tokensholds 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), andcontext7.jsonmakes Context7 find this Nanolog rather than the C++ NanoLog (#79, #78). - CI also tests SLF4J 1.7, compiles the calls from Kotlin, builds a
jlinkimage 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
- How many tokens did agent mode save on your project? Tell us in Feedback on 1.4.
- Questions: Q&A.
- Bugs and ideas: issue forms.