Skip to content

Commit 3f786d7

Browse files
committed
Merge branch 'RA-8279_improve_application_visibility_timing_logs' into RA-8661_apply_updates_from_google
2 parents f2562ce + ff55056 commit 3f786d7

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ cockroach-data/
2626
server/.DS_Store
2727
.DS_Store
2828
cmd/trillian_log_server/trillian_log_server
29+
**/Dockerfile.local

cmd/trillian_log_server/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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()

config/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

config/config_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)