Skip to content

EventLogger Behavior

Protected edited this page Nov 18, 2023 · 1 revision

EventLogger allows other Behaviors to log events to files that will be stored in the path declared in the basePath configuration parameter. Rowboat loggers use winston under the hood.

Some important concepts:

  • Log channels: Each message sent to EventLogger has a single associated channel.
  • Templates: Log templates can be defined using the templateNAME config parameters, where NAME is the name of the template. They can be used for assembling a key-value map of fields into a single message for logging to a text file:

Each occurence of %FIELD% in the template will be replaced by the value of that field.

Each occurence of %(MOMENT)% (note the parentheses) will be replaced by a date-time string where MOMENT is a moment format string.

Log file declaration

Log files can be declared using the logs config parameter. This parameter should contain a list of objects each with the following format:

{outputFile: MOMENT, channels: [LOG CHANNEL, ...]}

outputFile takes a moment format string, allowing you to include date and time information in log file names. Enclose a string in [square brackets] if you want it to be used literally. Whenever the log file name resolves to the same string, data is logged into the same file.

channels is a list of log channels. All channels listed will be aggregated and logged together into the specified file in order of arrival. It's possible to log the same channel to multiple log file templates, but if no channels are specified nothing will be logged.

Built in logging channels

EventLogger can log some events from initialized Environments without requiring any additional Behaviors. The following channels are provided by default and can be used in logs:

  • join: This log channel is sent Environments' join events using templateJoin.
  • part: This log channel is sent Environments' part events using templatePart.
  • TYPE, where TYPE is a message type: This log channel is sent Environments' message events using templateMessage.

Messages of type regular and action are collapsed together into a log channel called public, which is useful for IRC compatibility. Likewise, private and privateaction are collapsed into the private log channel.

Logging methods

Dependent Behaviors can use these methods for logging additional events.

  • write(logchannel, message) - For low level logging; this method sends the message string to logchannel as a literal, ignoring the template system. It returns the amount of log files the message was written to (0 if none).
  • templateWrite(logchannel, template, fields) - Assembles a message by taking the given template string and expanding %FIELD% references to the contents of the fields map, as described above. The message is then logged to logchannel. Use this method if you want to use the template system, but want to provide the template itself from your own Behavior.
  • templateNameWrite(logchannel, templatename, fields) - Same as the previous method, but instead of taking the template as a string, it will search for template in the EventLogger config by reading the parameter templateNAME, where NAME is templatename.
Clone this wiki locally