-
Notifications
You must be signed in to change notification settings - Fork 139
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
Print logs to stderr #4922
base: main
Are you sure you want to change the base?
Print logs to stderr #4922
Conversation
Unused dependencies (1)
Unused devDependencies (1)
Unused types (1)
|
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/output.d.ts@@ -141,19 +141,19 @@ export interface OutputProcess {
action: (stdout: Writable, stderr: Writable, signal: AbortSignal) => Promise<void>;
}
/**
- * Prints a log message in the console.
+ * Prints a log message in the console to stdout.
*
* @param message - The message to print.
*/
export declare function consoleLog(message: string): void;
/**
- * Prints an error message in the console.
+ * Prints an error message in the console to stderr.
*
* @param message - The message to print.
*/
export declare function consoleError(message: string): void;
/**
- * Prints a warning message in the console.
+ * Prints a warning message in the console to stderr.
*
* @param message - The message to print.
*/
|
@@ -258,7 +256,7 @@ export const clearCollectedLogs = (): void => { | |||
* @param content - The content to be output to the user. | |||
* @param logger - The logging function to use to output to the user. | |||
*/ | |||
export function outputInfo(content: OutputMessage, logger: Logger = consoleLog): void { | |||
export function outputInfo(content: OutputMessage, logger: Logger = consoleWarn): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest a export function output(content: outputMessage, logger: Logger = consoleLog): void {
?
That way all the output{log,warn,error}
would all go to stderr and we'd make it explicit which one goes to stdout?
STDOUT = scriptable output
STDERR = logging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log
goes to stdout...
I think the idea is that we have several output functions based on log level, but by default all log to consoleWarn
which uses console.warn
which goes to stderr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's what I'm saying. Let's change this so that console.log is only used intentionally.
outputInfo
- STDERR loglevel infooutputDebug
- STDERR loglevel debugoutputWarn
- STDERR loglevel warnoutputError
- STDERR loglevel erroroutput
- STDOUT. Use only for JSON or whatever could be piped into another bash script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should ever log anything without specifying a log level. We can default everything to stderr and make stdout an explicit choice by specifying stdout as the logger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk I think output is output and logging is logging. I personally don't see a problem with these two things:
- logging that goes to STDERR and requires a loglevel
- output goes to STDOUT and doesn't require a loglevel.
STDOUT is for piping & scripts. Why would we want a loglevel in there? What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because, while we don't currently support it, many programs have a silent
log level which doesn't print anything. And I think we should ultimately support that. Keeping everything with log levels gives us more room to fine-tune logging behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a good example: https://docs.npmjs.com/cli/v10/using-npm/config#loglevel
Silent is just another log level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that mean that --json --silent
do nothing at all? There's always &> /dev/null
?
Whenever I'm scripting, I'm mostly annoyed by shit showing up in STDOUT and that's why I'd want --silent
, but if it doesn't, then I don't see the point.
One of pnpm
or nx
is an example offender here. If I want to run the shopify theme language-server
with the dev build in Shopify/cli, I can only do that by running the build node package stuff because otherwise pnpm & nx are outputting crap to STDOUT that don't fit the LSP.
Same goes for pnpm shopify theme check --json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that reason, whenever I want to test a Shopify/theme-tools bump in vim. I have to use a script in my $HOME/bin that is this:
#!/usr/bin/env bash
if [[ -z $DEBUG ]]; then
node /Users/charles/src/github.com/Shopify/cli/packages/cli/bin/dev.js "$@"
else
node --inspect-brk /Users/charles/src/github.com/Shopify/cli/packages/cli/bin/dev.js "$@"
fi
Which means I need pnpm run build
any time I want to test it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried pnpm --silent shopify:run ...
--silent
quiets pnpm
shopify:run
skips the build step (you have to run pnpm shopify build
first, but anyway you need to do that in your script)
WHY are these changes introduced?
Fixes #3863
WHAT is this pull request doing?
How to test your changes?
Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist