Convert COG_LOG_LEVEL=warning to use "warn" so zap can parse it#210
Convert COG_LOG_LEVEL=warning to use "warn" so zap can parse it#210michaeldwan wants to merge 2 commits into
COG_LOG_LEVEL=warning to use "warn" so zap can parse it#210Conversation
Cog sets `COG_LOG_LEVEL=warning` when running predictors. Python's logger (used before cog-runtime came along) can parse `warning,WARNING,warn,WARN` zap only accepts `warn,WARN`. This difference is causing `Failed to parse log level "warning": unrecognized level "warning"` to show up in user-facing logs. We _can_ fix the issue in cog, but we'd still have differences in behavior depending on the version of cog, cog-runtime, or cog-python being used. So safest thing is to normalize it here.
There was a problem hiding this comment.
Pull Request Overview
Normalizes the log level environment variable COG_LOG_LEVEL to use "warn" instead of "warning" for compatibility with zap's log level parser, preventing user-facing error messages about unrecognized log levels.
- Converts "WARNING" to "WARN" to match zap's expected format
- Maintains uppercase formatting for consistency with zap parsing
- Sets default log level to "INFO" when no level is specified
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| logLevel := strings.ToUpper(os.Getenv("COG_LOG_LEVEL")) | ||
| switch logLevel { | ||
| case "WARNING": | ||
| logLevel = "WARN" | ||
| case "": | ||
| logLevel = "INFO" | ||
| } |
There was a problem hiding this comment.
The switch statement only handles uppercase values but converts all input to uppercase first. Consider adding a case for lowercase 'warning' or documenting that the ToUpper conversion handles case-insensitive matching.
|
In theory go/replcate/logging does this already https://github.com/replicate/go/blob/b69e565fb9392b3016ed64c2e833d9c19b320e87/logging/logging.go#L39 Related, logging is on the short list to address post big refactor (introduce trace level and squash even more logging). Also big refactor resolved the ability to set debug level logging. |
|
@tempusfrangit what's the right way to proceed? I just want the warnings to stop showing in cog. I also saw there's 2 places we parse logs in main, which we may want to unify: https://github.com/search?q=repo%3Areplicate%2Fcog-runtime%20ParseLevel&type=code |
|
replaced by #216 |
Cog sets
COG_LOG_LEVEL=warningwhen running predictors.Python's logger (used before cog-runtime came along) can parse
warning,WARNING,warn,WARNzap only acceptswarn,WARN.This difference is causing
Failed to parse log level "warning": unrecognized level "warning"to show up in user-facing logs.We can fix the issue in cog, but we'd still have differences in behavior depending on the version of cog, cog-runtime, or cog-python being used. So safest thing is to normalize it here.