Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: configurable log levels, file logging (#359) #488

Merged
merged 10 commits into from
Jan 20, 2021
Merged

console: configurable log levels, file logging (#359) #488

merged 10 commits into from
Jan 20, 2021

Conversation

iceiix
Copy link
Owner

@iceiix iceiix commented Jan 19, 2021

No description provided.

@iceiix
Copy link
Owner Author

iceiix commented Jan 19, 2021

Current status: this works, logging to client.log in the configuration directory (as of #486, this is either the current working directory -or-:

// Lin: Some(/home/alice/.config)
// Win: Some(C:\Users\Alice\AppData\Roaming)
// Mac: Some(/Users/Alice/Library/Application Support)

), and to the terminal (now with color). But now nothing logs to the in-game console, nor the browser console (for #446 web). And configurable log levels would be nice, instead of hardcoding trace (add options in conf.cfg?). In particular, the terminal log output could have a lower log level to reduce console overhead, but keep the file log level higher (trace? debug?) for diagnosing problems after they happen.

Also allow disabling terminal colors, if it causes problems (TermLogger -> SimpleLogger, depending on a config option).

Maybe stop logging to the in-game console, and use it instead for #479 chat, and other client/server messages. It has a different purpose than diagnostic logging (trace/debug/info/warn/error).

@iceiix iceiix changed the title Use simplelog, combined terminal and file logging (#359) console: configurable log levels, file logging (#359) Jan 20, 2021
@iceiix iceiix marked this pull request as ready for review January 20, 2021 04:36
@iceiix iceiix linked an issue Jan 20, 2021 that may be closed by this pull request
@iceiix
Copy link
Owner Author

iceiix commented Jan 20, 2021

It was more straightforward to extend our existing logger backend than switch out to another logging system.

Added file logging and configurable log levels (edit in conf.cfg). The default of info for terminal (and trace for file) should help cut down on the stdout output, especially while network debugging, but keep this valuable information available in the log file (client.log).

Removing logging to the in-game console can come later, after #479 chat. Adding colors to the terminal output would be nice too, just like there are in the in-game console, using TextComponents (but not strictly necessary. convert the TextComponents to ANSI codes?):

        let mut msg = TextComponent::new("");
        msg.modifier.extra = Some(vec![
            Component::Text(TextComponent::new("[")),
            {
                let mut msg = TextComponent::new(file);
                msg.modifier.color = Some(Color::Green);
                Component::Text(msg)
            },
            Component::Text(TextComponent::new(":")),
            {
                let mut msg = TextComponent::new(&format!("{}", record.line().unwrap_or(0)));
                msg.modifier.color = Some(Color::Aqua);
                Component::Text(msg)
            },
            Component::Text(TextComponent::new("]")),
            Component::Text(TextComponent::new("[")),
            {
                let mut msg = TextComponent::new(&format!("{}", record.level()));
                msg.modifier.color = Some(match record.level() {
                    log::Level::Debug => Color::Green,
                    log::Level::Error => Color::Red,
                    log::Level::Warn => Color::Yellow,
                    log::Level::Info => Color::Aqua,
                    log::Level::Trace => Color::Blue,
                });
                Component::Text(msg)
            },
            Component::Text(TextComponent::new("] ")),
            Component::Text(TextComponent::new(&format!("{}", record.args()))),
        ]);

@iceiix iceiix merged commit 3daa9c0 into master Jan 20, 2021
@iceiix iceiix deleted the log branch January 20, 2021 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging to a file
1 participant