Any recommendations to improve this logging framework? Or is it overkill? So I've been kind of irritated with my logging recently as I find myself copying and pasting the same kinds of generic messages around to lots of different methods or retyping them ever so slightly differently (when they ought to be identical).

Hence, I created this kind of framework:

public class Log {

// other logging utility methods truncated

    public enum Message {

        //Main
        PROGRAM_EXIT ("Exiting program, return code = {0}"),
        THREAD_INTERRUPTED ("Thread interrupted while {0}"),
        FATAL_TERMINATING_ERROR ("Fatal exception thrown through entire stack: {0}"),
        SHUTDOWN_HOOK_EXCEPTION ("Exception while attempting to gracefully exit: {0}"),
        IO_READ_ATTEMPT ("Attempting to read file: {0}"),
        IO_READ_FAILURE ("Unable to read from file: {0}"),
        IO_WRITE_ATTEMPT ("Attempting to write to file: {0}"),
        IO_WRITE_FAILURE ("Unable to write to file: {0}"),
        IOEXCEPTION ("IOException while {0} to {1} : {2}"),

        private final String text;

        private Message(String text) {
            this.text = text;
        }

            @Override
            public String toString() {
                return text;
            }

        public String format(Object ... args) {
            String returnValue = toString();
            for(int i = 0; i &lt; args.length; i++) {
                String placeholder = "{" + i + "}";
                if(!returnValue.contains(placeholder)) {
                    LOGGER.error("Too many arguments supplied to generateMessage() from " + getCallingMethodName());
                    LOGGER.error(" -- " + name());
                    break;
                }
                returnValue = returnValue.replace("{" + i + "}", args[i] == null ? "null" : args[i].toString());
            }
            return returnValue; 
        }
    }
}


It's then invoked like the following:

private static final String FILE_PATH = "resources/something.txt";
//...
LOGGER.error(Log.Message.IO_READ_FAILURE.format(FILE_PATH));


... which would log ...


  Unable to read from file: resources/something.txt


It all works fine, but it feels a little too verbose at times for what I'm trying to accomplish, like I've tacked on a bit too many nuts and bolts.  Like I've gone deer hunting with a .50 cal or something.

Any suggestions to improve this?  The same messages are used redundantly in several places, so I am seeing some value out of it, but I'm not sure if there's a good way to make this still more clean or otherwise accomplish what I'm trying to do in a more succinct way.

If it's relevant, I'm using log4j.
You don't need to re-implement MessageFormat. It is much more powerful than what your implementation provides.



You don't show us the class of LOGGER, but based on the fact that you have a Log class, I suspect you are not using a logging library. I highly recommend you look into using one instead of implementing your on custom implementation. 

If you are using a logging library, you are abstracting to much away from the library. All of the frameworks I've used support message formating and detailed exception logging (with stack traces).



The problem you are really trying to solve here is to allow yourself to reuse a number of common log message formats. This can be done with a simple set of Strings set to public static final.