{"record":{"id":"04c966b49838cc9b","repo":"netbirdio/netbird","slug":"failed-initializing-log-v","errorCode":null,"errorMessage":"failed initializing log %v","messagePattern":"failed initializing log (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/cmd/login.go","lineNumber":468,"sourceCode":"\n\tcmd.Println(\"\")\n\n\tif !noBrowser {\n\t\tif err := util.OpenBrowser(verificationURIComplete); err != nil {\n\t\t\tcmd.Println(\"\\nAlternatively, you may want to use a setup key, see:\\n\\n\" +\n\t\t\t\t\"https://docs.netbird.io/how-to/register-machines-using-setup-keys\")\n\t\t}\n\t}\n}\n\nfunc setEnvAndFlags(cmd *cobra.Command) error {\n\tSetFlagsFromEnvVars(rootCmd)\n\n\tcmd.SetOut(cmd.OutOrStdout())\n\n\terr := util.InitLog(logLevel, \"console\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed initializing log %v\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":450,"sourceCodeEnd":473,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/login.go#L450-L473","documentation":"util.InitLog(logLevel, \"console\") failed at CLI startup. Per util/log.go:38 the first thing InitLogger does is logrus.ParseLevel(logLevel), which accepts only panic, fatal, error, warn, warning, info, debug, trace (case-insensitive) - anything else (e.g. 'verbose', 'DEBUG ' with a space, an empty-ish typo) returns an error. With the \"console\" output target the log-writer branch cannot fail, so in practice this error always means the --log-level flag or its NB_LOG_LEVEL env var holds an invalid value.","triggerScenarios":"Passing an unrecognized --log-level value; setting the environment variable that feeds logLevel (e.g. NB_LOG_LEVEL) to a non-level string; trailing whitespace or typos in automated scripts and unit tests that call setEnvAndFlags.","commonSituations":"Scripts copying log-level names from other tools (verbose, warning vs warn confusion, 'prod'); CI pipelines exporting a misspelled env var value; Shell profiles exporting a stale variable that predates a level rename","solutions":["Use one of the valid levels: panic, fatal, error, warn, info, debug, or trace (warn and warning are both accepted)","Check and fix the environment: echo the NB_LOG_LEVEL-style variable feeding logLevel and unset or correct it","Grep scripts/CI config for the flag or env assignment supplying the bad value","Validate the level before the CLI call when wrapping netbird in automation (see validation code)"],"exampleFix":"# before\n$ netbird login --log-level verbose\nError: failed initializing log failed parsing log-level verbose: not a valid logrus Level: \"verbose\"\n\n# after\n$ netbird login --log-level debug","handlingStrategy":"validation","validationCode":"// Validate the level before the CLI parses it\nif _, err := logrus.ParseLevel(logLevel); err != nil {\n    return fmt.Errorf(\"invalid --log-level %q (valid: panic,fatal,error,warn,info,debug,trace)\", logLevel)\n}\nerr := util.InitLog(logLevel, \"console\")","typeGuard":"// isValidLogLevel narrows accepted flag values before calling setEnvAndFlags\nfunc isValidLogLevel(s string) bool {\n    _, err := logrus.ParseLevel(s)\n    return err == nil\n}","tryCatchPattern":"if err := util.InitLog(logLevel, \"console\"); err != nil {\n    return fmt.Errorf(\"failed initializing log: %w\", err)\n}","preventionTips":["Restrict scripts to the canonical levels: error, warn, info, debug, trace","Lint CI env vars that feed netbird flags (catch NB_LOG_LEVEL typos)","Note that 'warn' and 'warning' are both valid, but 'verbose' is not"],"tags":["logging","configuration","cli","startup","netbird"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}