fixing windows loggers
This commit is contained in:
parent
ef0a4d825d
commit
3d0d420454
@ -4,12 +4,14 @@ import (
|
|||||||
`os`
|
`os`
|
||||||
`path/filepath`
|
`path/filepath`
|
||||||
`regexp`
|
`regexp`
|
||||||
|
|
||||||
|
`r00t2.io/goutils/bitmask`
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flags for logger configuration. These are used internally.
|
// Flags for logger configuration. These are used internally.
|
||||||
const (
|
const (
|
||||||
// LogUndefined indicates an undefined Logger type.
|
// LogUndefined indicates an undefined Logger type.
|
||||||
LogUndefined types.MaskBit = 1 << iota
|
LogUndefined bitmask.MaskBit = 1 << iota
|
||||||
// LogWinLogger indicates a WinLogger Logger type (Event Log).
|
// LogWinLogger indicates a WinLogger Logger type (Event Log).
|
||||||
LogWinLogger
|
LogWinLogger
|
||||||
// LogFile flags a FileLogger Logger type.
|
// LogFile flags a FileLogger Logger type.
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package logging
|
package logging
|
||||||
|
|
||||||
|
import (
|
||||||
|
`github.com/google/uuid`
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
AddDefaultLogger adds a default Logger (as would be determined by GetLogger) to a MultiLogger.
|
AddDefaultLogger adds a default Logger (as would be determined by GetLogger) to a MultiLogger.
|
||||||
|
|
||||||
@ -15,7 +19,7 @@ package logging
|
|||||||
Only the first logPaths entry that "works" will be used, later entries will be ignored.
|
Only the first logPaths entry that "works" will be used, later entries will be ignored.
|
||||||
Currently this will almost always return a WinLogger.
|
Currently this will almost always return a WinLogger.
|
||||||
*/
|
*/
|
||||||
func (m *MultiLogger) AddDefaultLogger(identifier string, eventIDs *WinEventID) (err error) {
|
func (m *MultiLogger) AddDefaultLogger(identifier string, eventIDs *WinEventID, logPaths ...string) (err error) {
|
||||||
|
|
||||||
var l Logger
|
var l Logger
|
||||||
var exists bool
|
var exists bool
|
||||||
@ -29,7 +33,12 @@ func (m *MultiLogger) AddDefaultLogger(identifier string, eventIDs *WinEventID)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if l, err = GetLogger(m.EnableDebug, m.Prefix, eventIDs, logPaths...); err != nil {
|
if logPaths != nil {
|
||||||
|
l, err = GetLogger(m.EnableDebug, m.Prefix, eventIDs, logPaths...);
|
||||||
|
} else {
|
||||||
|
l, err = GetLogger(m.EnableDebug, m.Prefix, eventIDs);
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,11 @@ package logging
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
`errors`
|
`errors`
|
||||||
|
`path`
|
||||||
`strings`
|
`strings`
|
||||||
|
|
||||||
|
`r00t2.io/goutils/bitmask`
|
||||||
|
`r00t2.io/sysutils/paths`
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2,6 +2,7 @@ package logging
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
`errors`
|
`errors`
|
||||||
|
`fmt`
|
||||||
|
|
||||||
`golang.org/x/sys/windows/svc/eventlog`
|
`golang.org/x/sys/windows/svc/eventlog`
|
||||||
)
|
)
|
||||||
@ -25,7 +26,7 @@ func (l *WinLogger) Setup() {
|
|||||||
l.eids.Notice,
|
l.eids.Notice,
|
||||||
l.eids.Warning,
|
l.eids.Warning,
|
||||||
} {
|
} {
|
||||||
if !(1 <= eid <= 1000) {
|
if !((eid <= 1000) && (1 <= eid)) {
|
||||||
err = errors.New("event IDs must be between 1 and 1000 inclusive")
|
err = errors.New("event IDs must be between 1 and 1000 inclusive")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -197,7 +198,7 @@ func (l *WinLogger) Err(s string, v ...interface{}) (err error) {
|
|||||||
msg = s
|
msg = s
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.elog.Error(l.eids.Error, msg)
|
err = l.elog.Error(l.eids.Err, msg)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user