001package org.javasimon.callback.logging;
002
003/**
004 * Log template class is the root of a hierarchy of implementations with different purposes.
005 *
006 * @author gquintana
007 */
008public abstract class LogTemplate<C> {
009
010        /**
011         * If enabled, logs the message for context.
012         *
013         * @param context Context
014         * @param messageSource Message producer
015         * @return true if logging is enabled, false otherwise
016         */
017        public final boolean log(C context, LogMessageSource<C> messageSource) {
018                final boolean enabled = isEnabled(context);
019                if (enabled) {
020                        log(messageSource.getLogMessage(context));
021                }
022                return enabled;
023        }
024
025        /**
026         * Tells whether logging is enabled.
027         *
028         * @return Logging enabled
029         */
030        protected abstract boolean isEnabled(C context);
031
032        /** Logs a message. */
033        protected abstract void log(String message);
034}