Pull request 2303: AGDNS-2505-upd-next
Squashed commit of the following: commit 586b0eb180afc22d06d673756dd916c17a173361 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Nov 12 19:58:56 2024 +0300 next: upd more commit d729aa150f7ac367255830cceca40b8880c51015 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Nov 12 16:53:15 2024 +0300 next/websvc: upd more commit 0c64e6cfc66b9212f077b2de7450586fd4d02802 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Nov 11 21:08:51 2024 +0300 next: upd more commit 05eec75222360708621c99d3eeac7c8d9f2a5080 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Nov 8 19:20:02 2024 +0300 next: upd code
This commit is contained in:
@@ -1,39 +1,39 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||
)
|
||||
|
||||
// syslogServiceName is the name of the AdGuard Home service used for writing
|
||||
// logs to the system log.
|
||||
const syslogServiceName = "AdGuardHome"
|
||||
|
||||
// setLog sets up the text logging.
|
||||
//
|
||||
// TODO(a.garipov): Add parameters from configuration file.
|
||||
func setLog(opts *options) (err error) {
|
||||
// newBaseLogger constructs a base logger based on the command-line options.
|
||||
// opts must not be nil.
|
||||
func newBaseLogger(opts *options) (baseLogger *slog.Logger) {
|
||||
var output io.Writer
|
||||
switch opts.confFile {
|
||||
case "stdout":
|
||||
log.SetOutput(os.Stdout)
|
||||
output = os.Stdout
|
||||
case "stderr":
|
||||
log.SetOutput(os.Stderr)
|
||||
output = os.Stderr
|
||||
case "syslog":
|
||||
err = aghos.ConfigureSyslog(syslogServiceName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("initializing syslog: %w", err)
|
||||
}
|
||||
// TODO(a.garipov): Add a syslog handler to golibs.
|
||||
default:
|
||||
// TODO(a.garipov): Use the path.
|
||||
// TODO(a.garipov): Use the path.
|
||||
}
|
||||
|
||||
lvl := slog.LevelInfo
|
||||
if opts.verbose {
|
||||
log.SetLevel(log.DEBUG)
|
||||
log.Debug("verbose logging enabled")
|
||||
lvl = slog.LevelDebug
|
||||
}
|
||||
|
||||
return nil
|
||||
return slogutil.New(&slogutil.Config{
|
||||
Output: output,
|
||||
// TODO(a.garipov): Get from config?
|
||||
Format: slogutil.FormatText,
|
||||
Level: lvl,
|
||||
// TODO(a.garipov): Get from config.
|
||||
AddTimestamp: true,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user