Skip to content

add color to console and file logger#172

Merged
g11tech merged 38 commits intomainfrom
color-logging
Sep 15, 2025
Merged

add color to console and file logger#172
g11tech merged 38 commits intomainfrom
color-logging

Conversation

@noopur23
Copy link
Copy Markdown
Contributor

  • Add colors for console logging
  • Add colors for file logging with option to turn it off from cli for non color supported editors
  • Add testLogger tests - level set to debug and no file logging

closes #140

@g11tech g11tech changed the title Color logging, testLogger add color to console and file logger Sep 14, 2025
@noopur23 noopur23 requested a review from g11tech September 14, 2025 18:29
@noopur23 noopur23 marked this pull request as ready for review September 14, 2025 18:32
Copilot AI review requested due to automatic review settings September 14, 2025 18:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds color support to both console and file logging in the Zeam project. The changes include colored output for different log levels (error, warn, info, debug), timestamps, and scopes, with an option to disable colors in file logs for compatibility with non-color-supporting editors.

  • Add color constants and formatting to the logging system with ANSI escape codes
  • Introduce a monocolorFile option to control colored output in log files
  • Add a new getTestLogger() function for test environments with debug-level logging and no file output

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkgs/utils/src/log.zig Adds color support with ANSI escape codes, implements file color toggling, and introduces test logger functionality
pkgs/state-transition/src/mock.zig Updates to use the new test logger instead of regular logger
pkgs/state-transition/src/lib.zig Updates test functions to use the new test logger
pkgs/node/src/forkchoice.zig Updates test to use the new test logger
pkgs/node/src/chain.zig Updates test to use the new test logger
pkgs/cli/src/main.zig Adds CLI option for monochrome file logging and ensures log directory creation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

.fileActiveLevel = fileParams.?.fileBehaviour.fileActiveLevel,
.file = fileParams.?.file.?,
}
FileLogParams{ .fileActiveLevel = fileParams.?.fileBehaviour.fileActiveLevel, .file = fileParams.?.file.?, .monocolorFile = fileParams.?.fileBehaviour.monocolorFile }
Copy link

Copilot AI Sep 14, 2025

Choose a reason for hiding this comment

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

[nitpick] This struct initialization is very long and hard to read on a single line. Consider breaking it into multiple lines for better readability.

Suggested change
FileLogParams{ .fileActiveLevel = fileParams.?.fileBehaviour.fileActiveLevel, .file = fileParams.?.file.?, .monocolorFile = fileParams.?.fileBehaviour.monocolorFile }
FileLogParams{
.fileActiveLevel = fileParams.?.fileBehaviour.fileActiveLevel,
.file = fileParams.?.file.?,
.monocolorFile = fileParams.?.fileBehaviour.monocolorFile,
}

Copilot uses AI. Check for mistakes.
@noopur23 noopur23 requested a review from Copilot September 15, 2025 08:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +52 to 56
var print_str = std.fmt.bufPrint(
buf[0..],
"{s} {s}" ++ fmt ++ "\n",
.{ timestamp_str, prefix } ++ args,
"{s}{s}{s} {s}[{s}]{s} {s}{s}{s}" ++ fmt ++ "\n",
.{ timestamp_color, timestamp_str, reset_color, level_color, comptime level.asText(), reset_color, scope_color, scope_prefix, reset_color } ++ args,
) catch return;
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

The format string is complex and difficult to read with 9 format specifiers. Consider breaking this into separate formatting steps or using a helper function to construct the colored message parts.

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +70
print_str = std.fmt.bufPrint(
buf[0..],
"{s} {s}" ++ fmt ++ "\n",
.{ timestamp_str, prefix } ++ args,
) catch return;
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

The variable prefix is used but not defined in the current scope. This should likely be the original format that was replaced by the colored version above.

Copilot uses AI. Check for mistakes.

nosuspend fileLogParams.?.file.writeAll(print_str) catch |err| {
stderr.print("{s} [ERROR] {s}: Failed to write to log file : {any}\n", .{ timestamp_str, scope_prefix, err }) catch {};
stderr.print("{s}{s}{s} {s}[ERROR]{s} {s}{s}{s}Failed to write to log file: {any}\n", .{ timestamp_color, timestamp_str, reset_color, Colors.err, reset_color, scope_color, scope_prefix, reset_color, err }) catch {};
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

This error message format string is also overly complex with 9 format specifiers. Consider using a helper function for consistent error message formatting.

Copilot uses AI. Check for mistakes.
@@ -265,6 +270,10 @@ pub fn getLogger(activeLevel: ?std.log.Level, fileBehaviourParams: ?FileBehaviou
return ZeamLogger.init(.default, activeLevel orelse std.log.default_level, fileBehaviourParams);
}

Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

The getTestLogger function lacks documentation explaining its purpose and when it should be used instead of getLogger.

Suggested change
/// Returns a ZeamLogger instance configured for use in test environments.
/// Unlike `getLogger`, this logger always uses the default log level and does not write to any file.
/// Use this function when you need a logger for tests and do not require file logging or custom log levels.

Copilot uses AI. Check for mistakes.
@g11tech g11tech merged commit 989dadc into main Sep 15, 2025
6 checks passed
@g11tech g11tech deleted the color-logging branch September 15, 2025 09:11
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.

color code the level (like [info] [debug]) into different colors, as well as timestamp and where we print the scope

3 participants