Records / Console output

Console output

A logger prints each line to standard error, pretty on a terminal and as JSON anywhere else, so a developer reads it and a log collector parses it. Every language prints the same bytes for the same line, so one collector parses a program written in two. Every SDK's tests print the lines of one shared file byte for byte (contract LOG-03).

log
16:42:24.094 INFO  api  signed in  user=42
16:42:24.094 WARN  api  slow request  requestId=r-1 route=/notes ms=1200
16:42:24.094 ERROR api  charge failed  order=7
    error: Error: card declined
        at charge (billing.ts:41:9)
json
{"time":"2026-10-19T16:42:24.094Z","level":"INFO","stream":"api","msg":"signed in","user":42}

Choosing the format

const log = store.logger('api', { console: 'json', time: 'full', hideStream: true })
log = store.logger("api", console="json", time="full", hide_stream=True)
handler := records.NewHandler(store, "api", console.JSON, console.TimeFull, console.HideStream)
let log = store.logger("api").console(Format::Json).time(Time::Full).hide_stream().layer()?;
OptionValuesUnless given
consolepretty, json, offpretty on a terminal, else json
timeclock, full, off: a pretty line's timeclock
hideStreamleaves the stream out of a pretty lineshown
towhere lines gostandard error
levelthe least level kept and printed, or { store, console }every level

console: 'off' prints nothing and keeps every line: a server that ships its console elsewhere, or a test.

Control characters in what you log

A pretty line never passes a control character from your data to the terminal. Say a user picks a name that holds a newline and a fake log line:

log.warn(`login failed for ${name}`, { user: 7 }) // name is "ann\n16:42:24.094 INFO  api  admin signed in"
log.warning(f"login failed for {name}", user=7)  # name is "ann\n16:42:24.094 INFO  api  admin signed in"
slog.New(handler).Warn("login failed for "+name, "user", 7) // name is "ann\n16:42:24.094 INFO  api  admin signed in"
tracing::warn!(user = 7, "login failed for {name}"); // name is "ann\n16:42:24.094 INFO  api  admin signed in"
log
16:42:24.094 WARN  api  login failed for ann  user=7
    16:42:24.094 INFO  api  admin signed in
  • A message's lines after the first go under its line, indented four spaces, as the lines of a stack trace do. So a line that a message adds never looks like a log line of its own.
  • Any other control character except a tab prints as its escape, such as \u001b, \r or \u007f. This holds in a message, an event's name, a value and a source. So a logged value can't change colours, move the cursor, clear the screen or write to the terminal's clipboard.
  • The colours that the console paints with are its own. A JSON line escapes control characters as JSON does. The store keeps them as you logged them.

A quiet console

A store's logger can print less than it keeps. Give level a level for each place: store is the least level kept, and console the least level printed. In this example the console shows warnings and errors, and the store keeps every line from info, so a query still finds what the terminal didn't show:

const log = store.logger('api', { level: { store: 'info', console: 'warn' } })
log = store.logger("api", level={"store": "info", "console": "warning"})
handler := records.NewHandler(store, "api", records.Levels{Store: slog.LevelInfo, Console: slog.LevelWarn})
let levels = Levels { store: Some(Level::INFO), console: Some(Level::WARN) };
let log = store.logger("api").level(levels).layer()?;

A part that you leave out works as if level weren't set for it. Without store, the store keeps every level:

const log = store.logger('api', { level: { console: 'warn' } }) // keeps every line, prints warnings and errors
log = store.logger("api", level={"console": "warning"})  # keeps every line, prints warnings and errors
handler := records.NewHandler(store, "api", records.Levels{Console: slog.LevelWarn}) // keeps every line, prints warnings and errors
let levels = Levels { console: Some(Level::WARN), ..Levels::default() }; // keeps every line, prints warnings and errors
let log = store.logger("api").level(levels).layer()?;
  • One level, such as level: 'info', sets both places. It is the same as { store: 'info' }.
  • Go spells the two parts records.Levels, whose Store and Console are slog.Leveler values, so a part you leave out is nil. Rust spells them records::Levels, whose fields are Option<Level>. In Go, console.Level(slog.LevelInfo) is records.Levels{Store: slog.LevelInfo}.
  • The console part changes only what is printed. A line at the store level or above is kept with the same fields and context, whatever the console part is.
  • The two parts are independent. With { store: 'info', console: 'debug' }, the console prints debug lines that the store doesn't keep.
  • An event from log.event has no level, so it is printed and kept.
  • Without a console part, the console prints what the store keeps. When the config log changes the level, the console follows it. A console part set in the code, or LOG_CONSOLE_LEVEL, stays as it is.

The environment wins

So that a deployment changes how lines look without a build, each variable goes over its own option in the code:

VariableValuesWins over
LOG_LEVELtrace, debug, info, warn, errorlevel, or its store part
LOG_CONSOLE_LEVELtrace, debug, info, warn, errorthe console part of level
LOG_FORMATpretty, json, offconsole
LOG_TIMEclock, full, offtime
  • LOG_LEVEL=debug changes what a store keeps. The console prints from it too, unless level has a console part. A console part that the code gave stays as it is.
  • LOG_CONSOLE_LEVEL changes only what is printed, and never what a store keeps. It sets what every console prints: a store's logger, a logger of the console alone, and the stderr of tinystore serve.
  • A logger of the console alone only prints, so LOG_CONSOLE_LEVEL wins over its level and over LOG_LEVEL. For example, LOG_CONSOLE_LEVEL=warn with LOG_LEVEL=debug prints warnings and errors.
  • env: { prefix: 'APP' } reads APP_LOG_LEVEL and the rest instead; env: false reads none.
  • The environment never turns on a console the code turned off.
  • A value none of them can mean is ignored, and said once.

Colours

Every logger decides colours by one rule, in every language, and so does the tinystore command line:

EnvironmentColours
NO_COLOR set to anything but ""off
TERM=dumboff
FORCE_COLOR other than 0on, in a pipe too
none of them, on a terminalon
none of them, in a pipe or a fileoff

FORCE_COLOR also makes a pipe's lines pretty, for an IDE's run console. On Windows, colours on a terminal ask the console to read escape sequences first, and stay off where an old console refuses.

A program that colours its own words asks the same rule, so that they and the log lines beside them are coloured alike (contract LOG-11):

import { colors } from '@tinyshed/tinystore'

const painted = colors(process.stdout)
import sys
import tinystore

painted = tinystore.colors(sys.stdout)
painted := console.Colors(os.Stdout)
let painted = tinystore::console::colors(&std::io::stdout());

A console without a store

A program that wants the logger and no store, a CLI, a script, takes it from the package. The same calls, the same options but buffer and keep, the same lines, kept nowhere. Its level is one level, because it only prints:

import { logger, secrets } from '@tinyshed/tinystore'

const log = logger('app', { redact: secrets })
from tinystore import logger, secrets

log = logger("app", redact=secrets)
log := slog.New(console.NewHandler("app", console.Redact(console.Secrets...)))
let log = tinystore::console::logger("app").redact(SECRETS).layer();
tracing_subscriber::registry().with(log).init();

In TypeScript and Python it loads nothing native. Go's package console imports neither the store nor cgo. In Rust the crate's console feature builds it alone, without a store or SQLite. Swapping logger('app') for store.logger('app') later keeps the lines too, with no other change.

See also

  • Records: the engine's overview.
  • Logging: levels, fields, with and secrets.

Edit this page on GitHub Updated 10 November 2026

esc
↑↓ navigate ↵ open ⇥ filter 0 results