severity.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2013 Google Inc. All Rights Reserved.
  2. // Copyright 2022 The Kubernetes Authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // Package severity provides definitions for klog severity (info, warning, ...)
  16. package severity
  17. import (
  18. "strings"
  19. )
  20. // severity identifies the sort of log: info, warning etc. The binding to flag.Value
  21. // is handled in klog.go
  22. type Severity int32 // sync/atomic int32
  23. // These constants identify the log levels in order of increasing severity.
  24. // A message written to a high-severity log file is also written to each
  25. // lower-severity log file.
  26. const (
  27. InfoLog Severity = iota
  28. WarningLog
  29. ErrorLog
  30. FatalLog
  31. NumSeverity = 4
  32. )
  33. // Char contains one shortcut letter per severity level.
  34. const Char = "IWEF"
  35. // Name contains one name per severity level.
  36. var Name = []string{
  37. InfoLog: "INFO",
  38. WarningLog: "WARNING",
  39. ErrorLog: "ERROR",
  40. FatalLog: "FATAL",
  41. }
  42. // ByName looks up a severity level by name.
  43. func ByName(s string) (Severity, bool) {
  44. s = strings.ToUpper(s)
  45. for i, name := range Name {
  46. if name == s {
  47. return Severity(i), true
  48. }
  49. }
  50. return 0, false
  51. }