windows build fix

This commit is contained in:
Snider 2025-11-09 19:13:48 +00:00
parent 6fd424f562
commit fdac15ba43
4 changed files with 220 additions and 24 deletions

View file

@ -2,28 +2,12 @@ package mining
import (
"fmt"
"log" // Import log for general logging
"log/syslog" // Import syslog
"log"
"strings"
"sync"
"time"
)
var syslogWriter *syslog.Writer
func init() {
// Initialize syslog writer globally.
// LOG_NOTICE is for normal but significant condition.
// LOG_DAEMON is for system daemons.
// "mining-service" is the tag for the log messages.
var err error
syslogWriter, err = syslog.New(syslog.LOG_NOTICE|syslog.LOG_DAEMON, "mining-service")
if err != nil {
log.Printf("Failed to connect to syslog: %v. Falling back to standard logger.", err)
// If syslog fails, syslogWriter remains nil, and we'll use standard log.
}
}
// Manager handles miner lifecycle and operations
type Manager struct {
miners map[string]Miner
@ -68,13 +52,9 @@ func (m *Manager) StartMiner(minerType string, config *Config) (Miner, error) {
m.miners[minerKey] = miner
// Log to syslog if available, otherwise use standard logger
// Log to syslog (or standard log on Windows)
logMessage := fmt.Sprintf("CryptoCurrency Miner started: %s (Binary: %s)", miner.GetName(), miner.GetBinaryPath())
if syslogWriter != nil {
syslogWriter.Notice(logMessage)
} else {
log.Println(logMessage)
}
logToSyslog(logMessage)
return miner, nil
}
@ -166,7 +146,7 @@ func (m *Manager) collectMinerStats() {
stats, err := miner.GetStats()
if err != nil {
// Log the error but don't stop the collection for other miners
fmt.Printf("Error getting stats for miner %s: %v\n", miner.GetName(), err)
log.Printf("Error getting stats for miner %s: %v\n", miner.GetName(), err)
continue
}
miner.AddHashratePoint(HashratePoint{

32
pkg/mining/syslog_unix.go Normal file
View file

@ -0,0 +1,32 @@
//go:build !windows
package mining
import (
"log"
"log/syslog"
)
var syslogWriter *syslog.Writer
func init() {
// Initialize syslog writer globally.
// LOG_NOTICE is for normal but significant condition.
// LOG_DAEMON is for system daemons.
// "mining-service" is the tag for the log messages.
var err error
syslogWriter, err = syslog.New(syslog.LOG_NOTICE|syslog.LOG_DAEMON, "mining-service")
if err != nil {
log.Printf("Failed to connect to syslog: %v. Syslog logging will be disabled.", err)
syslogWriter = nil // Ensure it's nil on failure
}
}
// logToSyslog sends a message to syslog if available, otherwise falls back to standard log.
func logToSyslog(message string) {
if syslogWriter != nil {
_ = syslogWriter.Notice(message)
} else {
log.Println(message)
}
}

View file

@ -0,0 +1,15 @@
//go:build windows
package mining
import (
"log"
)
// On Windows, syslog is not available. We'll use a dummy implementation
// that logs to the standard logger.
// logToSyslog logs a message to the standard logger, mimicking the syslog function's signature.
func logToSyslog(message string) {
log.Println(message)
}

169
ui/package-lock.json generated

File diff suppressed because it is too large Load diff