JavaScript is disabled on your browser.
javolution.context

Class LogContext



  • public abstract class LogContext
    extends AbstractContext 

    Asynchronous logging context integrated with the OSGi logging framework. The logging back-end, or how the log entries are displayed, stored, or processed is unspecified but always performed asynchronously. When running outside OSGi, log messages are sent to System.out. Message formatting itself is always performed synchronously using the current TextContext.

    Logging contexts support automatic prefixing/suffixing of any information relevant to the user/developer (thread info, user id, and so on).

     void run() {
     LogContext ctx = LogContext.enter(); 
     try {
     // Prefix the executing thread to any message being logged.
     ctx.prefix("[Thread: ", Thead.currentThread(), "] "); 
     ... 
     } finally {
     ctx.exit();
     }
     }

    Applications should separate messages elements by commas and not use String concatenations when calling log methods otherwise the concatenation is performed even when log events are filtered out.

     LogContext ctx = LogContext.enter();
     try {
     ctx.setLevel(Level.INFO); // Does not log debug messages. 
     ... 
     LogContext.debug("Index: ", index, " at maximum value"); // GOOD, no formatting performed !
     LogContext.debug("Index: " + index + " at maximum value"); // BAD, formatting performed even though nothing is logged !
     ...
     } finally {
     ctx.exit();
     }

    Version:
    6.0, July 21, 2013
    Author:
    Jean-Marie Dautelle
    See Also:
    Understanding OSGi Logging
    • Field Detail

      • LEVEL

        public static final Configurable<LogContext.Level> LEVEL
        Holds the default logging level (DEBUG). This level is configurable. For example, running with the option -Djavolution.context.LogContext#LEVEL=WARNING causes the debug/info not to be logged.
    • Constructor Detail

      • LogContext

        protected LogContext()
        Default constructor.
    • Method Detail

      • debug

        public static void debug(Object... message)
        Logs the specified debug message.
      • enter

        public static LogContext enter()
        Enters and returns a new log context instance.
      • error

        public static void error(Object... message)
        Logs the specified error message (which may include any Throwable instance).
      • info

        public static void info(Object... message)
        Logs the specified info message.
      • warning

        public static void warning(Object... message)
        Logs the specified warning message.
      • prefix

        public abstract void prefix(Object... prefixes)
        Prefixes all messages being logged by the specified prefixes (prefixing existing prefixes if any).
      • setLevel

        public abstract void setLevel(LogContext.Level level)
        Set the logging level, messages below that level are not logged.
      • suffix

        public abstract void suffix(Object... suffixes)
        Suffixes all messages being logged by the specified suffixes (suffixing existing suffixes if any).
      • log

        protected abstract void log(LogContext.Level level,
         Object... message)
        Logs the specified message at the specified level.

Copyright © 2005-2013 Javolution. All Rights Reserved.

AltStyle によって変換されたページ (->オリジナル) /