/** * <p> * Construct (if necessary) and return a <code>Log</code> instance, using * the factory's current set of configuration attributes. * </p> * * @param name * Logical name of the <code>Log</code> instance to be returned * (the meaning of this name is only known to the underlying logging * implementation that is being wrapped) * * @exception LogConfigurationException * if a suitable <code>Log</code> instance cannot be returned */ public Log getInstance(String name) throws LogConfigurationException { Log instance = loggerMap.get(name); if (instance != null) { return instance; } else { Log newInstance; Logger slf4jLogger = LoggerFactory.getLogger(name); if (slf4jLogger instanceof LocationAwareLogger) { newInstance = new SLF4JLocationAwareLog((LocationAwareLogger) slf4jLogger); } else { newInstance = new SLF4JLog(slf4jLogger); } Log oldInstance = loggerMap.putIfAbsent(name, newInstance); return oldInstance == null ? newInstance : oldInstance; } }
public Log getInstance(String name) throws LogConfigurationException { String match=""; for (int i=prefixes.size();name!=null && i-->0;) { String prefix=(String)prefixes.get(i); if (name.startsWith(prefix) && prefix.length()>match.length()) match=prefix; } if (match.length()>0) name=match+".*"; // Get value Object o = attributes.get(name); // Dereference string attributes while(o!=null && o instanceof String) o=attributes.get(o); // return actual log. if (o instanceof Log) return (Log)o; return log; }
private Log getLog(String cat, String suffix) { if (suffix != null) { suffix = suffix.replace('.', '-'); suffix = suffix.replace(' ', '-'); cat = cat + "." + suffix; } final PrintStream tmpOut = System.out; final PrintStream tmpErr = System.err; System.setOut(out); System.setErr(err); if (!initialized) { try { logFactory = LogFactory.getFactory(); } catch (final LogConfigurationException e) { e.printStackTrace(System.err); return null; } } initialized = true; final Log log = logFactory.getInstance(cat); System.setOut(tmpOut); System.setErr(tmpErr); return log; }
public Log getInstance(String name) throws LogConfigurationException { Log instance = (Log) this.instances.get(name); if (instance == null) { Logger tempLogger = (Logger) Jdk14Factory.otherLoggerMap.get(name); if (tempLogger == null) { tempLogger = Jdk14Factory.defaultLogger; } instance = new MyJdk14Logger(tempLogger); this.instances.put(name, instance); } return instance; }
/** * <p> * Construct (if necessary) and return a <code>Log</code> instance, using * the factory's current set of configuration attributes. * </p> * * @param name * Logical name of the <code>Log</code> instance to be returned * (the meaning of this name is only known to the underlying logging * implementation that is being wrapped) * * @exception LogConfigurationException * if a suitable <code>Log</code> instance cannot be returned */ public Log getInstance(String name) throws LogConfigurationException { // Log instance = loggerMap.get(name); // if (instance != null) { // return instance; // } else { // Log newInstance; // Logger slf4jLogger = org.zollty.log.LogFactory.getLogger(name); // // newInstance = new Mlf4jLog(slf4jLogger); // // Log oldInstance = loggerMap.putIfAbsent(name, newInstance); // return oldInstance == null ? newInstance : oldInstance; // } return new JrettyCommonsLog( org.jretty.log.LogFactory.getLogger(name) ); }
/** * Convenience method to derive a name from the specified class and * call <code>getInstance(String)</code> with it. * @param clazz Class for which a suitable Log name will be derived * @param log the cached log instance. * @return the {@link Log} instance. */ @Nullable protected Log getInstance(@NotNull final Class<?> clazz, @Nullable final Log log) throws LogConfigurationException { @Nullable Log result = log; @Nullable final LogFactory t_LogFactory = LogFactory.getFactory(); if (t_LogFactory != null) { result = t_LogFactory.getInstance(clazz); } return result; }
/** * <p>Construct (if necessary) and return a <code>Log</code> instance, * using the factory's current set of configuration attributes.</p> * <p><strong>NOTE</strong> - Depending upon the implementation of * the <code>LogFactory</code> you are using, the <code>Log</code> * instance you are returned may or may not be local to the current * application, and may or may not be returned again on a subsequent * call with the same name argument.</p> * @param name Logical name of the <code>Log</code> instance to be * returned (the meaning of this name is only known to the underlying * logging implementation that is being wrapped) * @param log the possibly cached log instance. * @return the {@link Log} instance. * @throws LogConfigurationException in case of misconfiguration. */ @Nullable public Log getInstance(@NotNull final String name, @Nullable final Log log) throws LogConfigurationException { @Nullable Log result = log; if (result == null) { @Nullable final LogFactory t_LogFactory = LogFactory.getFactory(); if (t_LogFactory != null) { result = t_LogFactory.getInstance(name); } } return result; }
/** * Creates a <code>CommonsLoggingListener. Initializes its log factory. * @throws CheckstyleException if if the implementation class is not * available or cannot be instantiated. */ public CommonsLoggingListener() throws CheckstyleException { try { mLogFactory = LogFactory.getFactory(); } catch (LogConfigurationException e) { throw new CheckstyleException("log configuration exception", e); } mInitialized = true; }
/** * constructor with <code>SymbolTable</code> to be resolved */ public Resolver(SymbolTable symbolTable) { super(symbolTable); try { mLogFactory = LogFactory.getFactory(); } catch (LogConfigurationException e) { System.out.println("log configuration exception" + e); } mInitialized = true; }
private static void followCommonsLog(CommonsLoggingListener logger, String logName) throws LogConfigurationException, SecurityException { if (registeredLoggers.contains(logName)) //make sure no log is registered twice! return; Core.getLogger(CommonsLoggingListener.class.getName()).info("Now listening to " + logName); registeredLoggers.add(logName); org.apache.commons.logging.impl.Jdk14Logger lognode = (org.apache.commons.logging.impl.Jdk14Logger) LogFactory.getLog(logName); lognode.getLogger().addHandler(logger); }
@Override public Log getInstance(String name) throws LogConfigurationException { if (AutoConfigurationReportLoggingInitializer.class.getName().equals(name)) { return logThreadLocal.get(); } return new NoOpLog(); }
public Log getInstance(final String name) throws LogConfigurationException { Log _logger = __LOGGER_CACHE.get(name); if (_logger == null) { _logger = new JCLogger(name); __LOGGER_CACHE.put(name, _logger); } return _logger; }
@Test(expectedExceptions = LogConfigurationException.class) public void testInitLoggerContextException() throws Throwable { doReturn(null).when(testling).getConfigFileFromClasspath(); doReturn(null).when(testling).getConfigFile(); testling.initLoggerContext(); }
/** * {@inheritDoc} */ @Nullable @Override public Log getInstance(@NotNull final Class clazz) throws LogConfigurationException { return getInstance(clazz, getLog()); }
@Override public Log getInstance(final String name) throws LogConfigurationException { final ConcurrentMap<String, Log> loggers = getLoggersMap(); if (loggers.containsKey(name)) { return loggers.get(name); } final org.apache.logging.log4j.Logger logger = PrivateManager.getLogger(name); if (logger instanceof AbstractLogger) { loggers.putIfAbsent(name, new Log4jLog((AbstractLogger) logger, name)); return loggers.get(name); } throw new LogConfigurationException( "Commons Logging Adapter requires base logging system to extend Log4j AbstractLogger"); }
public static RequestLog getRequestLog(String name) { String lookup = serverToComponent.get(name); if (lookup != null) { name = lookup; } String loggerName = "http.requests." + name; String appenderName = name + "requestlog"; Log logger = LogFactory.getLog(loggerName); boolean isLog4JLogger;; try { isLog4JLogger = logger instanceof Log4JLogger; } catch (NoClassDefFoundError err) { // In some dependent projects, log4j may not even be on the classpath at // runtime, in which case the above instanceof check will throw // NoClassDefFoundError. LOG.debug("Could not load Log4JLogger class", err); isLog4JLogger = false; } if (isLog4JLogger) { Log4JLogger httpLog4JLog = (Log4JLogger)logger; Logger httpLogger = httpLog4JLog.getLogger(); Appender appender = null; try { appender = httpLogger.getAppender(appenderName); } catch (LogConfigurationException e) { LOG.warn("Http request log for " + loggerName + " could not be created"); throw e; } if (appender == null) { LOG.info("Http request log for " + loggerName + " is not defined"); return null; } if (appender instanceof HttpRequestLogAppender) { HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender)appender; NCSARequestLog requestLog = new NCSARequestLog(); requestLog.setFilename(requestLogAppender.getFilename()); requestLog.setRetainDays(requestLogAppender.getRetainDays()); return requestLog; } else { LOG.warn("Jetty request log for " + loggerName + " was of the wrong class"); return null; } } else { LOG.warn("Jetty request log can only be enabled using Log4j"); return null; } }
public static RequestLog getRequestLog(String name) { String lookup = serverToComponent.get(name); if (lookup != null) { name = lookup; } String loggerName = "http.requests." + name; String appenderName = name + "requestlog"; Log logger = LogFactory.getLog(loggerName); if (logger instanceof Log4JLogger) { Log4JLogger httpLog4JLog = (Log4JLogger)logger; Logger httpLogger = httpLog4JLog.getLogger(); Appender appender = null; try { appender = httpLogger.getAppender(appenderName); } catch (LogConfigurationException e) { LOG.warn("Http request log for " + loggerName + " could not be created"); throw e; } if (appender == null) { LOG.info("Http request log for " + loggerName + " is not defined"); return null; } if (appender instanceof HttpRequestLogAppender) { HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender)appender; NCSARequestLog requestLog = new NCSARequestLog(); requestLog.setFilename(requestLogAppender.getFilename()); requestLog.setRetainDays(requestLogAppender.getRetainDays()); return requestLog; } else { LOG.warn("Jetty request log for " + loggerName + " was of the wrong class"); return null; } } else { LOG.warn("Jetty request log can only be enabled using Log4j"); return null; } }
public Log getInstance(@SuppressWarnings("rawtypes") final Class clazz) throws LogConfigurationException { return getInstance(clazz.getName()); }
public Log getInstance(Class c) throws LogConfigurationException { if (c!=null) return getInstance(c.getName()); return getInstance((String)null); }
@SuppressWarnings("rawtypes") @Override public Log getInstance(Class clazz) throws LogConfigurationException { return new JuliLogAdapter(juliLogFactory.getInstance(clazz)); }
@Override public Log getInstance(String name) throws LogConfigurationException { return new JuliLogAdapter(juliLogFactory.getInstance(name)); }
@Override protected Log newInstance(String name) throws LogConfigurationException { return new RecordingSimpleLog(name); }
@PostConstruct public void initLoggerContext() { // properties of the LoggerContext List<ImmutablePair<String, String>> properties = Arrays.asList( new ImmutablePair<>(SakuliProperties.LOG_FOLDER, sakuliProperties.getLogFolder().toAbsolutePath().toString()), new ImmutablePair<>(SakuliProperties.LOG_PATTERN, sakuliProperties.getLogPattern()), new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SAKULI, sakuliProperties.getLogLevelSakuli()), new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SAHI, sakuliProperties.getLogLevelSahi()), new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SIKULI, sakuliProperties.getLogLevelSikuli()), new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SPRING, sakuliProperties.getLogLevelSpring()), new ImmutablePair<>(SakuliProperties.LOG_LEVEL_ROOT, sakuliProperties.getLogLevelRoot()) ); //log new properties before configuring properties.stream().filter(p -> isNotEmpty(p.getValue())) .forEach(p -> logger.info("set '{}' to '{}'", p.getKey(), p.getValue())); //start sysout forwarding to slf4j SysOutOverSLF4J.sendSystemOutAndErrToSLF4J(LogLevel.INFO, LogLevel.ERROR); LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); context.reset(); // overwrite default configuration //put properties into the context properties.stream().filter(p -> isNotEmpty(p.getValue())) .forEach(p -> context.putProperty(p.getKey(), p.getValue())); //determine the config file String configFilePath = getConfigFileFromClasspath(); if (configFilePath == null) { configFilePath = getConfigFile(); } if (configFilePath == null) { throw new LogConfigurationException("Log configuration file '" + LOG_CONFIG_FILE_NAME + "' not found! Please ensure that your config folder or your classpath contains the file."); } try { jc.doConfigure(configFilePath); } catch (JoranException e) { throw new LogConfigurationException("unable to run the LoggerIntializer, pleae check your config!", e); } logger.info("set logback configuration file '{}'", configFilePath); // Jersey uses java.util.logging - bridge to slf4 SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); }
public static RequestLog getRequestLog(String name) { String lookup = serverToComponent.get(name); if (lookup != null) { name = lookup; } String loggerName = "http.requests." + name; String appenderName = name + "requestlog"; org.apache.log4j.Logger httpLogger = getLog4jLogger(loggerName); if (httpLogger == null) { LOG.warn("Jetty request log can only be enabled using Log4j"); return null; } Appender appender = null; try { appender = httpLogger.getAppender(appenderName); } catch (LogConfigurationException e) { LOG.warn("Http request log for " + loggerName + " could not be created"); throw e; } if (appender == null) { LOG.info("Http request log for " + loggerName + " is not defined"); return null; } if (appender instanceof HttpRequestLogAppender) { HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender)appender; NCSARequestLog requestLog = new NCSARequestLog(); requestLog.setFilename(requestLogAppender.getFilename()); requestLog.setRetainDays(requestLogAppender.getRetainDays()); return requestLog; } else { LOG.warn("Jetty request log for " + loggerName + " was of the wrong class"); return null; } }
@Override public org.apache.commons.logging.Log getInstance(Class aClass) throws LogConfigurationException { return log; }
@Override public org.apache.commons.logging.Log getInstance(String string) throws LogConfigurationException { return log; }