I am currently working in a large project with a large number of applications that communicate with each other.
My team and I manage and configure applications on the system with the necessary bug fixes and change requests. The system is used heavily, and applications use a lot of logging.
A typical example:
Messageclient
public void save(final Message message) { logger.info("Trying to save message: {}", message); boolean result = false; try { result = messageService.save(message); } catch (final MessageStoreException e) { logger.warn("Unable to save message {}", message, e); throw e; } catch (final Exception e) { logger.error("Unknown error when trying to save message!", e); } if (!result) { logger.warn("Could not save the message!"); } }
MessageService
public boolean save(final Message message) throws MessageStoreException { if (message == null) { throw new IllegalArgumentException("message!"); } final boolean result = messageStore.store(message); if (result) { logger.info("Stored: {}", message.getId()); } else { logger.warn("Unable to store: {}", message.getId()); } return result; }
NOTE. I know that the sample code does not have better error handling, but it looks like this in many of the applications we manage.
Of course, this makes the log files VERY large.
I would like to enable the info log level and the warn log level in the production environment and leave the error level turned on, so that the log files contain only unexpected errors that require attention, and nothing more.
Other developers do not like this idea, because they do not know how to follow the "application flow" when they look at the log files that look for errors and errors.
I understand these arguments, and I feel that I need some input from the community.
So what's the best thing here? Should we use information / warning log levels in the production environment or should we use only the error log? Or maybe both?
Thanks!
UPDATE: Applications run on several servers, and currently we write everything to a file (a regular log file for each application with RollingFileAppender ). It is a lot of work to start writing to the database, so this is not an option.
CONCLUSION: Logging is not entirely trivial. We will not disable information and warning levels (it was a pretty radical action), but instead, as @jgauffin says, review and analyze business rules for applications that print "unnecessary" log messages.
Case is closed! Thank you all for your great contribution and good advice.