chore(log): add wolLogger

This commit is contained in:
Siyuan Miao
2025-04-11 08:14:44 +02:00
parent 6489421605
commit 924b55059f
2 changed files with 19 additions and 4 deletions

9
wol.go
View File

@@ -3,7 +3,6 @@ package kvm
import (
"bytes"
"encoding/binary"
"fmt"
"net"
)
@@ -12,7 +11,7 @@ func rpcSendWOLMagicPacket(macAddress string) error {
// Parse the MAC address
mac, err := net.ParseMAC(macAddress)
if err != nil {
return fmt.Errorf("invalid MAC address: %v", err)
return ErrorfL(&wolLogger, "invalid MAC address", err)
}
// Create the magic packet
@@ -21,16 +20,18 @@ func rpcSendWOLMagicPacket(macAddress string) error {
// Set up UDP connection
conn, err := net.Dial("udp", "255.255.255.255:9")
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()
// Send the packet
_, err = conn.Write(packet)
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
}