github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/protocol/otlp/log_helper.go (about) 1 // Copyright 2023 iLogtail Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package otlp 16 17 import ( 18 "strings" 19 20 "go.opentelemetry.io/collector/pdata/plog" 21 ) 22 23 // SeverityTextToSeverityNumber can convert a provided serverityText into its corresponding serverity number. 24 // It is case-insensitive and can accept the following serverityText values: 25 // Trace, Trace2, Trace3, Trace4, Debug, Debug2, Debug3, Debug4, 26 // Info, Info2, Info3, Info4, Information, Information2, Information3, Information4, 27 // Warn, Warn2, Warn3, Warn4, Warning, Warning2, Warning3, Warning4, 28 // Error, Error2, Error3, Error4, Fatal, Fatal2, Fatal3, Fatal4, and Unspecified. 29 // If the provided serverityText is not in this list, the function will return Unspecified by default. 30 func SeverityTextToSeverityNumber(severityText string) plog.SeverityNumber { 31 severity := strings.ToLower(severityText) 32 33 // using switch is a little faster than using hashmap when the count of cases is about 20. 34 switch severity { 35 case "trace": 36 return plog.SeverityNumberTrace 37 case "trace2": 38 return plog.SeverityNumberTrace2 39 case "trace3": 40 return plog.SeverityNumberTrace3 41 case "trace4": 42 return plog.SeverityNumberTrace4 43 case "debug": 44 return plog.SeverityNumberDebug 45 case "debug2": 46 return plog.SeverityNumberDebug2 47 case "debug3": 48 return plog.SeverityNumberDebug3 49 case "debug4": 50 return plog.SeverityNumberDebug4 51 case "info", "information": 52 return plog.SeverityNumberInfo 53 case "info2", "information2": 54 return plog.SeverityNumberInfo2 55 case "info3", "information3": 56 return plog.SeverityNumberInfo3 57 case "info4", "information4": 58 return plog.SeverityNumberInfo4 59 case "warn", "warning": 60 return plog.SeverityNumberWarn 61 case "warn2", "warning2": 62 return plog.SeverityNumberWarn2 63 case "warn3", "warning3": 64 return plog.SeverityNumberWarn3 65 case "warn4", "warning4": 66 return plog.SeverityNumberWarn4 67 case "error": 68 return plog.SeverityNumberError 69 case "error2": 70 return plog.SeverityNumberError2 71 case "error3": 72 return plog.SeverityNumberError3 73 case "error4": 74 return plog.SeverityNumberError4 75 case "fatal": 76 return plog.SeverityNumberFatal 77 case "fatal2": 78 return plog.SeverityNumberFatal2 79 case "fatal3": 80 return plog.SeverityNumberFatal3 81 case "fatal4": 82 return plog.SeverityNumberFatal4 83 default: 84 return plog.SeverityNumberUnspecified 85 } 86 }