{"record":{"id":"1162c2658ec21d1f","repo":"googleapis/mcp-toolbox","slug":"unable-to-initialize-logger-w","errorCode":null,"errorMessage":"unable to initialize logger: %w","messagePattern":"unable to initialize logger: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/options.go","lineNumber":98,"sourceCode":"\treturn func(o *ToolboxOptions) {\n\t\to.IOStreams.Out = out\n\t\to.IOStreams.ErrOut = err\n\t}\n}\n\n// Setup create logger and telemetry instrumentations.\nfunc (opts *ToolboxOptions) Setup(ctx context.Context) (context.Context, func(context.Context) error, error) {\n\t// If stdio, set logger's out stream (usually DEBUG and INFO logs) to\n\t// errStream\n\tloggerOut := opts.IOStreams.Out\n\tif opts.Cfg.Stdio {\n\t\tloggerOut = opts.IOStreams.ErrOut\n\t}\n\n\t// Handle logger separately from config\n\tlogger, err := log.NewLogger(opts.Cfg.LoggingFormat.String(), opts.Cfg.LogLevel.String(), loggerOut, opts.IOStreams.ErrOut)\n\tif err != nil {\n\t\treturn ctx, nil, fmt.Errorf(\"unable to initialize logger: %w\", err)\n\t}\n\n\tctx = util.WithLogger(ctx, logger)\n\topts.Logger = logger\n\n\tctx = util.WithIgnoreUnknownTools(ctx, opts.Cfg.IgnoreUnknownTools)\n\n\tlogger.InfoContext(ctx, fmt.Sprintf(\"Starting MCP Toolbox for Databases version %s\", opts.Cfg.Version))\n\n\t// Set up OpenTelemetry\n\totelShutdown, err := telemetry.SetupOTel(ctx, opts.Cfg.Version, opts.Cfg.TelemetryOTLP, opts.Cfg.TelemetryGCP, opts.Cfg.TelemetryGCPProject, opts.Cfg.TelemetryServiceName)\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"error setting up OpenTelemetry: %w\", err)\n\t\tlogger.ErrorContext(ctx, errMsg.Error())\n\t\treturn ctx, nil, errMsg\n\t}\n\n\tshutdownFunc := func(ctx context.Context) error {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/cmd/internal/options.go#L80-L116","documentation":"Returned by the public `Setup` method in cmd/internal/options.go when `log.NewLogger` cannot construct the application logger from the configured logging format, log level, and output streams. Since Setup is invoked by every entrypoint (runInvoke, runMigrate, runServe, run), an invalid logger configuration prevents the binary from starting at all. The wrapped error from NewLogger names the invalid format or level value.","triggerScenarios":"Passing an unsupported value via the --logging-format flag (or LOGGING_FORMAT env / config file), e.g. \"structured\" or \"jsonl\" instead of a supported value like \"json\" or \"standard\"; similarly an invalid --log-level such as \"verbose\" or \"trace\" instead of debug/info/warn/error.","commonSituations":"Typo in a YAML/JSON config file's logging section after editing; CI pipeline exporting a custom LOGGING_FORMAT env var; upgrading the toolbox and using a log level/format string from a different tool's convention; quoting mistakes leaving stray whitespace or quotes in the config value.","solutions":["Read the wrapped error text to see which value was rejected; fix --logging-format or --log-level to a supported value (e.g. logging-format: \"json\", log-level: \"debug\").","Check environment variables (LOGGING_FORMAT, LOG_LEVEL) that override flags; unset or correct them.","Trim whitespace/quotes around the value in the config file and re-run.","Run `./toolbox --help` (or check docs/en/reference) to list the exact accepted format and level strings."],"exampleFix":"// before: invalid value in tools.yaml\nlogging:\n  format: \"structured\"\n  level: \"verbose\"\n// after\nlogging:\n  format: \"json\"\n  level: \"debug\"","handlingStrategy":"validation","validationCode":"validFormats := map[string]bool{\"standard\": true, \"json\": true}\nvalidLevels := map[string]bool{\"debug\": true, \"info\": true, \"warn\": true, \"error\": true}\nif !validFormats[strings.TrimSpace(os.Getenv(\"LOGGING_FORMAT\"))] && os.Getenv(\"LOGGING_FORMAT\") != \"\" {\n    log.Fatalf(\"LOGGING_FORMAT=%q is not supported\", os.Getenv(\"LOGGING_FORMAT\"))\n}\nif !validLevels[strings.TrimSpace(os.Getenv(\"LOG_LEVEL\"))] && os.Getenv(\"LOG_LEVEL\") != \"\" {\n    log.Fatalf(\"LOG_LEVEL=%q is not supported\", os.Getenv(\"LOG_LEVEL\"))\n}","typeGuard":null,"tryCatchPattern":"ctx, shutdown, err := opts.Setup(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to initialize logger\") {\n        fmt.Fprintf(os.Stderr, \"logger config invalid: %v — check --logging-format and --log-level values\\n\", err)\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["Copy flag/config values only from the official docs or `--help` output; do not reuse values from other tools.","Validate the logging section of your YAML/JSON config in CI before deploying.","Grep for LOGGING_FORMAT/LOG_LEVEL exports in shell profiles and CI env blocks when the value is unexpected.","Prefer config-file values over ad-hoc environment overrides to keep startup deterministic."],"tags":["go","logging","configuration","startup"],"backgroundTag":"invalid-config-value","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}