Skip to content

Tag log messages with originating stream#903

Draft
LasmarKhalifa wants to merge 1 commit into
mainfrom
05-28/log-message-prototype
Draft

Tag log messages with originating stream#903
LasmarKhalifa wants to merge 1 commit into
mainfrom
05-28/log-message-prototype

Conversation

@LasmarKhalifa
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment on lines -124 to +127
Roast::Log.logger.warn { "#{format_path(event)} ❯❯ #{event[:stderr]}" }
Roast::Log.logger.warn(Roast::Log::Message.new(
stream: :stderr,
text: "#{format_path(event)} ❯❯ #{event[:stderr]}",
))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is really clever. I like the approach of passing through a richer context object than just a string, so we can include additional parameters like the originating stream.

A couple minor optimizations I'd suggest:

The style of the existing logger invocation that might seem somewhat odd at first glance, where the message argument is passed inside a block passed to the logger.warn method instead of just passing the message directly as a string serves a useful purpose. The block is not evaluated at all if the relevant log level is disabled, saving the cost of the string formatting that happens inside it (and any additional work, which might in some cases be more substantial, like computing a full stack trace, etc.). I'd like to preserve that style of invocation, so please look into returning the Roast::Log::Message from a block instead of passing it directly (and because it now includes object instantiation, not just string formatting, there is actually a bit more perf overhead to save when the log won't actually be emitted).

I'd also suggest you consider renaming the stream parameter to something more generic, like type. Right now, special colouring rules are only used for stdout and stderr, but it might be the case that in the future we want additional special colours (for instance, we might want them for block output for prompts and/or responses of chat and agent cogs), so making that param a little more generic makes it more future-proof for this kind of thing

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.

2 participants