slogMessageFormat ensures that the log message starts with lowercase, and does not end with special character.
(m dsl.Matcher)
| 370 | // slogMessageFormat ensures that the log message starts with lowercase, and does not |
| 371 | // end with special character. |
| 372 | func slogMessageFormat(m dsl.Matcher) { |
| 373 | m.Import("cdr.dev/slog/v3") |
| 374 | m.Match( |
| 375 | `logger.Error($ctx, $message, $*args)`, |
| 376 | `logger.Warn($ctx, $message, $*args)`, |
| 377 | `logger.Info($ctx, $message, $*args)`, |
| 378 | `logger.Debug($ctx, $message, $*args)`, |
| 379 | |
| 380 | `$foo.logger.Error($ctx, $message, $*args)`, |
| 381 | `$foo.logger.Warn($ctx, $message, $*args)`, |
| 382 | `$foo.logger.Info($ctx, $message, $*args)`, |
| 383 | `$foo.logger.Debug($ctx, $message, $*args)`, |
| 384 | |
| 385 | `Logger.Error($ctx, $message, $*args)`, |
| 386 | `Logger.Warn($ctx, $message, $*args)`, |
| 387 | `Logger.Info($ctx, $message, $*args)`, |
| 388 | `Logger.Debug($ctx, $message, $*args)`, |
| 389 | |
| 390 | `$foo.Logger.Error($ctx, $message, $*args)`, |
| 391 | `$foo.Logger.Warn($ctx, $message, $*args)`, |
| 392 | `$foo.Logger.Info($ctx, $message, $*args)`, |
| 393 | `$foo.Logger.Debug($ctx, $message, $*args)`, |
| 394 | ). |
| 395 | Where( |
| 396 | ( |
| 397 | // It doesn't end with a special character: |
| 398 | m["message"].Text.Matches(`[.!?]"$`) || |
| 399 | // it starts with lowercase: |
| 400 | m["message"].Text.Matches(`^"[A-Z]{1}`) && |
| 401 | // but there are exceptions: |
| 402 | !m["message"].Text.Matches(`^"Prometheus`) && |
| 403 | !m["message"].Text.Matches(`^"X11`) && |
| 404 | !m["message"].Text.Matches(`^"CSP`) && |
| 405 | !m["message"].Text.Matches(`^"OIDC`))). |
| 406 | Report(`Message $message must start with lowercase, and does not end with a special characters.`) |
| 407 | } |
| 408 | |
| 409 | // slogMessageLength ensures that important log messages are meaningful, and must be at least 16 characters long. |
| 410 | func slogMessageLength(m dsl.Matcher) { |