2018-01-19 19:33:25 +01:00
|
|
|
package dlog
|
|
|
|
|
|
|
|
import "golang.org/x/sys/windows/svc/eventlog"
|
|
|
|
|
|
|
|
type systemLogger struct {
|
|
|
|
inner *eventlog.Log
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSystemLogger(appName string, facility string) (*systemLogger, error) {
|
2018-01-19 20:27:48 +01:00
|
|
|
eventlog.InstallAsEventCreate(appName, eventlog.Error|eventlog.Warning|eventlog.Info)
|
2018-01-19 19:33:25 +01:00
|
|
|
var eventLogger *eventlog.Log
|
2018-01-19 20:27:48 +01:00
|
|
|
var err error
|
2018-01-19 19:33:25 +01:00
|
|
|
if eventLogger, err = eventlog.Open(appName); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &systemLogger{inner: eventLogger}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (systemLogger *systemLogger) writeString(severity Severity, message string) {
|
|
|
|
switch severity {
|
|
|
|
case SeverityError:
|
|
|
|
case SeverityCritical:
|
|
|
|
case SeverityFatal:
|
|
|
|
systemLogger.inner.Error(uint32(severity), message)
|
|
|
|
case SeverityWarning:
|
|
|
|
systemLogger.inner.Warning(uint32(severity), message)
|
|
|
|
default:
|
|
|
|
systemLogger.inner.Info(uint32(severity), message)
|
|
|
|
}
|
|
|
|
}
|