github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekalog/level.go (about) 1 // Copyright © 2018-2021. All rights reserved. 2 // Author: Ilya Stroy. 3 // Contacts: iyuryevich@pm.me, https://github.com/qioalice 4 // License: https://opensource.org/licenses/MIT 5 6 package ekalog 7 8 type ( 9 // Level is the log message's severity level. 10 // There are 7 log levels the same as used in syslog. 11 // 12 // You can use log constants to determine 13 // which log entry will you receive in your Integrator. 14 // 15 // Keep in mind, logging using LEVEL_EMERGENCY cause calling ekadeath.Die(), 16 // after writing a log message. 17 // 18 // Read more: 19 // https://en.wikipedia.org/wiki/Syslog 20 // 21 Level uint8 22 ) 23 24 //noinspection GoSnakeCaseUsage 25 const ( 26 LEVEL_EMERGENCY Level = iota 27 LEVEL_ALERT 28 LEVEL_CRITICAL 29 LEVEL_ERROR 30 LEVEL_WARNING 31 LEVEL_NOTICE 32 LEVEL_INFO 33 LEVEL_DEBUG 34 ) 35 36 // String returns a capitalized string of the current log level. 37 // Returns an empty string if it's unexpected log level. 38 func (l Level) String() string { 39 switch l { 40 case LEVEL_EMERGENCY: 41 return "Emergency" 42 case LEVEL_ALERT: 43 return "Alert" 44 case LEVEL_CRITICAL: 45 return "Critical" 46 case LEVEL_ERROR: 47 return "Error" 48 case LEVEL_WARNING: 49 return "Warning" 50 case LEVEL_NOTICE: 51 return "Notice" 52 case LEVEL_INFO: 53 return "Info" 54 case LEVEL_DEBUG: 55 return "Debug" 56 default: 57 return "" 58 } 59 } 60 61 // String3 returns a capitalized short-hand string of the current log level. 62 // It has a length of 3 chars for all but LEVEL_EMERGENCY takes 5 for that. 63 // Returns an empty string if it's unexpected log level. 64 func (l Level) String3() string { 65 switch l { 66 case LEVEL_EMERGENCY: 67 return "Emerg" 68 case LEVEL_ALERT: 69 return "Ale" 70 case LEVEL_CRITICAL: 71 return "Cri" 72 case LEVEL_ERROR: 73 return "Err" 74 case LEVEL_WARNING: 75 return "War" 76 case LEVEL_NOTICE: 77 return "Noe" 78 case LEVEL_INFO: 79 return "Inf" 80 case LEVEL_DEBUG: 81 return "Deb" 82 default: 83 return "" 84 } 85 } 86 87 // ToUpper returns an uppercase variant of String() call. 88 func (l Level) ToUpper() string { 89 switch l { 90 case LEVEL_EMERGENCY: 91 return "EMERGENCY" 92 case LEVEL_ALERT: 93 return "ALERT" 94 case LEVEL_CRITICAL: 95 return "CRITICAL" 96 case LEVEL_ERROR: 97 return "ERROR" 98 case LEVEL_WARNING: 99 return "WARNING" 100 case LEVEL_NOTICE: 101 return "NOTICE" 102 case LEVEL_INFO: 103 return "INFO" 104 case LEVEL_DEBUG: 105 return "DEBUG" 106 default: 107 return "" 108 } 109 } 110 111 // ToLower returns a lowercase variant of String() call. 112 func (l Level) ToLower() string { 113 switch l { 114 case LEVEL_EMERGENCY: 115 return "emergency" 116 case LEVEL_ALERT: 117 return "alert" 118 case LEVEL_CRITICAL: 119 return "critical" 120 case LEVEL_ERROR: 121 return "error" 122 case LEVEL_WARNING: 123 return "warning" 124 case LEVEL_NOTICE: 125 return "notice" 126 case LEVEL_INFO: 127 return "info" 128 case LEVEL_DEBUG: 129 return "debug" 130 default: 131 return "" 132 } 133 } 134 135 // ToUpper3 returns an uppercase variant of String3() call. 136 func (l Level) ToUpper3() string { 137 switch l { 138 case LEVEL_EMERGENCY: 139 return "EMERG" 140 case LEVEL_ALERT: 141 return "ALE" 142 case LEVEL_CRITICAL: 143 return "CRI" 144 case LEVEL_ERROR: 145 return "ERR" 146 case LEVEL_WARNING: 147 return "WAR" 148 case LEVEL_NOTICE: 149 return "NOE" 150 case LEVEL_INFO: 151 return "INF" 152 case LEVEL_DEBUG: 153 return "DEB" 154 default: 155 return "" 156 } 157 } 158 159 // ToLower3 returns an uppercase variant of String3() call. 160 func (l Level) ToLower3() string { 161 switch l { 162 case LEVEL_EMERGENCY: 163 return "emerg" 164 case LEVEL_ALERT: 165 return "ale" 166 case LEVEL_CRITICAL: 167 return "cri" 168 case LEVEL_ERROR: 169 return "err" 170 case LEVEL_WARNING: 171 return "war" 172 case LEVEL_NOTICE: 173 return "noe" 174 case LEVEL_INFO: 175 return "inf" 176 case LEVEL_DEBUG: 177 return "deb" 178 default: 179 return "" 180 } 181 }