mirror of
https://github.com/wneessen/logranger.git
synced 2024-11-27 15:15:07 +01:00
Winni Neessen
80e30c6bda
The changes involved refactor and clean-up of variable names. This encompasses making the names more descriptive and meaningful to enhance the readability of the code. Accuracy of variable names in conveying their usage and purpose has been greatly improved. The changes span across multiple files, touching crucial components like the server, rulesets, connection, and configuration handling.
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package main
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"syscall"
|
|
|
|
"github.com/wneessen/logranger"
|
|
)
|
|
|
|
const (
|
|
// LogErrKey is the keyword used in slog for error messages
|
|
LogErrKey = "error"
|
|
)
|
|
|
|
func main() {
|
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)).With(slog.String("context", "logranger"))
|
|
confPath := "logranger.toml"
|
|
confPathEnv := os.Getenv("LOGRANGER_CONFIG")
|
|
if confPathEnv != "" {
|
|
confPath = confPathEnv
|
|
}
|
|
|
|
path := filepath.Dir(confPath)
|
|
file := filepath.Base(confPath)
|
|
config, err := logranger.NewConfig(path, file)
|
|
if err != nil {
|
|
logger.Error("failed to read/parse config", LogErrKey, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
server, err := logranger.New(config)
|
|
if err != nil {
|
|
logger.Error("failed to create new server", LogErrKey, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
go func() {
|
|
if err = server.Run(); err != nil {
|
|
logger.Error("failed to start logranger", LogErrKey, err)
|
|
os.Exit(1)
|
|
}
|
|
}()
|
|
|
|
signalChan := make(chan os.Signal, 1)
|
|
signal.Notify(signalChan)
|
|
for recvSig := range signalChan {
|
|
if recvSig == syscall.SIGKILL || recvSig == syscall.SIGABRT || recvSig == syscall.SIGINT || recvSig == syscall.SIGTERM {
|
|
logger.Warn("received signal. shutting down server", slog.String("signal", recvSig.String()))
|
|
// server.Stop()
|
|
logger.Info("server gracefully shut down")
|
|
os.Exit(0)
|
|
}
|
|
if recvSig == syscall.SIGHUP {
|
|
logger.Info(`received signal`,
|
|
slog.String("signal", "SIGHUP"),
|
|
slog.String("action", "reloading config/ruleset"))
|
|
if err = server.ReloadConfig(path, file); err != nil {
|
|
logger.Error("failed to reload config", LogErrKey, err)
|
|
}
|
|
}
|
|
}
|
|
}
|