| 1 | package logrscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src go1.23.3 errors/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.23.3 strings/" |
| 6 | ) |
| 7 | |
| 8 | type Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# string |
| 9 | |
| 10 | const ( |
| 11 | LevelDebugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelDebug. Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# = "DEBUG" |
| 12 | LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo. Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# = "INFO" |
| 13 | LevelWarnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelWarn. Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# = "WARN" |
| 14 | LevelErrorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelError. Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# = "ERROR" |
| 15 | LevelFatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelFatal. Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# = "FATAL" |
| 16 | ) |
| 17 | |
| 18 | var ( |
| 19 | ErrInvalidLevelStringscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/ErrInvalidLevelString. = errorsscip-go gomod github.com/golang/go/src go1.23.3 errors/.Newscip-go gomod github.com/golang/go/src go1.23.3 errors/New().("invalid level, must be one of DEBUG, INFO, WARN, ERROR or FATAL") |
| 20 | ) |
| 21 | |
| 22 | func (level Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#) Valuescip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#Value().() int { |
| 23 | switch level { |
| 24 | case LevelDebugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelDebug.: |
| 25 | return 0 |
| 26 | case LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo.: |
| 27 | return 1 |
| 28 | case LevelWarnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelWarn.: |
| 29 | return 2 |
| 30 | case LevelErrorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelError.: |
| 31 | return 3 |
| 32 | case LevelFatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelFatal.: |
| 33 | return 4 |
| 34 | default: |
| 35 | return -1 |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func (level Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#) IsValidscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#IsValid().() bool { |
| 40 | return level.Valuescip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#Value().() != -1 |
| 41 | } |
| 42 | |
| 43 | func LevelFromStringscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelFromString().(level string) (Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#, error) { |
| 44 | switch stringsscip-go gomod github.com/golang/go/src go1.23.3 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.23.3 strings/ToUpper().(level) { |
| 45 | case "DEBUG": |
| 46 | return LevelDebugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelDebug., nil |
| 47 | case "INFO": |
| 48 | return LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo., nil |
| 49 | case "WARN": |
| 50 | return LevelWarnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelWarn., nil |
| 51 | case "ERROR": |
| 52 | return LevelErrorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelError., nil |
| 53 | case "FATAL": |
| 54 | return LevelFatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelFatal., nil |
| 55 | default: |
| 56 | return LevelDebugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelDebug., ErrInvalidLevelStringscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/ErrInvalidLevelString. |
| 57 | } |
| 58 | } |