Repository navigation
Nanolog 1.4: fewer tokens for AI coding agents, LOG.dbg and wide events #88
andriishin
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
When a coding agent runs your tests, Nanolog 1.4 keeps the console short: a failing
mvn -q testprinted 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:
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 (Agent mode: detect coding agents (AI_AGENT, CLAUDECODE, ...) and keep the console short #61).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 (Report unknown nanolog.* settings and unprefixed keys, with a "did you mean" #43).nanolog.diagnostics=onceis the default;allrestores one line per occurrence,offsilences them (Control [NANOLOG] diagnostics: once per JVM, nanolog.diagnostics=once|all|off, name the source #44).nanolog.propertieson the classpath when one of them is in a jar (Protect the application's logger from libraries: report LOG.init replacements, nanolog.logger.lock #47, Warn when several nanolog.properties files from jars are on the classpath #48).MemoryLogger.assertNoDiagnostics()saysNanolog reportedinstead ofstrict mode reported(Temporary by design: list leftover LOG.dbg calls, switch them off, fail tests on them #60).ConsoleLoggerline that follows a line break no longer starts with a space (Show the source line of the call under each entry in development (nanolog.console.showSourceLine) #70).New
LOG.dbg, one line per entry, with short stack traces and repeats collapsed into one line with a count (Agent mode: detect coding agents (AI_AGENT, CLAUDECODE, ...) and keep the console short #61, Agent mode: collapse repeated console entries into one line with a count (nanolog.console.repeats) #73).nanolog.summary, Run summary: a digest at the end of the run that survives agent output truncation #62).target/nanolog/latest.logholds every entry of the last run,latest.errors.logits warnings and errors, with the last 10 runs kept (nanolog.run, Per-run log file for agents: latest.log plus history, path always printed #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 (LOG.dbg(...): print the expression, its value and the call site (Java's dbg! / icecream) #58, Safe dump of objects without toString() for LOG.dbg and {} arguments (no more SomeType@2f92e0f4) #59, Temporary by design: list leftover LOG.dbg calls, switch them off, fail tests on them #60).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 (Units of work: one canonical line per request or job (wide events) with tail sampling #65).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 (Context for every entry of a scope: LOG.context(key, value) and LOG.wrap(task) #26, Structured fields: LOG.kv(key, value) arguments #27, Context providers: trace IDs from OpenTelemetry and others without an MDC #54).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 (JUnit 5 extension: print a test's log only when the test fails #64, MemoryLogger.capture(): thread-scoped capture for parallel tests #51).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 (Masking secrets: LOG.secret(...) and key-based redaction #38, LOG.content(...): log payloads such as prompts as length and hash unless shown on purpose #67).nanolog.buffer=DEBUGholdsDEBUGentries back and writes them only before the nextERROR(Breadcrumbs: buffer DEBUG entries and print them only before an ERROR (nanolog.buffer) #66).LOG.tag("audit").warn(...)with levels per tag,nanolog.tags=audit=WARN(Tags: LOG.tag("audit") with levels per tag #34).LOG.time(...)andLOG.timed(...)time a block;LOG.catching(...)logs and carries on;LOG.installUncaughtExceptionHandler()logs the exceptions that kill threads (LOG.time(...): log the duration of a block #30, LOG.catching(...) and an uncaught exception handler #31).FileLoggerappends to a file, with size rollover and buffered flushing (FileLogger: minimal file output with append, size rollover and flush #55).java.util.loggingboth ways.JulLoggerwrites to JUL, andNanologHandlerturns JUL andSystem.Loggerrecords into Nanolog entries (Bridges: java.util.logging and System.Logger into Nanolog, and a JUL backend #36).System.outandSystem.errintoLOGwithLOG.captureSystemStreams()(Route System.out and System.err into LOG #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) (ConsoleLogger: colored levels with terminal detection (nanolog.console.color) #28, ConsoleLogger: keep one entry on one line (nanolog.console.multiline) #33, Show the source line of the call under each entry in development (nanolog.console.showSourceLine) #70, ConsoleLogger: abbreviate the source class name (nanolog.console.sourceLength) #29, ConsoleLogger: time zone for timestamps (nanolog.console.timeZone) #53).LOG.lazy(...)computes one argument only when the level is enabled (LOG.lazy(...): lazy individual arguments #32).nanolog.caller.skip,LOG.skipCaller(...)(Skip user-defined wrapper classes in caller detection (nanolog.caller.skip) #25).jlinkimage ofjava.basealone, and carries the metadata of a GraalVM native image and rules for R8 and ProGuard (A real module descriptor (module-info) so the jar works with jlink #45, Ship GraalVM native-image metadata and R8/ProGuard rules in the jar #46).Documentation and build
src/tokensholds the four measured runs and the script that repeats them (Fewer tokens for AI coding agents: measure what agent mode saves, in tokens, and lead the docs with it #82)./plugin marketplace add nanolaba/nanolog), andcontext7.jsonmakes Context7 find this Nanolog rather than the C++ NanoLog (Agent docs: shorter skill installation, a Claude Code plugin, catalog-ready front matter that names the token saving, a rule for reporting problems #79, Context7: context7.json so coding agents find this Nanolog, not the C++ NanoLog #78).jlinkimage and GraalVM native images; CodeQL analyses every push; the project has the OpenSSF Best Practices passing badge (CI: test Slf4jLogger against SLF4J 1.7 #49, CI: compile Kotlin callers to catch overload ambiguity #50, A real module descriptor (module-info) so the jar works with jlink #45, Ship GraalVM native-image metadata and R8/ProGuard rules in the jar #46, OpenSSF Scorecard: fix the cheap checks, then publish the score #81).Installation
implementation("com.nanolaba:nanolog:1.4")Requires Java 8 or later.
slf4j-apiis needed only whenSlf4jLoggeris used.Full changelog: v1.3...v1.4
Feedback
This discussion was created from the release Nanolog 1.4: fewer tokens for AI coding agents, LOG.dbg and wide events.
All reactions