mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
f392f51df6
* [MISC] Append log file instead of overwriting If Authelia is restarted when a `log_file_path` is defined upon restart the log file is overwritten as opposed to appending the existing file. This change ensures that the log file will be appended to, users will need to ensure that they rotate/truncate this over time especially if running in `debug` or `trace`. * Amend documentation for log_file_path
38 lines
781 B
Go
38 lines
781 B
Go
package logging
|
|
|
|
import (
|
|
"os"
|
|
|
|
logrus_stack "github.com/Gurpartap/logrus-stack"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Logger return the standard logrus logger.
|
|
func Logger() *logrus.Logger {
|
|
return logrus.StandardLogger()
|
|
}
|
|
|
|
// SetLevel set the level of the logger.
|
|
func SetLevel(level logrus.Level) {
|
|
logrus.SetLevel(level)
|
|
}
|
|
|
|
// InitializeLogger initialize logger.
|
|
func InitializeLogger(filename string) error {
|
|
callerLevels := []logrus.Level{}
|
|
stackLevels := []logrus.Level{logrus.PanicLevel, logrus.FatalLevel, logrus.ErrorLevel}
|
|
logrus.AddHook(logrus_stack.NewHook(callerLevels, stackLevels))
|
|
|
|
if filename != "" {
|
|
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
logrus.SetOutput(f)
|
|
}
|
|
|
|
return nil
|
|
}
|