fixing windows loggers

This commit is contained in:
brent s. 2022-01-06 04:16:44 -05:00
parent ef0a4d825d
commit 3d0d420454
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
4 changed files with 21 additions and 5 deletions

View File

@ -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.

View File

@ -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
} }



View File

@ -2,7 +2,11 @@ package logging


import ( import (
`errors` `errors`
`path`
`strings` `strings`

`r00t2.io/goutils/bitmask`
`r00t2.io/sysutils/paths`
) )


/* /*

View File

@ -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