How to Configure Logging with CBM_LOGLEVEL in Codebase Memory MCP

Set the CBM_LOGLEVEL environment variable to error, warn, info, debug, or trace to control verbosity, or use the --loglevel flag or .cbmconfig file for project-specific defaults.

Codebase Memory MCP (CBM) provides flexible logging configuration through the CBM_LOGLEVEL environment variable, allowing developers to adjust output verbosity from silent error-only mode to detailed trace logs. According to the source in docs/CONFIGURATION.md, this variable is read during process startup and affects both the Go runtime wrapper and native C components. Whether you are debugging a failed indexing operation or silencing verbose output in production, configuring CBM_LOGLEVEL is the primary mechanism for log control.

Understanding CBM_LOGLEVEL Values

CBM_LOGLEVEL accepts standard severity levels that map to internal log filters in both the Go and C codebases. The variable is case-insensitive and defaults to info if unset or unrecognized.

The supported values are:

  • error – Only fatal errors and unrecoverable failures
  • warn – Warnings and all error-level messages
  • info – General operational messages (default)
  • debug – Detailed debugging information for development
  • trace – Maximum verbosity, including low-level internal traces

Configuration Methods

CBM supports three configuration mechanisms, processed in the following order: environment variables, .cbmconfig file, then command-line flags.

Environment Variable Configuration

Set the variable in your shell before launching CBM:

export CBM_LOGLEVEL=debug
codebase-memory-mcp run

For permanent user-level configuration, add the export to your shell profile:

echo 'export CBM_LOGLEVEL=info' >> ~/.bashrc
source ~/.bashrc

Project-Level Configuration with .cbmconfig

Place a .cbmconfig file in the repository root to set project-specific defaults. As documented in docs/CONFIGURATION.md, the configuration uses TOML-style syntax:

CBM_LOGLEVEL = "warn"

CBM reads this file after processing environment variables, allowing the config file to override system defaults but not command-line flags.

Command-Line Flag Override

Pass the --loglevel flag directly to override other settings:

codebase-memory-mcp --loglevel=trace analyze ./src

The flag parser in pkg/go/cmd/codebase-memory-mcp/main.go processes this value identically to the environment variable, ensuring consistent behavior across configuration methods.

Initialization and Propagation

The logging subsystem initializes early in the application lifecycle. In pkg/go/cmd/codebase-memory-mcp/main.go, the process calls os.Getenv("CBM_LOGLEVEL") immediately after startup to determine the desired verbosity level.

This value propagates through the entire application stack:

  1. Go runtime – Configures the structured logger instance used by the MCP server
  2. Native components – Passed to internal/cbm/log.c, which implements low-level logging routines used by the storage and indexing components declared in internal/cbm/log.h
  3. Child processes – When CBM spawns auxiliary binaries (such as language servers or indexers), it explicitly exports CBM_LOGLEVEL to ensure consistent logging across the process tree

Because initialization occurs before heavy processing begins, you must restart CBM after changing the log level for changes to take effect.

Summary

  • Primary control: Set CBM_LOGLEVEL environment variable to error, warn, info, debug, or trace
  • Configuration hierarchy: Environment variables → .cbmconfig file → command-line flags (--loglevel)
  • Initialization: Parsed immediately in main.go before heavy operations begin
  • Propagation: Automatically inherited by child processes and native C components
  • Default: Falls back to info if undefined or invalid

Frequently Asked Questions

What is the difference between CBM_LOGLEVEL and --loglevel?

There is no functional difference in behavior. CBM_LOGLEVEL is the environment variable name, while --loglevel is the command-line flag equivalent. The flag is parsed by the same routine in pkg/go/cmd/codebase-memory-mcp/main.go and accepts the same values. Use the environment variable for persistent configuration and the flag for one-off debugging sessions.

Does CBM_LOGLEVEL affect third-party language servers?

Yes. When CBM spawns language server processes as part of its indexing pipeline, it propagates the CBM_LOGLEVEL environment variable to those child processes. This ensures consistent verbosity across the entire toolchain, though individual language servers may interpret the value differently if they do not support the same level names.

Why is my CBM_LOGLEVEL setting being ignored?

Settings can be ignored if the variable is set after the process starts, contains a typo (e.g., CBM_LOG_LEVEL with an underscore), or is overridden by a .cbmconfig file in the repository root. CBM reads configuration in the order: environment variables, then .cbmconfig, then command-line flags. Check that you are using the exact variable name CBM_LOGLEVEL (no underscore) and that you have restarted the process after making changes.

Can I set different log levels for different components of CBM?

Currently, CBM_LOGLEVEL sets a global filter for the entire application. The logging implementation in internal/cbm/log.c applies a single threshold across all modules. For component-specific debugging, you must run those components separately with different environment variables or use the trace level and filter output externally.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →