fork of whitequark.org/git-pages with mods for tangled

Add the ability to send logs to a syslog daemon.

miyuko fcc109c3 4d8f6d5e

Changed files
+37 -1
src
+4
README.md
··· 115 * If `SENTRY_DSN` environment variable is set, panics are reported to Sentry. 116 * If `SENTRY_DSN` and `SENTRY_LOGS=1` environment variables are set, logs are uploaded to Sentry. 117 * If `SENTRY_DSN` and `SENTRY_TRACING=1` environment variables are set, traces are uploaded to Sentry. 118 119 120 Architecture (v2)
··· 115 * If `SENTRY_DSN` environment variable is set, panics are reported to Sentry. 116 * If `SENTRY_DSN` and `SENTRY_LOGS=1` environment variables are set, logs are uploaded to Sentry. 117 * If `SENTRY_DSN` and `SENTRY_TRACING=1` environment variables are set, traces are uploaded to Sentry. 118 + * Optional syslog integration allows transmitting application logs to a syslog daemon. When present, the `SYSLOG_ADDR` environment variable enables the integration, and the variable's value is used to configure the absolute path to a Unix socket (usually located at `/dev/log` on Unix systems) or a network address of one of the following formats: 119 + * for TLS over TCP: `tcp+tls://host:port`; 120 + * for plain TCP: `tcp://host:post`; 121 + * for UDP: `udp://host:port`. 122 123 124 Architecture (v2)
+2
go.mod
··· 4 5 require ( 6 codeberg.org/git-pages/go-headers v1.1.0 7 github.com/KimMachineGun/automemlimit v0.7.5 8 github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 9 github.com/creasty/defaults v1.8.0 ··· 39 github.com/kevinburke/ssh_config v1.4.0 // indirect 40 github.com/klauspost/cpuid/v2 v2.3.0 // indirect 41 github.com/klauspost/crc32 v1.3.0 // indirect 42 github.com/minio/crc64nvme v1.1.0 // indirect 43 github.com/minio/md5-simd v1.1.2 // indirect 44 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
··· 4 5 require ( 6 codeberg.org/git-pages/go-headers v1.1.0 7 + codeberg.org/git-pages/go-slog-syslog v0.0.0-20251122140925-40467958039d 8 github.com/KimMachineGun/automemlimit v0.7.5 9 github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 10 github.com/creasty/defaults v1.8.0 ··· 40 github.com/kevinburke/ssh_config v1.4.0 // indirect 41 github.com/klauspost/cpuid/v2 v2.3.0 // indirect 42 github.com/klauspost/crc32 v1.3.0 // indirect 43 + github.com/leodido/go-syslog/v4 v4.3.0 // indirect 44 github.com/minio/crc64nvme v1.1.0 // indirect 45 github.com/minio/md5-simd v1.1.2 // indirect 46 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
+6
go.sum
··· 1 codeberg.org/git-pages/go-headers v1.1.0 h1:rk7/SOSsn+XuL7PUQZFYUaWKHEaj6K8mXmUV9rF2VxE= 2 codeberg.org/git-pages/go-headers v1.1.0/go.mod h1:N4gwH0U3YPwmuyxqH7xBA8j44fTPX+vOEP7ejJVBPts= 3 github.com/KimMachineGun/automemlimit v0.7.5 h1:RkbaC0MwhjL1ZuBKunGDjE/ggwAX43DwZrJqVwyveTk= 4 github.com/KimMachineGun/automemlimit v0.7.5/go.mod h1:QZxpHaGOQoYvFhv/r4u3U0JTC2ZcOwbSr11UZF46UBM= 5 github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= ··· 73 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 74 github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= 75 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 76 github.com/maypok86/otter/v2 v2.2.1 h1:hnGssisMFkdisYcvQ8L019zpYQcdtPse+g0ps2i7cfI= 77 github.com/maypok86/otter/v2 v2.2.1/go.mod h1:1NKY9bY+kB5jwCXBJfE59u+zAwOt6C7ni1FTlFFMqVs= 78 github.com/minio/crc64nvme v1.1.0 h1:e/tAguZ+4cw32D+IO/8GSf5UVr9y+3eJcxZI2WOO/7Q=
··· 1 codeberg.org/git-pages/go-headers v1.1.0 h1:rk7/SOSsn+XuL7PUQZFYUaWKHEaj6K8mXmUV9rF2VxE= 2 codeberg.org/git-pages/go-headers v1.1.0/go.mod h1:N4gwH0U3YPwmuyxqH7xBA8j44fTPX+vOEP7ejJVBPts= 3 + codeberg.org/git-pages/go-slog-syslog v0.0.0-20251122140501-cef0168bba20 h1:gwBA9NToHbaExklHIdOvjc4gzVJkDeffHxlsPY64NrM= 4 + codeberg.org/git-pages/go-slog-syslog v0.0.0-20251122140501-cef0168bba20/go.mod h1:8NPSXbYcVb71qqNM5cIgn1/uQgMisLbu2dVD1BNxsUw= 5 + codeberg.org/git-pages/go-slog-syslog v0.0.0-20251122140925-40467958039d h1:+U2YyXy2QX8oe1e5+UFR1PXfgIK79QWgAgM9l9FQG5o= 6 + codeberg.org/git-pages/go-slog-syslog v0.0.0-20251122140925-40467958039d/go.mod h1:8NPSXbYcVb71qqNM5cIgn1/uQgMisLbu2dVD1BNxsUw= 7 github.com/KimMachineGun/automemlimit v0.7.5 h1:RkbaC0MwhjL1ZuBKunGDjE/ggwAX43DwZrJqVwyveTk= 8 github.com/KimMachineGun/automemlimit v0.7.5/go.mod h1:QZxpHaGOQoYvFhv/r4u3U0JTC2ZcOwbSr11UZF46UBM= 9 github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= ··· 77 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 78 github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= 79 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 80 + github.com/leodido/go-syslog/v4 v4.3.0 h1:bbSpI/41bYK9iSdlYzcwvlxuLOE8yi4VTFmedtnghdA= 81 + github.com/leodido/go-syslog/v4 v4.3.0/go.mod h1:eJ8rUfDN5OS6dOkCOBYlg2a+hbAg6pJa99QXXgMrd98= 82 github.com/maypok86/otter/v2 v2.2.1 h1:hnGssisMFkdisYcvQ8L019zpYQcdtPse+g0ps2i7cfI= 83 github.com/maypok86/otter/v2 v2.2.1/go.mod h1:1NKY9bY+kB5jwCXBJfE59u+zAwOt6C7ni1FTlFFMqVs= 84 github.com/minio/crc64nvme v1.1.0 h1:e/tAguZ+4cw32D+IO/8GSf5UVr9y+3eJcxZI2WOO/7Q=
+25 -1
src/observe.go
··· 13 "runtime/debug" 14 "strconv" 15 "strings" 16 "time" 17 18 slogmulti "github.com/samber/slog-multi" 19 20 "github.com/prometheus/client_golang/prometheus" 21 "github.com/prometheus/client_golang/prometheus/promauto" ··· 41 NativeHistogramMinResetDuration: 10 * time.Minute, 42 }, []string{"method"}) 43 ) 44 45 func hasSentry() bool { 46 return os.Getenv("SENTRY_DSN") != "" ··· 83 log.Println("unknown log format", config.LogFormat) 84 } 85 86 if hasSentry() { 87 enableLogs := false 88 if value, err := strconv.ParseBool(os.Getenv("SENTRY_LOGS")); err == nil { ··· 154 } 155 156 func FiniObservability() { 157 if hasSentry() { 158 - sentry.Flush(2 * time.Second) 159 } 160 } 161 162 func ObserveError(err error) {
··· 13 "runtime/debug" 14 "strconv" 15 "strings" 16 + "sync" 17 "time" 18 19 slogmulti "github.com/samber/slog-multi" 20 + 21 + syslog "codeberg.org/git-pages/go-slog-syslog" 22 23 "github.com/prometheus/client_golang/prometheus" 24 "github.com/prometheus/client_golang/prometheus/promauto" ··· 44 NativeHistogramMinResetDuration: 10 * time.Minute, 45 }, []string{"method"}) 46 ) 47 + 48 + var syslogHandler syslog.Handler 49 50 func hasSentry() bool { 51 return os.Getenv("SENTRY_DSN") != "" ··· 88 log.Println("unknown log format", config.LogFormat) 89 } 90 91 + if syslogAddr := os.Getenv("SYSLOG_ADDR"); syslogAddr != "" { 92 + var err error 93 + syslogHandler, err = syslog.NewHandler(&syslog.HandlerOptions{ 94 + Address: syslogAddr, 95 + AppName: "git-pages", 96 + StructuredDataID: "git-pages", 97 + }) 98 + if err != nil { 99 + log.Fatalf("syslog: %v", err) 100 + } 101 + logHandlers = append(logHandlers, syslogHandler) 102 + } 103 + 104 if hasSentry() { 105 enableLogs := false 106 if value, err := strconv.ParseBool(os.Getenv("SENTRY_LOGS")); err == nil { ··· 172 } 173 174 func FiniObservability() { 175 + var wg sync.WaitGroup 176 + timeout := 2 * time.Second 177 + if syslogHandler != nil { 178 + wg.Go(func() { syslogHandler.Flush(timeout) }) 179 + } 180 if hasSentry() { 181 + wg.Go(func() { sentry.Flush(timeout) }) 182 } 183 + wg.Wait() 184 } 185 186 func ObserveError(err error) {