I log my app errors. but if the logging process failed for some reasons ( database error , no space in the hard disk .. etc ) . how can I know that ? How to log the failed log.
example :
try{
this_will_throw_exception();
}catch(Exception e){
result = Log.error(e.getMessage());
if( result == false)
{
// what should I do ?
}
}
You should keep your application code simple, i.e. not to worry about logging failure and delegate the logging failure to the logger itself.
Hence your application code should look like:
Now we look at how to handle failure in logger.
First, there is a lot of logging framework that provide appender failover. For example there us a FailoverAppender in log4j that log to secondary appender if the primary failed. http://logging.apache.org/log4j/2.x/manual/appenders.html
If you choose to build your own logging layer for whatever reason, you may find the decorator pattern useful to build failover logger yourself.