TestConsoleShouldLogWithDatabase ensures that if set, database log config takes precedence over console config.
(t *testing.T)
| 143 | |
| 144 | // TestConsoleShouldLogWithDatabase ensures that if set, database log config takes precedence over console config. |
| 145 | func TestConsoleShouldLogWithDatabase(t *testing.T) { |
| 146 | for _, test := range consoleShouldLogTests { |
| 147 | for _, dbConfig := range []struct { |
| 148 | consoleConfig *DbConsoleLogConfig |
| 149 | expected bool |
| 150 | }{ |
| 151 | { |
| 152 | consoleConfig: nil, |
| 153 | expected: test.expected, // fully inherit from console logger when dbConfig nil |
| 154 | }, |
| 155 | { |
| 156 | consoleConfig: &DbConsoleLogConfig{ |
| 157 | LogLevel: logLevelPtr(LevelNone), |
| 158 | LogKeys: logKeyMask(KeyAll), |
| 159 | }, |
| 160 | expected: false, // log nothing from db |
| 161 | }, |
| 162 | { |
| 163 | consoleConfig: &DbConsoleLogConfig{ |
| 164 | LogLevel: logLevelPtr(LevelTrace), |
| 165 | LogKeys: logKeyMask(KeyAll), |
| 166 | }, |
| 167 | expected: true, // log everything from db |
| 168 | }, |
| 169 | { |
| 170 | consoleConfig: &DbConsoleLogConfig{ |
| 171 | LogLevel: logLevelPtr(LevelInfo), |
| 172 | LogKeys: logKeyMask(KeyDCP), |
| 173 | }, |
| 174 | // log DCP only from db (overrides console key) |
| 175 | expected: test.logToKey == KeyDCP && test.logToLevel <= LevelInfo, |
| 176 | }, |
| 177 | { |
| 178 | consoleConfig: &DbConsoleLogConfig{ |
| 179 | LogLevel: logLevelPtr(LevelInfo), |
| 180 | LogKeys: logKeyMask(KeyHTTP), |
| 181 | }, |
| 182 | // Still expect the HTTP warnings when Info is set on db |
| 183 | expected: test.logToKey == KeyHTTP && test.logToLevel <= LevelInfo, |
| 184 | }, |
| 185 | } { |
| 186 | dbConfigLevel := "<nil>" |
| 187 | if dbConfig.consoleConfig != nil && dbConfig.consoleConfig.LogLevel != nil { |
| 188 | dbConfigLevel = dbConfig.consoleConfig.LogLevel.StringShort() |
| 189 | } |
| 190 | dbConfigKeys := "<nil>" |
| 191 | if dbConfig.consoleConfig != nil && dbConfig.consoleConfig.LogKeys != nil { |
| 192 | dbConfigKeys = dbConfig.consoleConfig.LogKeys.String() |
| 193 | } |
| 194 | |
| 195 | name := fmt.Sprintf("logger{%s,%s}.shouldLog(dbConfig(%s,%s), %s,%s)", |
| 196 | test.loggerLevel.StringShort(), test.loggerKeys, |
| 197 | dbConfigLevel, dbConfigKeys, |
| 198 | test.logToLevel.StringShort(), test.logToKey) |
| 199 | |
| 200 | level := test.loggerLevel |
| 201 | l := mustInitConsoleLogger(TestCtx(t), &ConsoleLoggerConfig{ |
| 202 | LogLevel: &level, |
nothing calls this directly
no test coverage detected