brent s
39e0a1fd43
Adding more Event Log support, and modifying the loggers so they return errors in their operational functions.
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package logging
|
|
|
|
import (
|
|
`os`
|
|
`path/filepath`
|
|
|
|
`r00t2.io/goutils/bitmask`
|
|
)
|
|
|
|
// Flags for logger configuration. These are used internally.
|
|
const (
|
|
// LogUndefined indicates an undefined Logger type.
|
|
LogUndefined bitmask.MaskBit = 1 << iota
|
|
// LogWinLogger indicates a WinLogger Logger type (Event Log).
|
|
LogWinLogger
|
|
// LogFile flags a FileLogger Logger type.
|
|
LogFile
|
|
// LogStdout flags a StdLogger Logger type.
|
|
LogStdout
|
|
)
|
|
|
|
var (
|
|
// defLogPaths indicates default log paths.
|
|
defLogPaths = []string{
|
|
filepath.Join(os.Getenv("ALLUSERSPROFILE"), "golang", "program.log"), // C:\ProgramData\log\golang\program.log
|
|
filepath.Join(os.Getenv("LOCALAPPDATA"), "log", "golang", "program.log"), // C:\Users\<username>\AppData\Local\log\golang\program.log
|
|
}
|
|
)
|
|
|
|
/*
|
|
ptrnSourceExists is a regex pattern to check for a registry entry (Event Log entry) already existing.
|
|
|
|
Deprecated: this is handled differently now.
|
|
*/
|
|
// var ptrnSourceExists *regexp.Regexp = regexp.MustCompile(`registry\skey\salready\sexists$`)
|
|
|
|
const (
|
|
EIDMin uint32 = 1
|
|
EIDMax uint32 = 1000
|
|
)
|
|
|
|
const (
|
|
eventLogRegistryKey string = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application"
|
|
)
|
|
|
|
// Default WinEventID, (can be) used in GetLogger and MultiLogger.AddWinLogger.
|
|
var DefaultEventID *WinEventID = &WinEventID{
|
|
Alert: EventAlert,
|
|
Crit: EventCrit,
|
|
Debug: EventDebug,
|
|
Emerg: EventEmerg,
|
|
Err: EventErr,
|
|
Info: EventInfo,
|
|
Notice: EventNotice,
|
|
Warning: EventWarning,
|
|
}
|
|
|
|
// Default Event IDs for WinEventID.
|
|
const (
|
|
EventAlert uint32 = 1 << iota
|
|
EventCrit
|
|
EventDebug
|
|
EventEmerg
|
|
EventErr
|
|
EventInfo
|
|
EventNotice
|
|
EventWarning
|
|
)
|