feat(logging): allow time replacement in log file name (#3330)
* feat(logging): allow time replacement in log file name This allows replacing `%d` with a date time format in the log `file_name` option. Closes #3210.pull/3487/head
parent
48ded6a507
commit
46d84e46b0
|
@ -87,6 +87,16 @@ log:
|
|||
file_path: /config/authelia.log
|
||||
```
|
||||
|
||||
If you include the value `%d` in the filename it will replace this value with a date time indicative of the time
|
||||
the logger was initialized in the following format:
|
||||
|
||||
`2006-02-01T150405Z`
|
||||
|
||||
```yaml
|
||||
log:
|
||||
file_path: /config/authelia.%d.log
|
||||
```
|
||||
|
||||
### keep_stdout
|
||||
<div markdown="1">
|
||||
type: boolean
|
||||
|
|
|
@ -3,6 +3,8 @@ package logging
|
|||
import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
logrus_stack "github.com/Gurpartap/logrus-stack"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -30,7 +32,9 @@ func InitializeLogger(config schema.LogConfiguration, log bool) error {
|
|||
}
|
||||
|
||||
if config.FilePath != "" {
|
||||
f, err := os.OpenFile(config.FilePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
filePath := strings.ReplaceAll(config.FilePath, "%d", time.Now().Format("2006-02-01T150405Z"))
|
||||
|
||||
f, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue