mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-21 06:37:21 +00:00
fix(logging): make level and field-name access concurrency-safe
SetFieldName wrote a package-global map with no lock while log read it from many goroutines, and the level, caller, and time-format setters mutated fields without synchronisation. A runtime setter call could crash the process with a concurrent map write. The scalar fields now use atomics on the hot log path and the global field-name map uses a read-write mutex. Behaviour for init-time configuration is unchanged.
This commit is contained in:
@@ -100,7 +100,7 @@ func (suite *LoggerTestSuite) Test_LogsLevelsPrint() {
|
||||
|
||||
// Set logger's minimum log level
|
||||
logger.SetMinLogLevel(tt.loggerMinLevel)
|
||||
fmt.Println("Logger min log level:", levelNames[logger.minLogLevel])
|
||||
fmt.Println("Logger min log level:", levelNames[logger.minLogLevel.Load()])
|
||||
|
||||
// Call the logging method
|
||||
callLoggerMethod(logger, tt.method, msg)
|
||||
@@ -138,13 +138,13 @@ func containsLogMessage(logOutput, expectedMessage string) bool {
|
||||
func (suite *LoggerTestSuite) Test_SetFormat() {
|
||||
logger := New().SetTimeFormat(time.RFC3339Nano)
|
||||
|
||||
assert.Equal(time.RFC3339Nano, logger.timeFormat)
|
||||
assert.Equal(time.RFC3339Nano, *logger.timeFormat.Load())
|
||||
}
|
||||
|
||||
func (suite *LoggerTestSuite) Test_SetMinLogLevel() {
|
||||
logger := New().SetMinLogLevel(LEVEL_DEBUG)
|
||||
|
||||
assert.Equal(LEVEL_DEBUG, logger.minLogLevel)
|
||||
assert.Equal(LEVEL_DEBUG, int(logger.minLogLevel.Load()))
|
||||
}
|
||||
|
||||
func (suite *LoggerTestSuite) Test_ShouldLog() {
|
||||
|
||||
Reference in New Issue
Block a user