mirror of https://github.com/jetkvm/kvm.git
chore(log): add wolLogger
This commit is contained in:
parent
6489421605
commit
924b55059f
14
log.go
14
log.go
|
@ -55,11 +55,25 @@ var (
|
||||||
serialLogger = getLogger("serial")
|
serialLogger = getLogger("serial")
|
||||||
terminalLogger = getLogger("terminal")
|
terminalLogger = getLogger("terminal")
|
||||||
displayLogger = getLogger("display")
|
displayLogger = getLogger("display")
|
||||||
|
wolLogger = getLogger("wol")
|
||||||
usbLogger = getLogger("usb")
|
usbLogger = getLogger("usb")
|
||||||
// external components
|
// external components
|
||||||
ginLogger = getLogger("gin")
|
ginLogger = getLogger("gin")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func ErrorfL(l *zerolog.Logger, format string, err error, args ...interface{}) error {
|
||||||
|
if l == nil {
|
||||||
|
l = &logger
|
||||||
|
}
|
||||||
|
|
||||||
|
l.Error().Err(err).Msgf(format, args...)
|
||||||
|
|
||||||
|
err_msg := err.Error() + ": %v"
|
||||||
|
err_args := append(args, err)
|
||||||
|
|
||||||
|
return fmt.Errorf(err_msg, err_args...)
|
||||||
|
}
|
||||||
|
|
||||||
func updateLogLevel() {
|
func updateLogLevel() {
|
||||||
scopeLevelMutex.Lock()
|
scopeLevelMutex.Lock()
|
||||||
defer scopeLevelMutex.Unlock()
|
defer scopeLevelMutex.Unlock()
|
||||||
|
|
9
wol.go
9
wol.go
|
@ -3,7 +3,6 @@ package kvm
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +11,7 @@ func rpcSendWOLMagicPacket(macAddress string) error {
|
||||||
// Parse the MAC address
|
// Parse the MAC address
|
||||||
mac, err := net.ParseMAC(macAddress)
|
mac, err := net.ParseMAC(macAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid MAC address: %v", err)
|
return ErrorfL(&wolLogger, "invalid MAC address", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the magic packet
|
// Create the magic packet
|
||||||
|
@ -21,16 +20,18 @@ func rpcSendWOLMagicPacket(macAddress string) error {
|
||||||
// Set up UDP connection
|
// Set up UDP connection
|
||||||
conn, err := net.Dial("udp", "255.255.255.255:9")
|
conn, err := net.Dial("udp", "255.255.255.255:9")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to establish UDP connection: %v", err)
|
return ErrorfL(&wolLogger, "failed to establish UDP connection", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// Send the packet
|
// Send the packet
|
||||||
_, err = conn.Write(packet)
|
_, err = conn.Write(packet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to send WOL packet: %v", err)
|
return ErrorfL(&wolLogger, "failed to send WOL packet", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wolLogger.Info().Str("mac", macAddress).Msg("WOL packet sent")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue