Skip to content

improved error messages#239

Closed
kplimack wants to merge 10 commits intologrotate:masterfrom
kplimack:error
Closed

improved error messages#239
kplimack wants to merge 10 commits intologrotate:masterfrom
kplimack:error

Conversation

@kplimack
Copy link

@kplimack kplimack commented Feb 8, 2019

What

Improving error messaging.

  • This PR adds the "error" prefix to messages that make the exit code non-zero, making the output simple to grep "error".
  • Output the total number of errors detected before exiting

Why?

When certain pieces of code change the exit-code to 1 and don't say the word error in their output, it makes it challenging to determine why logrotate is failing its checks without diving into the code.

Example

From the output of logrotate -d, it looks like there are no problems, it just exits 1. So you comb through the output looking for a message that indicates the reason, but nothing looks like a failure. You see a message like

destination /var/log/something/something already exists, skipping rotation

This is an error and is raising the exit code, but it is unclear that this is the behavior that is causing the failure

Related to #238

@kplimack kplimack changed the title error improved error messages Feb 8, 2019
@kdudka
Copy link
Member

kdudka commented Feb 12, 2019

Thank you for raising this topic! I think that vast majority of the message(MESS_ERROR, ...) calls should result in non-zero exit code. The few exceptions could be fixed to either return non-zero code, or by replacing MESS_ERROR by a different level. We could probably introduce MESS_WARNING to print warnings. Then we can easily modify the message() function to always print the error: prefix for MESS_ERROR and warning: for MESS_WARNING, instead of duplicating the prefixes all over the code. Does it make sense?

@kdudka kdudka self-assigned this Feb 12, 2019
@andy-v-h
Copy link

It does make sense. New push coming shortly.

rc |= writeState(stateFile);

if (debug && rc)
message(MESS_ERROR, "logrotate has had %d errors", rc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output is misleading. rc is a return code, not count of errors.

@kdudka
Copy link
Member

kdudka commented Nov 4, 2019

This pull request becomes messy as there are a lot of commits reverting each other. The resulting diff just adds the debug/info/verbose/error/fatal/unknown prefix, as I understand it. Note that the debug prefix does not work well for example with rotateLogSet(), where it prints something like this:

debug: reading config file lr.conf
debug: Reading state from file: lr.stat
debug: Allocating hash table for state file, size 64 entries
debug: Creating new state
debug: 
Handling 1 logs
debug: 
rotating pattern: /tmp/xxx  debug: 1048576 bytes debug: (1 rotations)
debug: empty log files are rotated, debug: old logs are removed
debug: considering log /tmp/xxx
debug:   Now: 2019-11-04 13:26
debug:   Last rotated at 2019-11-04 13:00
debug:   log does not need rotating (log size is below the 'size' threshold)
debug: set default create context to unconfined_u:object_r:user_home_t:s0

@andy-v-h
Copy link

andy-v-h commented Nov 6, 2019

@kdudka I apologize for the messy commit history, I’ve been working in Go mostly these days, and didn’t know how to best build and run test locally. I ended up having a couple of script locally.

I hadn’t considered how it would pollute the output. I hadn’t been concerned with that since I’m used to writing syslog formatted messages so the log level being on each line feels normal but I understand the need to minimize behavior changes. Perhaps an additional flag for whether or not to pretend with debug: then entire blocks would look more like

debug: reading config file lr.conf
       Reading state from file: lr.stat
       Allocating hash table for state file, size 64 entries
       Creating new state
       
Handling 1 logs
       
rotating pattern: /tmp/xxx  debug: 1048576 bytes debug: (1 rotations)
       empty log files are rotated, debug: old logs are removed
      considering log /tmp/xxx
         Now: 2019-11-04 13:26
         Last rotated at 2019-11-04 13:00
         log does not need rotating (log size is below the 'size' threshold)
       set default create context to unconfined_u:object_r:user_home_t:s0 

That way each time a series of debug level logs comes through, it is only pretended once?

@kdudka
Copy link
Member

kdudka commented Nov 11, 2019

Can't we just use the prefix for error messages only? Those affect logrotate's exit code after all...

@paumic
Copy link

paumic commented Dec 23, 2021

Not sure if this is related place to post, but it seems that destination /my/rotated/file/new-name already exists, skipping rotation and log does not need rotating (log size is below the 'size' threshold) messages both goes to the stderr.

First type will trigger RC 1, while second type will return RC 0. Perhaps it would be possible to either:

Place output to stdout which does not trigger RC 0, and/or separate error messages in stderr to determine which ones does trigger RC 1.

@cgzones
Copy link
Member

cgzones commented Dec 23, 2021

Not sure if this is related place to post, but it seems that destination /my/rotated/file/new-name already exists, skipping rotation and log does not need rotating (log size is below the 'size' threshold) messages both goes to the stderr.

First type will trigger RC 1, while second type will return RC 0. Perhaps it would be possible to either:

Place output to stdout which does not trigger RC 0, and/or separate error messages in stderr to determine which ones does trigger RC 1.

Currently all messages are printed to stderr

logrotate/log.c

Lines 60 to 64 in 5b4518d

if (level >= logLevel) {
va_start(args, format);
log_once(stderr, level, format, args);
va_end(args);
}

but the message log does not need rotating (log size is below the 'size' threshold) is only printed in debug mode

logrotate/logrotate.c

Lines 1427 to 1430 in 5b4518d

if (!state->doRotate) {
message(MESS_DEBUG, " log does not need rotating "
"(log size is below the 'size' threshold)\n");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants