don't pre-create log files (not required anymore) (#2267)
The lumberjack package fixed the issue in natefinch/lumberjack#83 (tested with umask 002) and this code is now redundant since we updated the dependency to v2.2.1.
This commit is contained in:
parent
edd062522d
commit
5b3200173e
|
@ -9,9 +9,18 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/go-co-op/gocron"
|
||||||
|
"github.com/golang-jwt/jwt/v4"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
|
"gopkg.in/tomb.v2"
|
||||||
|
|
||||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||||
|
@ -22,13 +31,6 @@ import (
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/go-co-op/gocron"
|
|
||||||
"github.com/golang-jwt/jwt/v4"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
"gopkg.in/tomb.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -116,7 +118,7 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {
|
||||||
|
|
||||||
logFile := ""
|
logFile := ""
|
||||||
if config.LogMedia == "file" {
|
if config.LogMedia == "file" {
|
||||||
logFile = fmt.Sprintf("%s/crowdsec_api.log", config.LogDir)
|
logFile = filepath.Join(config.LogDir, "crowdsec_api.log")
|
||||||
}
|
}
|
||||||
|
|
||||||
if log.GetLevel() < log.DebugLevel {
|
if log.GetLevel() < log.DebugLevel {
|
||||||
|
@ -162,15 +164,7 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {
|
||||||
if config.CompressLogs != nil {
|
if config.CompressLogs != nil {
|
||||||
_compress = *config.CompressLogs
|
_compress = *config.CompressLogs
|
||||||
}
|
}
|
||||||
/*cf. https://github.com/natefinch/lumberjack/issues/82
|
|
||||||
let's create the file beforehand w/ the right perms */
|
|
||||||
// check if file exists
|
|
||||||
_, err := os.Stat(logFile)
|
|
||||||
// create file if not exists, purposefully ignore errors
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
file, _ := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE, 0600)
|
|
||||||
file.Close()
|
|
||||||
}
|
|
||||||
LogOutput := &lumberjack.Logger{
|
LogOutput := &lumberjack.Logger{
|
||||||
Filename: logFile,
|
Filename: logFile,
|
||||||
MaxSize: _maxsize, //megabytes
|
MaxSize: _maxsize, //megabytes
|
||||||
|
|
|
@ -40,19 +40,9 @@ func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level
|
||||||
if compress != nil {
|
if compress != nil {
|
||||||
_compress = *compress
|
_compress = *compress
|
||||||
}
|
}
|
||||||
/*cf. https://github.com/natefinch/lumberjack/issues/82
|
|
||||||
let's create the file beforehand w/ the right perms */
|
|
||||||
fname := cfgFolder + "/crowdsec.log"
|
|
||||||
// check if file exists
|
|
||||||
_, err := os.Stat(fname)
|
|
||||||
// create file if not exists, purposefully ignore errors
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
file, _ := os.OpenFile(fname, os.O_RDWR|os.O_CREATE, 0600)
|
|
||||||
file.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
LogOutput = &lumberjack.Logger{
|
LogOutput = &lumberjack.Logger{
|
||||||
Filename: fname,
|
Filename: filepath.Join(cfgFolder, "crowdsec.log"),
|
||||||
MaxSize: _maxsize,
|
MaxSize: _maxsize,
|
||||||
MaxBackups: _maxfiles,
|
MaxBackups: _maxfiles,
|
||||||
MaxAge: _maxage,
|
MaxAge: _maxage,
|
||||||
|
|
Loading…
Reference in a new issue