2021-12-15 04:49:03 -05:00
|
|
|
package logging
|
|
|
|
|
|
|
|
import (
|
|
|
|
`os`
|
|
|
|
`path/filepath`
|
2022-01-06 04:16:44 -05:00
|
|
|
|
|
|
|
`r00t2.io/goutils/bitmask`
|
2021-12-15 04:49:03 -05:00
|
|
|
)
|
|
|
|
|
2022-01-05 05:15:38 -05:00
|
|
|
// Flags for logger configuration. These are used internally.
|
2021-12-15 04:49:03 -05:00
|
|
|
const (
|
2022-01-05 05:15:38 -05:00
|
|
|
// LogUndefined indicates an undefined Logger type.
|
2022-01-06 04:16:44 -05:00
|
|
|
LogUndefined bitmask.MaskBit = 1 << iota
|
2022-01-05 05:15:38 -05:00
|
|
|
// LogWinLogger indicates a WinLogger Logger type (Event Log).
|
2021-12-15 04:49:03 -05:00
|
|
|
LogWinLogger
|
2022-01-05 05:15:38 -05:00
|
|
|
// LogFile flags a FileLogger Logger type.
|
2021-12-15 04:49:03 -05:00
|
|
|
LogFile
|
2022-01-05 05:15:38 -05:00
|
|
|
// LogStdout flags a StdLogger Logger type.
|
2021-12-15 04:49:03 -05:00
|
|
|
LogStdout
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-01-05 05:15:38 -05:00
|
|
|
// defLogPaths indicates default log paths.
|
2021-12-15 04:49:03 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-01-16 02:05:42 -05:00
|
|
|
/*
|
|
|
|
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"
|
|
|
|
)
|
2021-12-15 04:49:03 -05:00
|
|
|
|
2022-01-05 05:15:38 -05:00
|
|
|
// Default WinEventID, (can be) used in GetLogger and MultiLogger.AddWinLogger.
|
2021-12-15 04:49:03 -05:00
|
|
|
var DefaultEventID *WinEventID = &WinEventID{
|
|
|
|
Alert: EventAlert,
|
|
|
|
Crit: EventCrit,
|
|
|
|
Debug: EventDebug,
|
|
|
|
Emerg: EventEmerg,
|
|
|
|
Err: EventErr,
|
|
|
|
Info: EventInfo,
|
|
|
|
Notice: EventNotice,
|
|
|
|
Warning: EventWarning,
|
|
|
|
}
|
|
|
|
|
2022-01-16 06:55:29 -05:00
|
|
|
// Default Event IDs for WinEventID (DefaultEventID, specifically).
|
2021-12-15 04:49:03 -05:00
|
|
|
const (
|
|
|
|
EventAlert uint32 = 1 << iota
|
|
|
|
EventCrit
|
|
|
|
EventDebug
|
|
|
|
EventEmerg
|
|
|
|
EventErr
|
|
|
|
EventInfo
|
|
|
|
EventNotice
|
|
|
|
EventWarning
|
|
|
|
)
|