mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Defines a `winsvc.Event` type which can be sent using the `winsvc.SendEvent` function. If nomad is running on Windows and can send to the Windows Eventlog the event will be sent. Initial event types are defined for starting, ready, stopped, and log message. The `winsvc.EventLogger` provides an `io.WriteCloser` that can be included in the logger's writers collection. It will extract the log level from log lines and write them appropriately to the eventlog. The eventlog only supports error, warning, and info levels so messages with other levels will be ignored. A new configuration block is included for enabling logging to the eventlog. Logging must be enabled with the `log_level` option and the `eventlog.level` value can then be of the same or higher severity.
27 lines
509 B
Go
27 lines
509 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package winsvc
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
"github.com/hashicorp/nomad/helper"
|
|
)
|
|
|
|
var chanEvents = make(chan Event)
|
|
|
|
// SendEvent sends an event to the Windows eventlog
|
|
func SendEvent(e Event) {
|
|
timer, stop := helper.NewSafeTimer(100 * time.Millisecond)
|
|
defer stop()
|
|
|
|
select {
|
|
case chanEvents <- e:
|
|
case <-timer.C:
|
|
hclog.L().Error("failed to send event to windows eventlog, timed out",
|
|
"event", e)
|
|
}
|
|
}
|