-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Drew O'Meara
committed
Jan 4, 2025
1 parent
dd575b6
commit 90f71fe
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package log | ||
|
||
import ( | ||
"github.com/brynbellomy/klog" | ||
) | ||
|
||
type Severity byte | ||
|
||
const ( | ||
Severity_Debug Severity = 0 | ||
Severity_Info Severity = 1 | ||
Severity_Warning Severity = 2 | ||
Severity_Error Severity = 3 | ||
Severity_Fatal Severity = 4 | ||
) | ||
|
||
var ( | ||
SeverityNames = []string{ | ||
"DEBUG", | ||
"INFO", | ||
"WARNING", | ||
"ERROR", | ||
"FATAL", | ||
} | ||
) | ||
|
||
type Target interface { | ||
Write(severity Severity, level int, buf []byte) error | ||
} | ||
|
||
func SetOutputBySeverity(target Target, severity ...Severity) { | ||
for _, si := range severity { | ||
redirect := &redirect{ | ||
sev: si, | ||
dst: target, | ||
} | ||
klog.SetOutputBySeverity(SeverityNames[si], redirect) | ||
} | ||
} | ||
|
||
func RedirectTo(severity ...string) { | ||
|
||
} | ||
|
||
type redirect struct { | ||
sev Severity | ||
dst Target | ||
} | ||
|
||
func (r *redirect) Write(p []byte) (n int, err error) { | ||
n = len(p) | ||
return n, r.dst.Write(r.sev, 0, p) | ||
} |