@@ -18,6 +18,8 @@ import (
1818 "github.com/mxpv/podsync/pkg/db"
1919 "github.com/mxpv/podsync/pkg/fs"
2020 "github.com/mxpv/podsync/pkg/ytdl"
21+
22+ "gopkg.in/natefinch/lumberjack.v2"
2123)
2224
2325type Opts struct {
@@ -72,6 +74,23 @@ func main() {
7274 log .Info (banner )
7375 }
7476
77+ // Load TOML file
78+ log .Debugf ("loading configuration %q" , opts .ConfigPath )
79+ cfg , err := config .LoadConfig (opts .ConfigPath )
80+ if err != nil {
81+ log .WithError (err ).Fatal ("failed to load configuration file" )
82+ }
83+
84+ if cfg .Log .Filename != "" {
85+ log .SetOutput (& lumberjack.Logger {
86+ Filename : cfg .Log .Filename ,
87+ MaxSize : cfg .Log .MaxSize ,
88+ MaxBackups : cfg .Log .MaxBackups ,
89+ MaxAge : cfg .Log .MaxAge ,
90+ Compress : cfg .Log .Compress ,
91+ })
92+ }
93+
7594 log .WithFields (log.Fields {
7695 "version" : version ,
7796 "commit" : commit ,
@@ -83,13 +102,6 @@ func main() {
83102 log .WithError (err ).Fatal ("youtube-dl error" )
84103 }
85104
86- // Load TOML file
87- log .Debugf ("loading configuration %q" , opts .ConfigPath )
88- cfg , err := config .LoadConfig (opts .ConfigPath )
89- if err != nil {
90- log .WithError (err ).Fatal ("failed to load configuration file" )
91- }
92-
93105 database , err := db .NewBadger (& cfg .Database )
94106 if err != nil {
95107 log .WithError (err ).Fatal ("failed to open database" )
0 commit comments