Skip to content

Commit 3c0e9c3

Browse files
fix(plex): Fixed debug log level
1 parent ad6d4eb commit 3c0e9c3

File tree

7 files changed

+564
-6
lines changed

7 files changed

+564
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ bin/
2828
tmp/
2929

3030
# binary name
31-
prometheus-plex-exporter
31+
prometheus-plex-exporter
32+
test-build

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ linters:
1616
- gosec
1717
- gocritic
1818
- gocyclo
19+

.pre-commit-config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ repos:
33
hooks:
44
- id: gofmt
55
name: gofmt
6-
# Format each passed Go file and re-stage it if it's not ignored.
7-
entry: bash -c 'for f; do [ -e "$f" ] || continue; gofmt -s -w "$f"; if ! git check-ignore -q -- "$f"; then git add -- "$f"; fi; done' --
6+
entry: gofmt -s -w
87
language: system
9-
pass_filenames: true
108
types: [go]
119
files: '\.go$'
1210

cmd/prometheus-plex-exporter/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ const (
2323
)
2424

2525
var (
26-
logger = createLogger()
26+
// logger is intentionally not initialized at package level to avoid timing issues.
27+
// In containerized environments, environment variables (especially from .env files)
28+
// may not be available during package initialization, but are guaranteed to be
29+
// available when main() executes. We initialize this in main() to ensure
30+
// LOG_LEVEL and other env vars are properly read for logger configuration.
31+
logger log.Logger
2732
)
2833

2934
// createLogger creates the appropriate logger based on environment
@@ -50,6 +55,12 @@ func maskToken(t string) string {
5055
}
5156

5257
func main() {
58+
// CRITICAL: Initialize logger first to ensure environment variables are fully loaded.
59+
// This fixes a timing issue where package-level logger initialization occurs before
60+
// container environment variables (including .env files) are available, causing
61+
// LOG_LEVEL=debug and similar settings to be ignored.
62+
logger = createLogger()
63+
5364
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
5465

5566
serverAddress := os.Getenv("PLEX_SERVER")

0 commit comments

Comments
 (0)