I'm currently working in a large project with a lot of applications that are communicating with each other.
Me and my team manage and adjust the applications in the system with necessary bug fixes and change requests. The system is being used heavily, and the applications uses a lot of logging.
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 example code does not have the best error handling, but this is how it looks like in many applications that we manage.
Of course, this makes the logfiles VERY big.
I would like to turn of log level info and log level warn in the production environment, and only leave the error level on, so that the logfiles only contains unexpected errors that need attention and nothing else.
The other developers do not like this idea, as they don't know how to follow the "application flow" when they are viewing the logfiles searching for bugs and errors.
I understand these arguments, and I feel that I need some input from the community.
So, what is best practice here? Should we use info/warn log levels in the production environment or should we only use error logging? Or maybe both?
Thanks!
UPDATE: The applications run on multiple servers, and we currently log everything to file (usual one log file per application with a RollingFileAppender). It is to much work to start logging to a database, so this is not an option.
CONCLUSION: Logging is not entirely trivial. We will not turn off the info and warning levels (it was a pretty drastic action), but instead just like @jgauffin says, go through and analyze business rules for the applications that prints "unnecessary" log messages.
Case closed! Thank you all for the great input and good advice.