[service] Move logging to the core, remove pkg level logs
This commit is contained in:
@@ -8,12 +8,17 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/safing/jess"
|
||||
"github.com/safing/portmaster/base/log"
|
||||
)
|
||||
|
||||
type ServiceConfig struct {
|
||||
BinDir string
|
||||
DataDir string
|
||||
|
||||
LogToStdout bool
|
||||
LogDir string
|
||||
LogLevel string
|
||||
|
||||
BinariesIndexURLs []string
|
||||
IntelIndexURLs []string
|
||||
VerifyBinaryUpdates jess.TrustStore
|
||||
@@ -21,9 +26,10 @@ type ServiceConfig struct {
|
||||
}
|
||||
|
||||
func (sc *ServiceConfig) Init() error {
|
||||
// Check directories
|
||||
// Check directories.
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
// Fall back to defaults.
|
||||
if sc.BinDir == "" {
|
||||
exeDir, err := getCurrentBinaryFolder() // Default: C:/Program Files/Portmaster
|
||||
if err != nil {
|
||||
@@ -34,6 +40,9 @@ func (sc *ServiceConfig) Init() error {
|
||||
if sc.DataDir == "" {
|
||||
sc.DataDir = filepath.FromSlash("$ProgramData/Portmaster")
|
||||
}
|
||||
if sc.LogDir == "" {
|
||||
sc.LogDir = filepath.Join(sc.DataDir, "logs")
|
||||
}
|
||||
|
||||
case "linux":
|
||||
// Fall back to defaults.
|
||||
@@ -43,6 +52,9 @@ func (sc *ServiceConfig) Init() error {
|
||||
if sc.DataDir == "" {
|
||||
sc.DataDir = "/var/lib/portmaster"
|
||||
}
|
||||
if sc.LogDir == "" {
|
||||
sc.LogDir = "/var/log/portmaster"
|
||||
}
|
||||
|
||||
default:
|
||||
// Fail if not configured on other platforms.
|
||||
@@ -52,11 +64,15 @@ func (sc *ServiceConfig) Init() error {
|
||||
if sc.DataDir == "" {
|
||||
return errors.New("binary directory must be configured - auto-detection not supported on this platform")
|
||||
}
|
||||
if !sc.LogToStdout && sc.LogDir == "" {
|
||||
return errors.New("logging directory must be configured - auto-detection not supported on this platform")
|
||||
}
|
||||
}
|
||||
|
||||
// Expand path variables.
|
||||
sc.BinDir = os.ExpandEnv(sc.BinDir)
|
||||
sc.DataDir = os.ExpandEnv(sc.DataDir)
|
||||
sc.LogDir = os.ExpandEnv(sc.LogDir)
|
||||
|
||||
// Apply defaults for required fields.
|
||||
if len(sc.BinariesIndexURLs) == 0 {
|
||||
@@ -67,6 +83,11 @@ func (sc *ServiceConfig) Init() error {
|
||||
sc.IntelIndexURLs = DefaultIntelIndexURLs
|
||||
}
|
||||
|
||||
// Check log level.
|
||||
if sc.LogLevel != "" && log.ParseLevel(sc.LogLevel) == 0 {
|
||||
return fmt.Errorf("invalid log level %q", sc.LogLevel)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user