@@ -75,6 +75,13 @@ func Initialize(conf *config.ConfigType) error {
7575 // Set up log rotation using lumberjack
7676 logFile := filepath .Join (logsDir , "codacy-cli.log" )
7777
78+ // Try to create/open the log file to test permissions
79+ f , err := os .OpenFile (logFile , os .O_WRONLY | os .O_CREATE | os .O_APPEND , utils .DefaultFilePerms )
80+ if err != nil {
81+ return fmt .Errorf ("failed to create/open log file: %w" , err )
82+ }
83+ f .Close ()
84+
7885 lumberjackLogger := & lumberjack.Logger {
7986 Filename : logFile ,
8087 MaxSize : 10 , // megabytes
@@ -86,7 +93,7 @@ func Initialize(conf *config.ConfigType) error {
8693 // Configure logrus to use our custom formatter
8794 fileLogger .SetFormatter (& CustomTextFormatter {})
8895 fileLogger .SetOutput (lumberjackLogger )
89- fileLogger .SetLevel (logrus .InfoLevel )
96+ fileLogger .SetLevel (logrus .DebugLevel )
9097
9198 // Enable caller information for file location
9299 fileLogger .SetReportCaller (true )
@@ -103,21 +110,37 @@ func Log(level logrus.Level, msg string, fields logrus.Fields) {
103110}
104111
105112// Info logs an info level message
106- func Info (msg string , fields logrus.Fields ) {
107- Log (logrus .InfoLevel , msg , fields )
113+ func Info (msg string , fields ... logrus.Fields ) {
114+ var f logrus.Fields
115+ if len (fields ) > 0 {
116+ f = fields [0 ]
117+ }
118+ Log (logrus .InfoLevel , msg , f )
108119}
109120
110121// Error logs an error level message
111- func Error (msg string , fields logrus.Fields ) {
112- Log (logrus .ErrorLevel , msg , fields )
122+ func Error (msg string , fields ... logrus.Fields ) {
123+ var f logrus.Fields
124+ if len (fields ) > 0 {
125+ f = fields [0 ]
126+ }
127+ Log (logrus .ErrorLevel , msg , f )
113128}
114129
115130// Debug logs a debug level message
116- func Debug (msg string , fields logrus.Fields ) {
117- Log (logrus .DebugLevel , msg , fields )
131+ func Debug (msg string , fields ... logrus.Fields ) {
132+ var f logrus.Fields
133+ if len (fields ) > 0 {
134+ f = fields [0 ]
135+ }
136+ Log (logrus .DebugLevel , msg , f )
118137}
119138
120139// Warn logs a warning level message
121- func Warn (msg string , fields logrus.Fields ) {
122- Log (logrus .WarnLevel , msg , fields )
140+ func Warn (msg string , fields ... logrus.Fields ) {
141+ var f logrus.Fields
142+ if len (fields ) > 0 {
143+ f = fields [0 ]
144+ }
145+ Log (logrus .WarnLevel , msg , f )
123146}
0 commit comments