File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,11 +66,9 @@ parse_format:;
6666 return ;
6767 }
6868
69- const char * env = getenv ("ENVIRONMENT" );
70- const char * cloud_run = getenv ("K_SERVICE" );
71- if ((env && strcmp (env , "production" ) == 0 ) || (cloud_run && cloud_run [0 ] != '\0' )) {
72- cbm_log_set_format (CBM_LOG_FORMAT_JSON );
73- }
69+ /* Format is intentionally explicit-only. Logs stay local to stderr and the
70+ * optional in-process sink; deployment environment variables must not
71+ * silently change the operator-selected output shape. */
7472}
7573
7674void cbm_log_set_sink (cbm_log_sink_fn fn ) {
Original file line number Diff line number Diff line change 44 * Design:
55 * - All output goes to stderr (stdout is reserved for MCP JSON-RPC)
66 * - Structured text format: "level=info msg=pass.timing pass=defs elapsed_ms=42"
7- * - Optional JSON format for production collectors / Cloud Logging
7+ * - Optional JSON format for local structured parsing
88 * - Levels: DEBUG, INFO, WARN, ERROR
99 * - Level filtering at runtime via cbm_log_set_level() or the
1010 * CBM_LOG_LEVEL env var (see cbm_log_init_from_env)
@@ -40,9 +40,8 @@ typedef enum {
4040 * the numeric equivalents 0..4 matching CBMLogLevel. Unknown, empty, or
4141 * unset values leave the level unchanged (fail-open).
4242 *
43- * Also applies CBM_LOG_FORMAT=text|json. If unset, JSON is auto-enabled for
44- * production / Cloud Run style environments (ENVIRONMENT=production or
45- * K_SERVICE present). Call once at startup before any threads or log lines. */
43+ * Also applies CBM_LOG_FORMAT=text|json. If unset, the current format is left
44+ * unchanged. Call once at startup before any threads or log lines. */
4645void cbm_log_init_from_env (void );
4746
4847/* Set minimum log level (default: INFO). */
Original file line number Diff line number Diff line change @@ -197,6 +197,19 @@ TEST(log_format_from_env) {
197197 PASS ();
198198}
199199
200+ TEST (log_format_is_explicit_only ) {
201+ cbm_unsetenv ("CBM_LOG_FORMAT" );
202+ cbm_setenv ("ENVIRONMENT" , "production" , 1 );
203+ cbm_setenv ("K_SERVICE" , "cbm" , 1 );
204+ cbm_log_set_format (CBM_LOG_FORMAT_TEXT );
205+ cbm_log_init_from_env ();
206+ ASSERT_EQ (cbm_log_get_format (), CBM_LOG_FORMAT_TEXT );
207+
208+ cbm_unsetenv ("ENVIRONMENT" );
209+ cbm_unsetenv ("K_SERVICE" );
210+ PASS ();
211+ }
212+
200213/* CBM_LOG_LEVEL parsing — distilled from #414 (closes #413). */
201214TEST (log_level_from_env_textual ) {
202215 cbm_setenv ("CBM_LOG_LEVEL" , "error" , 1 );
@@ -281,6 +294,7 @@ SUITE(log) {
281294 RUN_TEST (log_sink_tee_keeps_stderr );
282295 RUN_TEST (log_operational_helpers );
283296 RUN_TEST (log_format_from_env );
297+ RUN_TEST (log_format_is_explicit_only );
284298 RUN_TEST (log_level_from_env_textual );
285299 RUN_TEST (log_level_from_env_numeric );
286300 RUN_TEST (log_level_from_env_invalid_ignored );
You can’t perform that action at this time.
0 commit comments