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 16 // Package severity provides definitions for klog severity (info, warning, ...) 17 package severity 18 19 import ( 20 "strings" 21 ) 22 23 // severity identifies the sort of log: info, warning etc. The binding to flag.Value 24 // is handled in klog.go 25 type Severity int32 // sync/atomic int32 26 27 // These constants identify the log levels in order of increasing severity. 28 // A message written to a high-severity log file is also written to each 29 // lower-severity log file. 30 const ( 31 InfoLog Severity = iota 32 WarningLog 33 ErrorLog 34 FatalLog 35 NumSeverity = 4 36 ) 37 38 // Char contains one shortcut letter per severity level. 39 const Char = "IWEF" 40 41 // Name contains one name per severity level. 42 var Name = []string{ 43 InfoLog: "INFO", 44 WarningLog: "WARNING", 45 ErrorLog: "ERROR", 46 FatalLog: "FATAL", 47 } 48 49 // ByName looks up a severity level by name. 50 func ByName(s string) (Severity, bool) { 51 s = strings.ToUpper(s) 52 for i, name := range Name { 53 if name == s { 54 return Severity(i), true 55 } 56 } 57 return 0, false 58 } 59