-
Notifications
You must be signed in to change notification settings - Fork 78
Logging
Jonathan Daugherty edited this page May 1, 2018
·
11 revisions
This page is about improving Matterhorn's logging infrastructure.
- Logging should cost nothing or almost nothing if it is disabled.
- Logging should be possible without triggering redraws.
- The
mattermost-api
library should be able to participate in the same logging infrastructure that is used by the main application. This may require modifying the API library. - Recent messages should be available in an internal buffer regardless of whether logging is enabled. (Logging is "enabled" if log messages are being written to an external location such as a disk file.)
- Ordered log levels have lots of problems. Initially we'll go with an approach that doesn't assign ordered levels to log messages, but rather assigns tags that are similar to levels (for categorization) but have no ordering relationship.
- There will initially be no logging UI in the program itself. Instead,
we can add keybindings and commands to:
- start logging: open the log file for append, write the current ring buffer contents to the log file, and then begin appending log messages as they arrive from the program.
- stop logging: close the log file.
- The start and stop operations should emit additional output lines indicating the beginning and end of the buffer flush as well as the start or end of logging.
- All log messages should be timestamped.
- We'll use a Sequence to hold the internal buffer for efficient modification
- We'll have a logging thread responsible for owning the ring buffer and
managing output to the log file (when enabled). We'll need a channel
to that thread for sending logging protocol messages:
- log a message
- start logging to a disk file
- stop logging to a disk file
- We'll need a function
mhLog :: Tag -> Text -> MH ()
for logging. The tag type is for classifying messages. - We'll add an implicit logging context to
MH
. The context can then be manipulated with a combinatorwithContext :: LogContext -> MH a -> MH a
. The log context can include data relevant to any logging done in the monadic action, such as channel ID. All log messages will include a log context. -
mhError
and similarMH
functions should be instrumented with calls tomhLog
.