Skip to content

Logging

Graham Steffaniak edited this page Jan 16, 2025 · 13 revisions

Logging Explainer Wiki

This version of filebrowser comes with a robust logger built-in that offers a variety of features.

Note: this requires v0.4.0 or later

Do I need to configure the logger?

By default, if nothing is configured, the logger writes all INFO, ERROR, WARNING, and API events to the stdout with colors enabled.

The above default means you will see text logs in the terminal where you run the program like you would expect.

On windows or certain terminal prompts, colors may not work and you may see \033[0m text show up -- this indicates your terminal does not support colors and you would want to configure a logger with colors disabled to fix this.

Can I log to a file?

Yes! You can log to a file or multiple different files each with their own settings. Do you want errors to go to errors.log or API event logs to go to apievents.log you can do that!

How do I configure a custom logger?

You can configure logging with the following format:

This would only log to file (not stdout)

server:
  logging:
    - output: "path/to/targetfile.log" # or "stdout"
      level: "info" # or "debug", "error", "api"

This example would only log to stdout. (disables colors/api logs)

server:
  logging:
    - noColors: true
      noApi: true

This example would log to terminal (without api events) and also send error-level logs to errors.log (except API errors) and api logs to api-events.log

server:
  logging:
    - output: stdout
      noApi: true
    - output: "api-events.log"
      level: api
      noColors: true
    - output: "errors.log"
      level: error
      noApi: true
      noColors: true

Can I log a specific level and not others?

It depends. Log levels are hierarchical , meaning any level lower than the chosen will get logged.

Here are the levels:

	DISABLED LogLevel = 0
	ERROR    LogLevel = 1
	FATAL    LogLevel = 1
	WARNING  LogLevel = 2
	INFO     LogLevel = 3
	DEBUG    LogLevel = 4
	API      LogLevel = 10

This means if you set your log level to ERROR, you will see only ERROR and FATAL logs, but nothing greater.

If you set your level to WARNING, you will see WARNING and ERROR/FATAL. And so on.

However, for API log level logs have their own special rules and you can specify exactly which API messages you want to log.

Clone this wiki locally