authelia/internal/logging/logger.go
Clément Michaud c429488738
[FEATURE] [BREAKING] Support writing logs in a file. (#686)
* [FEATURE] Support writing logs in a file.

* Add documentation about logs file path.

* Rename logs_level and logs_file_path into log_level and log_file_path.

* Update BREAKING.md

Fixes #338

Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
2020-03-09 20:57:53 +01:00

35 lines
765 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_WRONLY|os.O_CREATE, 0600)
if err != nil {
return err
}
logrus.SetOutput(f)
}
return nil
}