Skip to content

feat: log standard output and error messages through the logger#165

Merged
pepicrft merged 2 commits intomainfrom
log-stdout-stderr
Jan 22, 2025
Merged

feat: log standard output and error messages through the logger#165
pepicrft merged 2 commits intomainfrom
log-stdout-stderr

Conversation

@pepicrft
Copy link
Copy Markdown
Contributor

@pepicrft pepicrft commented Jan 12, 2025

We allowed passing a logger instance to the CommandRunner, but we were only using it for logging the run commands, which might not be sufficient to debug failing workflows. This PR extends the usage to also log stdout and stderr .utf8 events.

@pepicrft pepicrft self-assigned this Jan 12, 2025
@pepicrft pepicrft requested review from a team, asmitbm, cschmatzler and fortmarek and removed request for a team, asmitbm and cschmatzler January 12, 2025 15:59
Copy link
Copy Markdown
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

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

For both scenarios, the output is already passed to the consumer and I think the consumer should deal with logging to stdout and stderror via the AsyncThrowingStream instead of us doing that implicitly when the logger instance is passed.

I'd keep the logger calls that we do inside CommandRunner scoped to logger.debug only.

At least as things are done now in tuist/tuist, this would easily cause duplicated output in our CLI.

Log the standard output and error messages through the logger to allow
the caller hook a loggers like syslog loggers to ease debugging.
@pepicrft
Copy link
Copy Markdown
Contributor Author

For both scenarios, the output is already passed to the consumer and I think the consumer should deal with logging to stdout and stderror via the AsyncThrowingStream instead of us doing that implicitly when the logger instance is passed.

I'd keep the logger calls that we do inside CommandRunner scoped to logger.debug only.

At least as things are done now in tuist/tuist, this would easily cause duplicated output in our CLI.

I forgot that we are conflating UI and logs currently in tuist/tuist. I adjusted it to use logger.debug to prevent duplicated logs on the caller side until we can separate the two things. I think as a follow-up work, the CLI should:

  • Use Noora for all the UI outputs.
  • Logger for debugging information.

}
} catch {
logger?.error("Error reading stdout: \(error)")
logger?.error("Error reading stdout: \(error)", metadata: loggerMetadata)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@fortmarek I ended up using metadata to pass the information of the command that's being run. The log handler can then output that information.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's smart! I like that 🙂

}
} catch {
logger?.error("Error reading stdout: \(error)")
logger?.error("Error reading stdout: \(error)", metadata: loggerMetadata)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's smart! I like that 🙂

@pepicrft pepicrft merged commit c207232 into main Jan 22, 2025
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