Logging

Riker provides logging out of the box which is built on top of the Log crate logging facade. The logger module starts during the actor system's start, making log macros such as info!, debug!, error! available immediately after ActorSystem::new:

  1. #[macro_use]
  2. extern crate log;
  3.  
  4. let sys = ActorSystem::new().unwrap();
  5. info!("My first log message!");

The only requirement is importing the Log crate into your application.

Base log level

The base log level is the level at which the Log crate's macros determine whether to ignore a message or forward it to the logger module. This is configured in riker.toml:

  1. [log]
  2. level = "debug"

Default logger

Log messages will be routed to the logging module configured in the model.The rest of this page refers primarily to the default Riker logger, the riker-logger crate.

Since the default logger is an actor log messages are handled concurrently, in a non-blocking manner. This means the impact of logging on an application's response time is reduced.

The default logger has the following features:

  • Log entry format is configurable using named parameters
  • Date and time formats can be configured
  • Log entries can be further filtered at the module level
  • An optional filter can be configured to omit logs from certain modulesLet's take a look at an example log configuration in riker.toml:
  1. [log]
  2. # max level to log
  3. level = "debug"
  4.  
  5. # Uncomment this to enable filters on the logger. The {module} field
  6. # of every log line will be checked, and if the {module} field contains
  7. # any item in this list, the entire log line will be omitted from the
  8. # logging output.
  9. #
  10. # This example will omit any logging output from any module with
  11. # "test" in the name and any module whose name contains "debug".
  12. #
  13. filter = [ "test", "debug" ]
  14.  
  15. # log format to use
  16. # correlates to format!(log_format, date=, time=, level=, module=, body=);
  17. # since named parameters are used the order of the fields is flexible
  18. # the formatting of each field can be changed also
  19. # e.g. to completely hide a field: {module:.0}
  20. # See: https://doc.rust-lang.org/std/fmt/#syntax
  21.  
  22. # {date} the calendar day
  23. # {time} the calendar time
  24. # {level} the level for the entry
  25. # {module} the module path originating the entry
  26. # {body} the message body
  27. log_format = "{date} {time} {level} [{module}] {body}"
  28. date_format = "%Y-%m-%d"
  29. time_format = "%H:%M:%S%:z"

This configuration will produce log entries formatted like:

  1. 2018-06-11 08:31:58+00:00 DEBUG [riker::system::system] Actor system started
  2. 2018-06-11 08:31:58+00:00 DEBUG [main] My first log message!

and the log lines which would have otherwise been printed:

  1. 2018-06-11 08:31:58+00:00 DEBUG [testSystem] A test line which should be filtered out!
  2. 2018-06-11 08:31:58+00:00 DEBUG [debug] A debugger module's log message

will be omitted from the log output.