Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package de.agilecoders.wicket.logging;
  
  import org.slf4j.Logger;
  
An IClientLogger is responsible for writing the log messages to the log store. Slf4j is used as default Logger implementation.

Author(s):
miha
 
 public interface IClientLogger {

    
writes a set of log messages to the log store

Parameters:
logObjects all log messages that needs to be written
clientInfos the client information according to given logObjects.
 
     void log(Collection<ClientSideLogObjectlogObjectsClientInfos clientInfos);

    
Default implementation of IClientLogger that uses slf4j as logger.
 
     public static class DefaultClientLogger implements IClientLogger {
         private final Logger logger;
         private final ILoggingBarrier barrier;

        
Construct.

Parameters:
id the logger id
 
         public DefaultClientLogger(final String id) {
             this. = newLogger(id);
             this. = newBarrier();
         }

        
creates a new slf4j logger

Parameters:
loggerName the name of the logger
Returns:
new logger
 
         protected Logger newLogger(String loggerName) {
             return LoggerFactory.getLogger(loggerName);
         }

        

Returns:
new barrier instance
 
         protected ILoggingBarrier newBarrier() {
             return new ILoggingBarrier.AllowAllBarrier();
         }
 
         @Override
         public void log(Collection<ClientSideLogObjectlogObjectsClientInfos clientInfos) {
             if(!.isAllowed(logObjects)) {
                 return;
             }
 
             final ILogCleaner cleaner = ClientSideLogging.settings().cleaner();
 
             for (ClientSideLogObject logObject : logObjects) {
                 if (.isAllowed(logObject)) {
                     switch (logObject.level()) {
                         case "error":
                             if (.isErrorEnabled()) {
                                 .error(newLogMessage("error"logObjectclientInfoscleaner));
                             }
                             break;
                         case "warn":
                             if (.isWarnEnabled()) {
                                 .warn(newLogMessage("warn"logObjectclientInfoscleaner));
                             }
                             break;
                         case "info":
                             if (.isInfoEnabled()) {
                                 .info(newLogMessage("info"logObjectclientInfoscleaner));
                             }
                             break;
                         case "debug":
                             if (.isDebugEnabled()) {
                                 .debug(newLogMessage("debug"logObjectclientInfoscleaner));
                             }
                             break;
                         case "trace":
                             if (.isTraceEnabled()) {
                                 .trace(newLogMessage("trace"logObjectclientInfoscleaner));
                             }
                             break;
                         default:
                     }
                 }
            }
        }

        
creates a new log line

Parameters:
logLevel the current log level
logObject the log object that contains message and level
clientInfos the client information that contains user-agent and ajax base url
cleaner the log cleaner implementation
Returns:
new log message line.
        protected String newLogMessage(String logLevelClientSideLogObject logObjectClientInfos clientInfosILogCleaner cleaner) {
            return String.format("[%s] %s [%s]; Stack: %s"cleaner.toCleanPath(clientInfos.ajaxBaseUrl()), logObjectcleaner.clean(clientInfos.userAgent()), logObject.stacktrace());
        }
    }
New to GrepCode? Check out our FAQ X