Skip to content

[log]

log

What a program's own records look like, and who is told when one of its requests fails.

The block gathers the shape of the record and the rungs the runtime climbs when something goes wrong. Two of its keys are the ordinary sort a program changes for itself: the rendering, JSON unless somebody asks for text, and the level, below which a record is not written at all. A job that wants its own run traced turns its level down and gets the detail for that one request, while the requests beside it keep what the deployment wrote.

The rest is the operator's, and each of those keys says so on its own page: the script run when a request fails, the memory and time held back for it, and the destination the floor writes to. Where the record of a failure goes is not the failing program's decision.

The example prints what this checkout starts with, turns one movable key down, and asks for the ones that will not move.

A request may change these keys in this block with Core\Config::set: format, level. Only nvs.toml sets the others.

A change in the file takes effect a few seconds after you save it. The server does not restart.

What a program may say about its own records

<?nvs
// `[log]` sets the format of log records and what happens when a request fails.
// A program may change `log.format` and `log.level`. Only the person who runs the
// server may change the other keys.
// This file sets neither key, so `get` returns the defaults for production mode.
// This prints `json` and `Info`.
echo 'rendering: ', Core\Config::get('log.format') ?? '(no value)', "\n";
echo 'level: ', Core\Config::get('log.level') ?? '(no value)', "\n";
// This sets the log level to `Debug` for this request only. Other requests
// still use the configured level.
echo 'trace this run: ', Core\Config::set('log.level', 'Debug') ? 'accepted' : 'not allowed', "\n";
echo 'level now: ', Core\Config::get('log.level') ?? '(no value)', "\n";
// A program cannot change where records go or which script runs when it fails. A name written
// in the call does not compile. These names are in variables, so both calls run and return `false`.
string $target = 'log.target';
string $handler = 'log.handler';
echo 'send them elsewhere: ', Core\Config::set($target, 'file:/tmp/mine.log') ? 'accepted' : 'not allowed', "\n";
echo 'name my own handler: ', Core\Config::set($handler, 'scripts/mine.nvs') ? 'accepted' : 'not allowed', "\n";
// `Core\Config::restore` sets the level back to the configured value.
// No level is configured here, so the result is the default, `Info`.
Core\Config::restore('log.level');
echo 'level after restore: ', Core\Config::get('log.level') ?? '(no value)', "\n";
Output
rendering: json
level: Info
trace this run: accepted
level now: Debug
send them elsewhere: not allowed
name my own handler: not allowed
level after restore: Info

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

log.handler

The script a deployment runs when a request fails.

Novis reports a failure in tiers. A program may arrange its own last words, and where they worked that is the end of it. This key names what happens when they did not: an ordinary Novis script, run as its own isolate with the failure's report handed to it, for any failure at all — a program that registered no handler, one whose handler failed in turn, an internal error, even a script that never compiled.

Because it runs when the request is already out of room, it is not funded by that request. It gets a small allotment of its own, sized once per worker, and the two keys beside it say how large.

Naming it is the operator's alone: a program able to choose who reports its failure could choose somebody who reports nothing.

The example prints what is on duty in this checkout and shows both halves of that split.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# The error handler gets 16M of memory and 5 seconds to write its report.
[log]
handler_reserve_memory = "16M"
handler_reserve_time = "5s"

Who is run when a request fails

<?nvs
// `[log] handler` names a script that runs when a request fails. It runs when the
// program has no handler of its own, or when that handler could not run.
echo 'the handler on duty: ', Core\Config::get('log.handler') ?? '(none written — the floor writes the record itself)', "\n";
echo 'memory held back: ', Core\Config::get('log.handler_reserve_memory') ?? '(no value)', "\n";
echo 'time held back: ', Core\Config::get('log.handler_reserve_time') ?? '(no value)', "\n";
// A program registers its own handler with `Core\Fatal::onLimit`. The function
// you give it runs inside the request that failed.
Core\Fatal::onLimit(fn(): void => {
echo "the program's own handler ran\n";
});
// `Core\Config::set('log.handler', ...)` does not compile,
// because a program may not change `log.handler`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.
string $handler = 'log.handler';
echo 'point it at my script: ', Core\Config::set($handler, 'scripts/mine.nvs') ? 'accepted' : 'not allowed', "\n";
echo 'or take it off: ', Core\Config::set($handler, '') ? 'accepted' : 'not allowed', "\n";
// The two reserve keys set the memory and time that script gets. A program
// cannot change them either.
string $reserveMemory = 'log.handler_reserve_memory';
string $reserveTime = 'log.handler_reserve_time';
echo 'widen its memory: ', Core\Config::set($reserveMemory, '1G') ? 'accepted' : 'not allowed', "\n";
echo 'narrow its time: ', Core\Config::set($reserveTime, '1ms') ? 'accepted' : 'not allowed', "\n";
Output
the handler on duty: (none written — the floor writes the record itself)
memory held back: 16M
time held back: 5s
point it at my script: not allowed
or take it off: not allowed
widen its memory: not allowed
narrow its time: not allowed

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

log.handler_reserve_memory

The memory the script that reports a failure is allowed to use.

A failing request has nothing to lend — being out of room is often what went wrong — so the script named beside this key does not spend its budget. It gets an allotment of its own, sized once per worker at startup, and this is how large.

Sixteen megabytes where nobody writes otherwise, far more than the slice [limits] keeps for a handler the program already had loaded: this one compiles and runs a whole script before it can say anything.

Sizing it belongs to whoever runs the deployment, for the reason naming the script does: a program able to shrink the room its own report is written in could make that report fail too, and a failure nobody hears about is what the whole ladder exists to prevent.

The example prints both halves of the allotment beside the request-side slice they are confused with.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# When a request stops on a limit, 1M of its memory is kept back for the report.
[limits]
fatal_reserve_memory = "1M"
# The error handler gets 16M of memory and 5 seconds to write its report.
[log]
handler_reserve_memory = "16M"
handler_reserve_time = "5s"

The room the report is written in

<?nvs
// `log.handler_reserve_memory` is the memory for the script that reports a failure.
// It does not come from the request that failed. The server sets it aside once,
// when it starts.
echo 'memory for the report: ', Core\Config::get('log.handler_reserve_memory') ?? '(nothing written)', "\n";
echo 'time for it: ', Core\Config::get('log.handler_reserve_time') ?? '(nothing written)', "\n";
echo 'the script it runs: ', Core\Config::get('log.handler') ?? '(none — the floor writes the record itself)', "\n";
// `limits.fatal_reserve_memory` is a different reserve. It is part of the request's
// memory. It is the extra memory that the program's own handler function gets.
echo 'the request-side slice: ', Core\Config::get('limits.fatal_reserve_memory') ?? '(nothing written)', "\n";
// A program cannot change this reserve. The compiler checks a setting name written as text,
// so `Core\Config::set('log.handler_reserve_memory', ...)` does not compile. Here the name is in a variable, so each call runs and returns `false`.
string $name = 'log.handler_reserve_memory';
echo 'widen it: ', Core\Config::set($name, '1G') ? 'accepted' : 'not allowed', "\n";
echo 'narrow it: ', Core\Config::set($name, '64K') ? 'accepted' : 'not allowed', "\n";
echo 'remove it: ', Core\Config::set($name, 'false') ? 'accepted' : 'not allowed', "\n";
// A program may still lower its own `limits.memory`. This reserve is not part
// of it.
echo 'bound my own heap: ', Core\Config::set('limits.memory', '64M') ? 'accepted' : 'not allowed', "\n";
Output
memory for the report: 16M
time for it: 5s
the script it runs: (none — the floor writes the record itself)
the request-side slice: 1M
widen it: not allowed
narrow it: not allowed
remove it: not allowed
bound my own heap: accepted

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

log.handler_reserve_time

The time the script that reports a failure is allowed to take.

The other half of the same allotment, and it is a ceiling on a report rather than a budget for work. What makes a report slow is almost never the formatting — it is the destination, a log file on a busy disk or a socket that is not answering — so the number covers a slow write rather than a computation.

Five seconds where nobody writes otherwise, a hundred times the slice [limits] keeps for a handler running inside the request, because this one compiles and starts a script first.

It belongs to whoever runs the deployment, like the memory beside it: a program that could cut the time its own report may take could cut it to nothing, and a report that never finishes is a failure nobody hears about.

The example prints it beside the other three numbers it is easy to mistake it for.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# When a request stops on a limit, 1M and 50 milliseconds are kept back for the report.
[limits]
fatal_reserve_memory = "1M"
fatal_reserve_time = "50ms"
# The error handler gets 16M of memory and 5 seconds to write its report.
[log]
handler_reserve_memory = "16M"
handler_reserve_time = "5s"

How long a report may take

<?nvs
// `log.handler_reserve_time` is how long the script that reports a failure may
// run. A report is usually slow because of where it writes, not what it writes.
echo 'time for the report: ', Core\Config::get('log.handler_reserve_time') ?? '(nothing written)', "\n";
echo 'memory beside it: ', Core\Config::get('log.handler_reserve_memory') ?? '(nothing written)', "\n";
// `limits.fatal_reserve_time` and `limits.fatal_reserve_memory` are part of the request's own limits.
// They are the extra time and memory that the program's own handler function gets.
echo 'the request-side time: ', Core\Config::get('limits.fatal_reserve_time') ?? '(nothing written)', "\n";
echo 'the request-side heap: ', Core\Config::get('limits.fatal_reserve_memory') ?? '(nothing written)', "\n";
// A program cannot change this time. A report that is stopped early never arrives.
// The compiler checks a setting name written as text, so `Core\Config::set('log.handler_reserve_time', ...)` does not compile.
// Here the name is in a variable, so each call runs and returns `false`.
string $name = 'log.handler_reserve_time';
echo 'give it an hour: ', Core\Config::set($name, '1h') ? 'accepted' : 'not allowed', "\n";
echo 'give it a moment: ', Core\Config::set($name, '1ms') ? 'accepted' : 'not allowed', "\n";
// A program may lower its own `limits.cpu_time`. The time for the report stays `5s`.
echo 'bound my own run: ', Core\Config::set('limits.cpu_time', '2s') ? 'accepted' : 'not allowed', "\n";
echo 'time for the report still: ', Core\Config::get('log.handler_reserve_time') ?? '(nothing written)', "\n";
Output
time for the report: 5s
memory beside it: 16M
the request-side time: 50ms
the request-side heap: 1M
give it an hour: not allowed
give it a moment: not allowed
bound my own run: accepted
time for the report still: 5s

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

log.target

[log] target sets where Novis writes the record of a failure that it reports itself.

When a request fails, Novis first runs the program's own error handler. If that does not run, it runs the script that [log] handler names. If that fails too, Novis writes the record itself. [log] target is where that record goes.

The value is stderr (the standard error stream), file:<path>, or syslog. When the key is not set, it is stderr. A service that does not set it writes to logs/nvs.log in the data folder. [log] max_size and [log] keep limit the size of a file.

Only the person who runs the server can set this key. A program cannot change it. Novis checks the value when it reads the configuration file, and a value it does not know is an error.

The example prints the target and shows that a program cannot change it.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

Where the record of a failure goes

<?nvs
// `[log] target` is where the server writes the record of a failure. It is used
// when neither the program's handler nor the `[log] handler` script could run.
echo 'records go to: ', Core\Config::get('log.target') ?? '(nothing written — stderr, which is the floor default)', "\n";
// A target can be `stderr`, a file or `syslog`. A program cannot change it, so `Core\Config::set('log.target', ...)`
// with the name as text does not compile. Here the name is in a variable, so every call runs and returns `false`.
string $name = 'log.target';
array<string> $destinations = ['stderr', 'file:/var/log/nvs.log', 'syslog'];
foreach ($destinations as string $destination) {
echo 'send them to ', $destination, ': ', Core\Config::set($name, $destination) ? 'accepted' : 'not allowed', "\n";
}
// A program may change `log.format` and `log.level` for one request.
// The target stays the same.
echo 'trace this one run: ', Core\Config::set('log.level', 'Debug') ? 'accepted' : 'not allowed', "\n";
Core\Config::restore('log.level');
echo 'destination now: ', Core\Config::get('log.target') ?? '(nothing written — still stderr)', "\n";
Output
records go to: (nothing written — stderr, which is the floor default)
send them to stderr: not allowed
send them to file:/var/log/nvs.log: not allowed
send them to syslog: not allowed
trace this one run: accepted
destination now: (nothing written — still stderr)

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

log.max_size

How large a log file can grow before Novis starts a new one.

This setting is used when [log] target is a file, such as target = "file:/var/log/nvs.log". When the next record would make the file larger than max_size, Novis renames the file to nvs.log.1. Then it writes the record to a new, empty nvs.log. Older files move up one number, so nvs.log.1 becomes nvs.log.2. [log] keep sets how many of these old files stay on disk.

The value is a size, such as "10M" or "1G". When it is not set, it is "10M". A size of 0 or false is not allowed, and the server does not start.

Only the person who runs the server can change this setting. A program cannot change it, so a program cannot make its log fill the disk.

The example prints the setting and shows that a program cannot change it.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

How large a log file grows

<?nvs
// This program prints the size limit of a log file and shows that a program cannot change it.
// This file does not set `log.max_size`, so this prints the default, `10M`.
echo 'max_size: ', Core\Config::get('log.max_size') ?? '(no value)', "\n";
// Only `nvs.toml` can set `log.max_size`.
// `Core\Config::set('log.max_size', ...)` does not compile,
// because a program may not change `log.max_size`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.
string $name = 'log.max_size';
echo 'set it to 1G: ', Core\Config::set($name, '1G') ? 'accepted' : 'not allowed', "\n";
echo 'remove the limit: ', Core\Config::set($name, 'false') ? 'accepted' : 'not allowed', "\n";
echo 'max_size now: ', Core\Config::get('log.max_size') ?? '(no value)', "\n";
Output
max_size: 10M
set it to 1G: not allowed
remove the limit: not allowed
max_size now: 10M

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

log.keep

How many old log files Novis keeps next to a log file.

This setting is used when [log] target is a file. When the file reaches [log] max_size, Novis renames it to nvs.log.1, and the old files move up one number. A file whose number would be larger than keep is deleted. With keep = 5 and max_size = "10M", the log uses at most 60 MB of disk: the current file and five old ones.

The value is a whole number. When it is not set, it is 5. With keep = 0, Novis deletes the full file and starts a new one, so no old records stay on disk. false and negative numbers are not allowed, and the server does not start.

Only the person who runs the server can change this setting. A program cannot change it.

The example prints the setting and shows that a program cannot change it.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

How many old log files stay

<?nvs
// This program shows how many old log files Novis keeps.
// This file does not set `log.keep`, so this prints the default, `5`.
echo 'keep: ', Core\Config::get('log.keep') ?? '(no value)', "\n";
// Only `nvs.toml` can set `log.keep`.
// `Core\Config::set('log.keep', ...)` does not compile,
// because a program may not change `log.keep`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.
string $name = 'log.keep';
echo 'keep 1000 files: ', Core\Config::set($name, '1000') ? 'accepted' : 'not allowed', "\n";
echo 'keep 0 files: ', Core\Config::set($name, '0') ? 'accepted' : 'not allowed', "\n";
echo 'keep now: ', Core\Config::get('log.keep') ?? '(no value)', "\n";
Output
keep: 5
keep 1000 files: not allowed
keep 0 files: not allowed
keep now: 5

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

log.client_ip

Whether the log lines the server writes contain the client's IP address.

The server writes one access line per request when [log] access is on. It always writes a line for a response with a 5xx status. Each of these lines has a field clientIp with the client address.

With client_ip = false, these lines have no clientIp field. The field is not written as null. The value is true or false, and it is true when it is not set.

Use this setting when you promise your users that you do not store their IP address. Core\Request::clientIp() still returns the address while the request runs, so your program can limit how many requests one address sends.

Only the person who runs the server can change this setting. A program cannot change it. A new value is used from the next request after a reload.

The example prints the setting and shows that a program cannot change it.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

Whether the log has the client address

<?nvs
// This program shows whether the server's log lines contain the client address.
// This file does not set `log.client_ip`, so this prints the default, `true`.
echo 'client_ip: ', Core\Config::get('log.client_ip') ?? '(no value)', "\n";
// Only `nvs.toml` can set `log.client_ip`.
// `Core\Config::set('log.client_ip', ...)` does not compile,
// because a program may not change `log.client_ip`.
// This program keeps the name in a variable. The compiler does not check a variable, so `set` runs and returns `false`.
string $name = 'log.client_ip';
echo 'turn it off: ', Core\Config::set($name, 'false') ? 'accepted' : 'not allowed', "\n";
echo 'client_ip now: ', Core\Config::get('log.client_ip') ?? '(no value)', "\n";
Output
client_ip: true
turn it off: not allowed
client_ip now: true

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.