org.apache.commons.logging.LogFactory#getLog ( )源码实例Demo

下面列出了org.apache.commons.logging.LogFactory#getLog ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: alfresco-repository   文件: TransactionalCache.java
/**
 * Ensures that all properties have been set
 */
public void afterPropertiesSet() throws Exception
{
    PropertyCheck.mandatory(this, "name", name);
    PropertyCheck.mandatory(this, "sharedCache", sharedCache);
    
    // generate the resource binding key
    resourceKeyTxnData = RESOURCE_KEY_TXN_DATA + "." + name;
    // Refine the log category
    logger = LogFactory.getLog(TransactionalCache.class.getName() + "." + name);
    isDebugEnabled = logger.isDebugEnabled();
    
    // Assign a 'null' cache if write-through is disabled
    if (disableSharedCache)
    {
        sharedCache = NullCache.getInstance();
    }
}
 
源代码2 项目: ranger   文件: Log4JAuditDestination.java
@Override
public void init(Properties prop, String propPrefix) {
	super.init(prop, propPrefix);
	loggerName = MiscUtil.getStringProperty(props, propPrefix + "."
			+ PROP_LOG4J_LOGGER);
	if (loggerName == null || loggerName.isEmpty()) {
		loggerName = DEFAULT_LOGGER_PREFIX + "." + getName();
		logger.info("Logger property " + propPrefix + "."
				+ PROP_LOG4J_LOGGER + " was not set. Constructing default="
				+ loggerName);
	}
	logger.info("Logger name for " + getName() + " is " + loggerName);
	auditLogger = LogFactory.getLog(loggerName);
	logger.info("Done initializing logger for audit. name=" + getName()
			+ ", loggerName=" + loggerName);
}
 
源代码3 项目: development   文件: UrlRewritingResponseWrapper.java
/**
 * Basic constructor.
 * 
 * pock: For BES we use a new server for every request. We can't determine
 * this server from the serverChain --> use the server of the request as
 * parameter (Bug 5487)
 * 
 * @param response
 *            The response we are wrapping
 * @param server
 *            The server that was matched
 * @param ownHostName
 *            String we are rewriting servers to
 * @throws IOException
 *             When there is a problem with the streams
 */
public UrlRewritingResponseWrapper(HttpServletResponse response,
		Server server, String ownHostName, String contextPath,
		ServerChain serverChain) throws IOException {
	super(response);
	this.server = server;
	this.ownHostName = ownHostName;
	this.contextPath = contextPath;
	this.serverChain = serverChain;

	log = LogFactory.getLog(UrlRewritingResponseWrapper.class);
	outStream = new UrlRewritingOutputStream(response.getOutputStream(),
			contextPath, response
					.getCharacterEncoding());
	outWriter = new PrintWriter(outStream);
	originalWriter = new PrintWriter(response.getOutputStream());
}
 
public static boolean setFieldExtractorIfNotSet(Settings settings, Class<? extends FieldExtractor> clazz, Log log) {
    if (!StringUtils.hasText(settings.getMappingIdExtractorClassName())) {
        Log logger = (log != null ? log : LogFactory.getLog(clazz));

        String name = clazz.getName();
        settings.setProperty(ConfigurationOptions.ES_MAPPING_DEFAULT_EXTRACTOR_CLASS, name);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Using pre-defined field extractor [%s] as default", settings.getMappingIdExtractorClassName()));
        }
        return true;
    }

    return false;
}
 
源代码5 项目: gflogger   文件: Log4jLoggerServiceImpl.java
@Override
public FormattedGFLogEntry formattedLog(LogLevel level, String categoryName, String pattern, final long appenderMask) {
	final Map<String, Log4jEntry> map = entries.get();
	Log4jEntry entry = map.get(categoryName);
	if (entry == null){
		entry = new Log4jEntry(LogFactory.getLog(categoryName));
		map.put(categoryName, entry);
	}
	entry.reset();
	entry.setPattern(pattern);
	entry.setLogLevel(level);
	return entry;
}
 
源代码6 项目: alfresco-repository   文件: TransactionalCache.java
/**
 * Public constructor.
 */
public TransactionalCache()
{
    logger = LogFactory.getLog(TransactionalCache.class);
    isDebugEnabled = logger.isDebugEnabled();
    disableSharedCache = false;
    isMutable = true;
    allowEqualsChecks = false;
}
 
public static boolean setUserProviderIfNotSet(Settings settings, Class<? extends UserProvider> clazz, Log log) {
    if (!StringUtils.hasText(settings.getSecurityUserProviderClass())) {
        settings.setProperty(ConfigurationOptions.ES_SECURITY_USER_PROVIDER_CLASS, clazz.getName());
        Log logger = (log != null ? log : LogFactory.getLog(clazz));
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Using pre-defined user provider [%s] as default", settings.getSecurityUserProviderClass()));
        }
        return true;
    }
    return false;
}
 
public static boolean setMetadataExtractorIfNotSet(Settings settings, Class<? extends MetadataExtractor> clazz, Log log) {
    if (!StringUtils.hasText(settings.getMappingMetadataExtractorClassName())) {
        Log logger = (log != null ? log : LogFactory.getLog(clazz));

        String name = clazz.getName();
        settings.setProperty(ConfigurationOptions.ES_MAPPING_METADATA_EXTRACTOR_CLASS, name);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Using pre-defined metadata extractor [%s] as default", settings.getMappingMetadataExtractorClassName()));
        }
        return true;
    }

    return false;
}
 
源代码9 项目: hadoop-ozone   文件: HttpRequestLog.java
public static RequestLog getRequestLog(String name) {

    String lookup = SERVER_TO_COMPONENT.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;
      org.apache.log4j.Logger httpLogger = httpLog4JLog.getLogger();
      Appender appender = null;

      try {
        appender = httpLogger.getAppender(appenderName);
      } catch (LogConfigurationException e) {
        LOG.warn("Http request log for {} could not be created", loggerName);
        throw e;
      }

      if (appender == null) {
        LOG.info("Http request log for {} is not defined", loggerName);
        return null;
      }

      if (appender instanceof HttpRequestLogAppender) {
        HttpRequestLogAppender requestLogAppender
            = (HttpRequestLogAppender) appender;
        AsyncRequestLogWriter logWriter = new AsyncRequestLogWriter();
        logWriter.setFilename(requestLogAppender.getFilename());
        logWriter.setRetainDays(requestLogAppender.getRetainDays());
        return new CustomRequestLog(logWriter,
            CustomRequestLog.EXTENDED_NCSA_FORMAT);
      } else {
        LOG.warn("Jetty request log for {} was of the wrong class", loggerName);
        return null;
      }
    } else {
      LOG.warn("Jetty request log can only be enabled using Log4j");
      return null;
    }
  }
 
源代码10 项目: steady   文件: StackTraceUtil.java
private static final Log getLog() {
	if(StackTraceUtil.log==null)
		StackTraceUtil.log =  LogFactory.getLog(StackTraceUtil.class);
	return StackTraceUtil.log;
}
 
public void testAddingLog4jProperties() throws Throwable
{
    Log log = LogFactory.getLog(this.getClass());
    // We expect DEBUG to be on
    assertTrue("DEBUG was not enabled for logger " + this.getClass(), log.isDebugEnabled());
}
 
源代码12 项目: pentaho-metadata   文件: SQLDialectFactory.java
/**
 * private constructor
 */
private SQLDialectFactory() {
  logger = LogFactory.getLog( SQLDialectFactory.class );
  registerCoreDialects();
  loadDialectPlugins();
}
 
/**
 * Create a new {@link MutablePropertySources} object.
 */
public MutablePropertySources() {
	this.logger = LogFactory.getLog(getClass());
}
 
源代码14 项目: webcurator   文件: InTrayController.java
/** Default Constructor. */
public InTrayController() {
    log = LogFactory.getLog(InTrayController.class);
    setCommandClass(InTrayCommand.class);
}
 
源代码15 项目: webcurator   文件: UserController.java
/** Default Constructor. */
public UserController() {
    log = LogFactory.getLog(UserController.class);
    setCommandClass(UserCommand.class);
}
 
源代码16 项目: lams   文件: HttpMessageConverterExtractor.java
/**
 * Creates a new instance of the {@code HttpMessageConverterExtractor} with the given response
 * type and message converters. The given converters must support the response type.
 */
public HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters) {
	this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class));
}
 
/**
 * Set whether to use a dynamic logger or a static logger.
 * Default is a static logger for this trace interceptor.
 * <p>Used to determine which {@code Log} instance should be used to write
 * log messages for a particular method invocation: a dynamic one for the
 * {@code Class} getting called, or a static one for the {@code Class}
 * of the trace interceptor.
 * <p><b>NOTE:</b> Specify either this property or "loggerName", not both.
 * @see #getLoggerForInvocation(org.aopalliance.intercept.MethodInvocation)
 */
public void setUseDynamicLogger(boolean useDynamicLogger) {
	// Release default logger if it is not being used.
	this.defaultLogger = (useDynamicLogger ? null : LogFactory.getLog(getClass()));
}
 
/**
 * Set the name of the logger to use. The name will be passed to the
 * underlying logger implementation through Commons Logging, getting
 * interpreted as log category according to the logger's configuration.
 * <p>This can be specified to not log into the category of a class
 * (whether this interceptor's class or the class getting called)
 * but rather into a specific named category.
 * <p><b>NOTE:</b> Specify either this property or "useDynamicLogger", not both.
 * @see org.apache.commons.logging.LogFactory#getLog(String)
 * @see java.util.logging.Logger#getLogger(String)
 */
public void setLoggerName(String loggerName) {
	this.defaultLogger = LogFactory.getLog(loggerName);
}
 
源代码19 项目: java-technology-stack   文件: HttpLogging.java
/**
 * Create a primary logger for the given class and wrap it with a composite
 * that delegates to it or to the fallback logger
 * "org.springframework.web.HttpLogging", if the primary is not enabled.
 * @param primaryLoggerClass the class for the name of the primary logger
 * @return the resulting composite logger
 */
public static Log forLogName(Class<?> primaryLoggerClass) {
	Log primaryLogger = LogFactory.getLog(primaryLoggerClass);
	return forLog(primaryLogger);
}
 
/**
 * Set the log category for warn logging.
 * <p>Default is no warn logging. Specify this setting to activate warn
 * logging into a specific category.
 * @since 5.1
 * @see org.apache.commons.logging.LogFactory#getLog(String)
 * @see java.util.logging.Logger#getLogger(String)
 */
public void setWarnLogCategory(String loggerName) {
	this.warnLogger = LogFactory.getLog(loggerName);
}
 
 同类方法