File tree Expand file tree Collapse file tree 4 files changed +15
-8
lines changed
Expand file tree Collapse file tree 4 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,4 @@ cockroach-data/
2626server /.DS_Store
2727.DS_Store
2828cmd /trillian_log_server /trillian_log_server
29+ ** /Dockerfile.local
Original file line number Diff line number Diff line change @@ -95,7 +95,8 @@ func main() {
9595
9696 // Set up logging adapter via config logic
9797 // This can be extended to use env vars, flags, or config files
98- config .InitLogging ()
98+ shutdown := config .InitLogging ()
99+ defer shutdown ()
99100
100101 ctx , cancel := context .WithCancel (context .Background ())
101102 defer cancel ()
Original file line number Diff line number Diff line change @@ -10,11 +10,12 @@ import (
1010// InitLogging sets up the logging adapter for the project.
1111// Note: This function is fail-safe. If OpenTelemetry initialization fails,
1212// it logs an error and falls back to a no-op tracer provider to ensure the binary continues running.
13- func InitLogging () {
13+ // Returns a shutdown function that should be deferred in main().
14+ func InitLogging () func () {
1415 // Initialize OpenTelemetry with config struct
15- logging .InitOpenTelemetry (logging .TelemetryConfigFromEnv ())
16+ shutdown := logging .InitOpenTelemetry (logging .TelemetryConfigFromEnv ())
1617
17- // Example: select logger backend via config, env var, or flag
18+ // Read logger backend configuration from env vars
1819 logFormat := os .Getenv ("LOG_FORMAT" )
1920 if logFormat == "" {
2021 logFormat = "text" // Default to text for human readability if not specified
@@ -41,4 +42,6 @@ func InitLogging() {
4142 }
4243 adapter := adapters .NewLogrusAdapter (logCfg )
4344 logging .SetLoggerAdapter (adapter )
45+
46+ return shutdown
4447}
Original file line number Diff line number Diff line change @@ -30,10 +30,12 @@ func TestInitLogging(t *testing.T) {
3030 t .Setenv ("LOG_LEVEL" , tt .logLevel )
3131 }
3232
33- // Ideally we would inspect the set logger, but since the global logger
34- // is hidden/private in ctutils or hard to inspect without getters,
35- // we at least verify this doesn't panic.
36- InitLogging ()
33+ // Verify shutdown function is returned and works
34+ shutdown := InitLogging ()
35+ if shutdown == nil {
36+ t .Fatal ("InitLogging() should return non-nil shutdown function" )
37+ }
38+ defer shutdown () // Verify shutdown doesn't panic
3739
3840 // Check that a logger is set (not nil)
3941 if logging .GetLogger () == nil {
You can’t perform that action at this time.
0 commit comments