Skip to content

Commit

Permalink
Fully adopt OTel severity system (open-telemetry#228)
Browse files Browse the repository at this point in the history
* Allow otel log levels to be used as keys in a severity mapping

* Updated severity docs to reflect newly allowed mapping keys

* Only support OTel severity levels

* Update severity docs. Remove support for int levels
  • Loading branch information
djaglowski authored Jul 27, 2021
1 parent 038b640 commit 87e9ee2
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 588 deletions.
184 changes: 85 additions & 99 deletions docs/types/severity.md

Large diffs are not rendered by default.

188 changes: 68 additions & 120 deletions entry/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,131 +21,79 @@ import (
// Severity indicates the seriousness of a log entry
type Severity int

var namedLevels = map[Severity]string{
Default: "default",
Trace: "trace",
Trace2: "trace2",
Trace3: "trace3",
Trace4: "trace4",
Debug: "debug",
Debug2: "debug2",
Debug3: "debug3",
Debug4: "debug4",
Info: "info",
Info2: "info2",
Info3: "info3",
Info4: "info4",
Notice: "notice",
Warning: "warning",
Warning2: "warning2",
Warning3: "warning3",
Warning4: "warning4",
Error: "error",
Error2: "error2",
Error3: "error3",
Error4: "error4",
Critical: "critical",
Alert: "alert",
Emergency: "emergency",
Emergency2: "emergency2",
Emergency3: "emergency3",
Emergency4: "emergency4",
Catastrophe: "catastrophe",
const (
// Default indicates an unknown severity
Default Severity = iota

// A fine-grained debugging event. Typically disabled in default configurations.
Trace
Trace2
Trace3
Trace4

// A debugging event.
Debug
Debug2
Debug3
Debug4

// An informational event. Indicates that an event happened.
Info
Info2
Info3
Info4

// A warning event. Not an error but is likely more important than an informational event.
Warn
Warn2
Warn3
Warn4

// An error event. Something went wrong.
Error
Error2
Error3
Error4

// An error event. Something went wrong.
Fatal
Fatal2
Fatal3
Fatal4
)

var sevText = map[Severity]string{
Default: "default",
Trace: "trace",
Trace2: "trace2",
Trace3: "trace3",
Trace4: "trace4",
Debug: "debug",
Debug2: "debug2",
Debug3: "debug3",
Debug4: "debug4",
Info: "info",
Info2: "info2",
Info3: "info3",
Info4: "info4",
Warn: "warn",
Warn2: "warn2",
Warn3: "warn3",
Warn4: "warn4",
Error: "error",
Error2: "error2",
Error3: "error3",
Error4: "error4",
Fatal: "fatal",
Fatal2: "fatal2",
Fatal3: "fatal3",
Fatal4: "fatal4",
}

// ToString converts a severity to a string
func (s Severity) String() string {
if str, ok := namedLevels[s]; ok {
if str, ok := sevText[s]; ok {
return str
}
return strconv.Itoa(int(s))
}

const (
// Default indicates an unknown severity
Default Severity = 0

// Trace indicates that the log may be useful for detailed debugging
Trace Severity = 10

// Trace2 indicates that the log may be useful for detailed debugging
Trace2 Severity = 12

// Trace3 indicates that the log may be useful for detailed debugging
Trace3 Severity = 13

// Trace4 indicates that the log may be useful for detailed debugging
Trace4 Severity = 14

// Debug indicates that the log may be useful for debugging purposes
Debug Severity = 20

// Debug2 indicates that the log may be useful for debugging purposes
Debug2 Severity = 22

// Debug3 indicates that the log may be useful for debugging purposes
Debug3 Severity = 23

// Debug4 indicates that the log may be useful for debugging purposes
Debug4 Severity = 24

// Info indicates that the log may be useful for understanding high level details about an application
Info Severity = 30

// Info2 indicates that the log may be useful for understanding high level details about an application
Info2 Severity = 32

// Info3 indicates that the log may be useful for understanding high level details about an application
Info3 Severity = 33

// Info4 indicates that the log may be useful for understanding high level details about an application
Info4 Severity = 34

// Notice indicates that the log should be noticed
Notice Severity = 40

// Warning indicates that someone should look into an issue
Warning Severity = 50

// Warning2 indicates that someone should look into an issue
Warning2 Severity = 52

// Warning3 indicates that someone should look into an issue
Warning3 Severity = 53

// Warning4 indicates that someone should look into an issue
Warning4 Severity = 54

// Error indicates that something undesirable has actually happened
Error Severity = 60

// Error2 indicates that something undesirable has actually happened
Error2 Severity = 62

// Error3 indicates that something undesirable has actually happened
Error3 Severity = 63

// Error4 indicates that something undesirable has actually happened
Error4 Severity = 64

// Critical indicates that a problem requires attention immediately
Critical Severity = 70

// Alert indicates that action must be taken immediately
Alert Severity = 80

// Emergency indicates that the application is unusable
Emergency Severity = 90

// Emergency2 indicates that the application is unusable
Emergency2 Severity = 92

// Emergency3 indicates that the application is unusable
Emergency3 Severity = 93

// Emergency4 indicates that the application is unusable
Emergency4 Severity = 94

// Catastrophe indicates that it is already too late
Catastrophe Severity = 100
)
21 changes: 8 additions & 13 deletions entry/severity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,16 @@ func TestStringer(t *testing.T) {
require.Equal(t, "info2", Info2.String())
require.Equal(t, "info3", Info3.String())
require.Equal(t, "info4", Info4.String())
require.Equal(t, "notice", Notice.String())
require.Equal(t, "warning", Warning.String())
require.Equal(t, "warning2", Warning2.String())
require.Equal(t, "warning3", Warning3.String())
require.Equal(t, "warning4", Warning4.String())
require.Equal(t, "warn", Warn.String())
require.Equal(t, "warn2", Warn2.String())
require.Equal(t, "warn3", Warn3.String())
require.Equal(t, "warn4", Warn4.String())
require.Equal(t, "error", Error.String())
require.Equal(t, "error2", Error2.String())
require.Equal(t, "error3", Error3.String())
require.Equal(t, "error4", Error4.String())
require.Equal(t, "critical", Critical.String())
require.Equal(t, "alert", Alert.String())
require.Equal(t, "emergency", Emergency.String())
require.Equal(t, "emergency2", Emergency2.String())
require.Equal(t, "emergency3", Emergency3.String())
require.Equal(t, "emergency4", Emergency4.String())
require.Equal(t, "catastrophe", Catastrophe.String())
require.Equal(t, "19", Severity(19).String())
require.Equal(t, "fatal", Fatal.String())
require.Equal(t, "fatal2", Fatal2.String())
require.Equal(t, "fatal3", Fatal3.String())
require.Equal(t, "fatal4", Fatal4.String())
}
6 changes: 3 additions & 3 deletions logger/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func parseSeverity(zapEntry zapcore.Entry) entry.Severity {
case zapcore.InfoLevel:
return entry.Info
case zapcore.WarnLevel:
return entry.Warning
return entry.Warn
case zapcore.ErrorLevel:
return entry.Error
case zapcore.PanicLevel:
return entry.Critical
return entry.Error4
case zapcore.FatalLevel:
return entry.Catastrophe
return entry.Fatal
default:
return entry.Default
}
Expand Down
4 changes: 2 additions & 2 deletions operator/builtin/input/windows/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func (e *EventXML) parseTimestamp() time.Time {
func (e *EventXML) parseSeverity() entry.Severity {
switch e.Level {
case "Critical":
return entry.Critical
return entry.Fatal
case "Error":
return entry.Error
case "Warning":
return entry.Warning
return entry.Warn
case "Information":
return entry.Info
default:
Expand Down
4 changes: 2 additions & 2 deletions operator/builtin/input/windows/xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func TestParseSeverity(t *testing.T) {
xmlWarning := EventXML{Level: "Warning"}
xmlInformation := EventXML{Level: "Information"}
xmlUnknown := EventXML{Level: "Unknown"}
require.Equal(t, entry.Critical, xmlCritical.parseSeverity())
require.Equal(t, entry.Fatal, xmlCritical.parseSeverity())
require.Equal(t, entry.Error, xmlError.parseSeverity())
require.Equal(t, entry.Warning, xmlWarning.parseSeverity())
require.Equal(t, entry.Warn, xmlWarning.parseSeverity())
require.Equal(t, entry.Info, xmlInformation.parseSeverity())
require.Equal(t, entry.Default, xmlUnknown.parseSeverity())
}
Expand Down
Loading

0 comments on commit 87e9ee2

Please sign in to comment.