JGET

explore

lumberjack

Downloads
9
Created On
1/26/2025
Last Updated
2/15/2025

Install this package:

$ jget get lumberjack

Lumberjack

Lumberjack is a logging library for Lua (computercraft). It provides logging facilities. Coming soon: a log explorer.


Logging

Choosing a logger

Lumberjack offers several loggers to choose from:

Pretty Print Logger

The basic logger is a pretty-printing logger, that will output to the terminal.

File Logger

There is also a file logger, which outputs to a file. You can construct it like so;

Network Logger

A network logger is also coming soon, which sends messages to a central server.

Logger Combinator

Lumberjack also lets you combine loggers. You might want to send all your logs to a central server, but have a local copy of just your logs too, for convenience. Or perhaps you want a saved copy, but you want all the logs to get printed out too. In that case, you should use the combo logger, which can combine an arbitrary number of loggers together:

Configuring a logger

There are also some options for configuring loggers.

Levels

First and foremost, on all loggers, you can control at what level they actually emit a log using the :withLevels function, which is used as so:

This logger will only emit logs at Warn or Error level. In general, you can use the :withLevels on any logger, and it will return a copy that only logs at the specified levels.

Using this and a combo-logger, you can build some very sophisticated pipelines - for example, here's a logger which puts errors and warnings into one file, and regular logs into another:

Printing

The full pretty-print logger output is quite cumbersome, and sometimes doesn't even fit on the terminal. Therefore, the pretty print logger is configurable - you can control what details get printed by passing a settings object to the constructor. Here's a real example; this one is is a minimal example that is quite good for applications witch only concern one machine:

The full config type looks like this:

You can also specify the time format with a strftime format string. By default, it uses "%d/%m/%y-%T" - which is also the format used to store the logs.


Using a Logger

All lumberjack loggers offer the same API.

You can create clones of a logger with different process names like so:

This allows you to have different process names for different parts of a system, if that's something you'd like.

To actually write a log, you can use one of the following functions:


Exploring your logs

The Log Format

Lumberjack logs are written in a standard format. Here's an example:

Breaking this down:

  • Log refers to the log level - it could be Warn or Error too.
  • 0(laptopTest) is the host - i.e. the computer this was logged on.
    • 0 is the Id.
    • laptopTest is the label - it will be omitted if the computer does not have one.
  • lumberjack is the process name
    • this just gives further (user controlled) granularity to distinguish where a message came from.
  • 22/12/24-21:56:33 is a timestamp - when the log was recorded
  • > ... is the actual log message

The Log Explorer

Coming soon,

Lumberjack also ships with a visual log explorer. This can load log files, and allow you to search and filter them.

other options like runtime verification are outside the scope of this.