Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Better logging #819

Merged
merged 21 commits into from
Jan 7, 2019
Merged

Better logging #819

merged 21 commits into from
Jan 7, 2019

Conversation

zippy
Copy link
Member

@zippy zippy commented Jan 4, 2019

This PR adds:

  • ChanelLogger: a generic implementation of Logger that sends the log message over a channel.
  • a DebugLogger at the container level which uses ChannelLogger for collect log messages
  • a LogRules which allow you to match for log messages you want (or don't want) and colorize them
  • colorization by instance id
  • updating of current log messages in the code to follow a convention of classifying them by type (debug/notify/warn/error) and code section.
  • removes configuration of logger at the instance level and promotes it to the container level

@zippy zippy added the review label Jan 4, 2019
@zippy zippy changed the title WIP: Better logging Better logging Jan 4, 2019
Copy link
Contributor

@StaticallyTypedAnxiety StaticallyTypedAnxiety left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot! What do you think about changing those unwraps to an "expect" just to give more context?

Copy link
Member

@maackle maackle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. We'll have decent logs now!

(now for some thoughts on future logging features that aren't really relevant right now but I want to get them out there)


Looking forward, the benefit of regex coloring may quickly degrade if we don't have conventions for log prefixes (like "error/net"), because we will get lazy and put whatever we want into the log messages, or make typos, so the patterns will deviate from the regex rules. It might be nice (in the future) to have an enum for all the different kinds of internal log messages, so we're forced to pick one when writing a log statement (or add another variant for a new type of message). Barring that, we should just be careful about it.

We could take enums a step further and let the variants have structure, so we're not limited to logging just strings. Each variant can know how to serialize itself. We can also apply coloring rules directly to those variants, in addition to regex matches of what's inside. There can be a generic variant for normal debug messages with a From<&str> impl so there's no boilerplate for simple log strings.


[logger]
type = "debug"
[[logger.rules.rules]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awkward but ok :)

// renders a log message, using the id color if no color specified for the message.
pub fn render(msg: LogMessage) {
let id_color = pick_color(&msg.id);
let msg_color = match msg.color == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Option<String> for color?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

pub logger_type: String,
#[serde(default)]
pub rules: LogRules,
// pub file: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

@ddd-mtl
Copy link
Contributor

ddd-mtl commented Jan 5, 2019

How about these standard logging levels:
https://www.tutorialspoint.com/log4j/log4j_logging_levels.htm

@lucksus lucksus merged commit 7168843 into develop Jan 7, 2019
@lucksus lucksus removed the review label Jan 7, 2019
@ddd-mtl
Copy link
Contributor

ddd-mtl commented Jan 8, 2019

@zippy I see inconsistencies between "err" and "error". Might be easier with an enum?

@zippy zippy deleted the better-logging branch January 10, 2019 04:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants