Java Code Examples for org.apache.commons.logging.Log#info()
The following examples show how to use
org.apache.commons.logging.Log#info() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReflectionUtils.java From RDFS with Apache License 2.0 | 6 votes |
/** * Log the current thread stacks at INFO level. * @param log the logger that logs the stack trace * @param title a descriptive title for the call stacks * @param minInterval the minimum time from the last */ public static void logThreadInfo(Log log, String title, long minInterval) { boolean dumpStack = false; if (log.isInfoEnabled()) { synchronized (ReflectionUtils.class) { long now = System.currentTimeMillis(); if (now - previousLogTime >= minInterval * 1000) { previousLogTime = now; dumpStack = true; } } if (dumpStack) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); printThreadInfo(new PrintWriter(buffer), title); log.info(buffer.toString()); } } }
Example 2
Source File: ProfilingTimer.java From Word2VecJava with MIT License | 6 votes |
/** Writes one profiling line of information to the log */ private static void writeToLog(int level, long totalNanos, long count, ProfilingTimerNode parent, String taskName, Log log, String logAppendMessage) { if (log == null) { return; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < level; i++) { sb.append('\t'); } String durationText = String.format("%s%s", formatElapsed(totalNanos), count == 1 ? "" : String.format(" across %d invocations, average: %s", count, formatElapsed(totalNanos / count))); String text = parent == null ? String.format("total time %s", durationText) : String.format("[%s] took %s", taskName, durationText); sb.append(text); sb.append(logAppendMessage); log.info(sb.toString()); }
Example 3
Source File: AnnotationUtils.java From java-technology-stack with MIT License | 6 votes |
/** * Handle the supplied annotation introspection exception. * <p>If the supplied exception is an {@link AnnotationConfigurationException}, * it will simply be thrown, allowing it to propagate to the caller, and * nothing will be logged. * <p>Otherwise, this method logs an introspection failure (in particular * {@code TypeNotPresentExceptions}) before moving on, assuming nested * Class values were not resolvable within annotation attributes and * thereby effectively pretending there were no annotations on the specified * element. * @param element the element that we tried to introspect annotations on * @param ex the exception that we encountered * @see #rethrowAnnotationConfigurationException */ static void handleIntrospectionFailure(@Nullable AnnotatedElement element, Throwable ex) { rethrowAnnotationConfigurationException(ex); Log loggerToUse = logger; if (loggerToUse == null) { loggerToUse = LogFactory.getLog(AnnotationUtils.class); logger = loggerToUse; } if (element instanceof Class && Annotation.class.isAssignableFrom((Class<?>) element)) { // Meta-annotation or (default) value lookup on an annotation type if (loggerToUse.isDebugEnabled()) { loggerToUse.debug("Failed to meta-introspect annotation " + element + ": " + ex); } } else { // Direct annotation lookup on regular Class, Method, Field if (loggerToUse.isInfoEnabled()) { loggerToUse.info("Failed to introspect annotations on " + element + ": " + ex); } } }
Example 4
Source File: MyPerformanceMonitorInterceptor.java From tutorials with MIT License | 6 votes |
@Override protected Object invokeUnderTrace(MethodInvocation invocation, Log log) throws Throwable { String name = createInvocationTraceName(invocation); long start = System.currentTimeMillis(); log.info("Method "+name+" execution started at:"+new Date()); try { return invocation.proceed(); } finally { long end = System.currentTimeMillis(); long time = end - start; log.info("Method "+name+" execution lasted:"+time+" ms"); log.info("Method "+name+" execution ended at:"+new Date()); if (time > 10){ log.warn("Method execution longer than 10 ms!"); } } }
Example 5
Source File: SpringApplication.java From spring-javaformat with Apache License 2.0 | 6 votes |
/** * Called to log active profile information. * @param context the application context */ protected void logStartupProfileInfo(ConfigurableApplicationContext context) { Log log = getApplicationLog(); if (log.isInfoEnabled()) { String[] activeProfiles = context.getEnvironment().getActiveProfiles(); if (ObjectUtils.isEmpty(activeProfiles)) { String[] defaultProfiles = context.getEnvironment().getDefaultProfiles(); log.info("No active profile set, falling back to default profiles: " + StringUtils.arrayToCommaDelimitedString(defaultProfiles)); } else { log.info("The following profiles are active: " + StringUtils.arrayToCommaDelimitedString(activeProfiles)); } } }
Example 6
Source File: LoggerModuleComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void executeInternal() throws Throwable { String moduleId = super.getModuleId(); String name = super.getName(); Log logger = LogFactory.getLog(moduleId + "." + name); switch (logLevel) { case INFO: logger.info(message); break; case WARN: logger.warn(message); break; case ERROR: logger.error(message); break; } }
Example 7
Source File: ReflectionUtils.java From hadoop-gpu with Apache License 2.0 | 6 votes |
/** * Log the current thread stacks at INFO level. * @param log the logger that logs the stack trace * @param title a descriptive title for the call stacks * @param minInterval the minimum time from the last */ public static void logThreadInfo(Log log, String title, long minInterval) { boolean dumpStack = false; if (log.isInfoEnabled()) { synchronized (ReflectionUtils.class) { long now = System.currentTimeMillis(); if (now - previousLogTime >= minInterval * 1000) { previousLogTime = now; dumpStack = true; } } if (dumpStack) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); printThreadInfo(new PrintWriter(buffer), title); log.info(buffer.toString()); } } }
Example 8
Source File: CompilationMessageCollector.java From spork with Apache License 2.0 | 5 votes |
private static void logMessage(String messageString, MessageType messageType, Log log) { switch(messageType) { case Info: log.info(messageString); break; case Warning: log.warn(messageString); break; case Error: log.error(messageString); } }
Example 9
Source File: CommonsLoggingListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */ public void auditFinished(AuditEvent aEvt) { if (mInitialized) { final Log log = mLogFactory.getInstance(Checker.class); log.info("Audit finished."); } }
Example 10
Source File: CommonsLoggingListener.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */ public void addError(AuditEvent aEvt) { final SeverityLevel severityLevel = aEvt.getSeverityLevel(); if (mInitialized && !SeverityLevel.IGNORE.equals(severityLevel)) { final Log log = mLogFactory.getInstance(aEvt.getSourceName()); final String fileName = aEvt.getFileName(); final String message = aEvt.getMessage(); // avoid StringBuffer.expandCapacity final int bufLen = message.length() + BUFFER_CUSHION; final StringBuffer sb = new StringBuffer(bufLen); sb.append("Line: ").append(aEvt.getLine()); if (aEvt.getColumn() > 0) { sb.append(" Column: ").append(aEvt.getColumn()); } sb.append(" Message: ").append(message); if (aEvt.getSeverityLevel().equals(SeverityLevel.WARNING)) { log.warn(sb.toString()); } else if (aEvt.getSeverityLevel().equals(SeverityLevel.INFO)) { log.info(sb.toString()); } else { log.error(sb.toString()); } } }
Example 11
Source File: CommonsLoggerTest.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Test public void testInfo() { Log mock = createStrictMock(Log.class); mock.info("a"); replay(mock); InternalLogger logger = new CommonsLogger(mock, "foo"); logger.info("a"); verify(mock); }
Example 12
Source File: ValidationController.java From rice with Educational Community License v2.0 | 5 votes |
/** * Writes the results of the validation to an output file * * @param log - The Log4j logger the output is sent to * @param validator - The filled validator * @param passed - Whether the validation passed or not */ protected void writeToLog(Log log, Validator validator, boolean passed) { log.info("Passed: " + passed); if (displayErrors) { log.info("Number of Errors: " + validator.getNumberOfErrors()); } if (displayWarnings) { log.info("Number of Warnings: " + validator.getNumberOfWarnings()); } if (displayErrorMessages) { for (int i = 0; i < validator.getErrorReportSize(); i++) { if (validator.getErrorReport(i).getErrorStatus() == ErrorReport.ERROR) { if (displayXmlPages) { log.error(validator.getErrorReport(i).errorMessage() + validator.getErrorReport(i) .errorPageList()); } else { log.error(validator.getErrorReport(i).errorMessage()); } } else { if (displayWarningMessages) { if (displayXmlPages) { log.warn(validator.getErrorReport(i).errorMessage() + validator.getErrorReport(i) .errorPageList()); } else { log.warn(validator.getErrorReport(i).errorMessage()); } } } } } }
Example 13
Source File: Log4jWebConfigurerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void assertLogOutput() { Log log = LogFactory.getLog(this.getClass()); log.debug("debug"); log.info("info"); log.warn("warn"); log.error("error"); log.fatal("fatal"); assertTrue(MockLog4jAppender.loggingStrings.contains("debug")); assertTrue(MockLog4jAppender.loggingStrings.contains("info")); assertTrue(MockLog4jAppender.loggingStrings.contains("warn")); assertTrue(MockLog4jAppender.loggingStrings.contains("error")); assertTrue(MockLog4jAppender.loggingStrings.contains("fatal")); }
Example 14
Source File: LogUtils.java From alfresco-bulk-import with Apache License 2.0 | 4 votes |
public final static void info(final Log log, final Throwable cause) { log.info(RAW_EXCEPTION, cause); }
Example 15
Source File: ContextLoader.java From spring-analysis-note with MIT License | 4 votes |
/** * Initialize Spring's web application context for the given servlet context, * using the application context provided at construction time, or creating a new one * according to the "{@link #CONTEXT_CLASS_PARAM contextClass}" and * "{@link #CONFIG_LOCATION_PARAM contextConfigLocation}" context-params. * * 使用构造时提供的应用程序上下文初始化 Spring 的给定 servlet 上下文的 Web 应用程序上下文, * 或者根据“ contextClass ”和“{ contextConfigLocation }”创建新的 context-params。 * * @param servletContext current servlet context * @return the new WebApplicationContext * @see #ContextLoader(WebApplicationContext) * @see #CONTEXT_CLASS_PARAM * @see #CONFIG_LOCATION_PARAM */ public WebApplicationContext initWebApplicationContext(ServletContext servletContext) { // demo 中用到的根容器是 Spring 容器 WebApplicationContext.class.getName() + ".ROOT" if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) { // web.xml 中存在多次 ContextLoader 定义 throw new IllegalStateException( "Cannot initialize context because there is already a root application context present - " + "check whether you have multiple ContextLoader* definitions in your web.xml!"); } servletContext.log("Initializing Spring root WebApplicationContext"); Log logger = LogFactory.getLog(ContextLoader.class); if (logger.isInfoEnabled()) { logger.info("Root WebApplicationContext: initialization started"); } long startTime = System.currentTimeMillis(); try { // Store context in local instance variable, to guarantee that // it is available on ServletContext shutdown. // 将上下文存储在本地实例变量中,以保证在 ServletContext 关闭时可用。 if (this.context == null) { // 初始化 context this.context = createWebApplicationContext(servletContext); } if (this.context instanceof ConfigurableWebApplicationContext) { ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context; if (!cwac.isActive()) { // The context has not yet been refreshed -> provide services such as // setting the parent context, setting the application context id, etc if (cwac.getParent() == null) { // The context instance was injected without an explicit parent -> // determine parent for root web application context, if any. ApplicationContext parent = loadParentContext(servletContext); cwac.setParent(parent); } configureAndRefreshWebApplicationContext(cwac, servletContext); } } // 记录在 ServletContext 中 servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl == ContextLoader.class.getClassLoader()) { currentContext = this.context; } else if (ccl != null) { currentContextPerThread.put(ccl, this.context); } if (logger.isInfoEnabled()) { // 计数器,计算初始化耗时时间 long elapsedTime = System.currentTimeMillis() - startTime; logger.info("Root WebApplicationContext initialized in " + elapsedTime + " ms"); } return this.context; } catch (RuntimeException | Error ex) { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } }
Example 16
Source File: LogUtils.java From alfresco-bulk-import with Apache License 2.0 | 4 votes |
public final static void info(final Log log, final String message, final Throwable cause) { log.info(PREFIX + message, cause); }
Example 17
Source File: Logalyzer.java From hadoop with Apache License 2.0 | 4 votes |
public static void main(String[] args) { Log LOG = LogFactory.getLog(Logalyzer.class); String version = "Logalyzer.0.0.1"; String usage = "Usage: Logalyzer [-archive -logs <urlsFile>] " + "-archiveDir <archiveDirectory> " + "-grep <pattern> -sort <column1,column2,...> -separator <separator> " + "-analysis <outputDirectory>"; System.out.println(version); if (args.length == 0) { System.err.println(usage); System.exit(-1); } //Command line arguments boolean archive = false; boolean grep = false; boolean sort = false; String archiveDir = ""; String logListURI = ""; String grepPattern = ".*"; String sortColumns = ""; String columnSeparator = " "; String outputDirectory = ""; for (int i = 0; i < args.length; i++) { // parse command line if (args[i].equals("-archive")) { archive = true; } else if (args[i].equals("-archiveDir")) { archiveDir = args[++i]; } else if (args[i].equals("-grep")) { grep = true; grepPattern = args[++i]; } else if (args[i].equals("-logs")) { logListURI = args[++i]; } else if (args[i].equals("-sort")) { sort = true; sortColumns = args[++i]; } else if (args[i].equals("-separator")) { columnSeparator = args[++i]; } else if (args[i].equals("-analysis")) { outputDirectory = args[++i]; } } LOG.info("analysisDir = " + outputDirectory); LOG.info("archiveDir = " + archiveDir); LOG.info("logListURI = " + logListURI); LOG.info("grepPattern = " + grepPattern); LOG.info("sortColumns = " + sortColumns); LOG.info("separator = " + columnSeparator); try { Logalyzer logalyzer = new Logalyzer(); // Archive? if (archive) { logalyzer.doArchive(logListURI, archiveDir); } // Analyze? if (grep || sort) { logalyzer.doAnalyze(archiveDir, outputDirectory, grepPattern, sortColumns, columnSeparator); } } catch (IOException ioe) { ioe.printStackTrace(); System.exit(-1); } }
Example 18
Source File: Logalyzer.java From RDFS with Apache License 2.0 | 4 votes |
public static void main(String[] args) { Log LOG = LogFactory.getLog(Logalyzer.class); String version = "Logalyzer.0.0.1"; String usage = "Usage: Logalyzer [-archive -logs <urlsFile>] " + "-archiveDir <archiveDirectory> " + "-grep <pattern> -sort <column1,column2,...> -separator <separator> " + "-analysis <outputDirectory>"; System.out.println(version); if (args.length == 0) { System.err.println(usage); System.exit(-1); } //Command line arguments boolean archive = false; boolean grep = false; boolean sort = false; String archiveDir = ""; String logListURI = ""; String grepPattern = ".*"; String sortColumns = ""; String columnSeparator = " "; String outputDirectory = ""; for (int i = 0; i < args.length; i++) { // parse command line if (args[i].equals("-archive")) { archive = true; } else if (args[i].equals("-archiveDir")) { archiveDir = args[++i]; } else if (args[i].equals("-grep")) { grep = true; grepPattern = args[++i]; } else if (args[i].equals("-logs")) { logListURI = args[++i]; } else if (args[i].equals("-sort")) { sort = true; sortColumns = args[++i]; } else if (args[i].equals("-separator")) { columnSeparator = args[++i]; } else if (args[i].equals("-analysis")) { outputDirectory = args[++i]; } } LOG.info("analysisDir = " + outputDirectory); LOG.info("archiveDir = " + archiveDir); LOG.info("logListURI = " + logListURI); LOG.info("grepPattern = " + grepPattern); LOG.info("sortColumns = " + sortColumns); LOG.info("separator = " + columnSeparator); try { Logalyzer logalyzer = new Logalyzer(); // Archive? if (archive) { logalyzer.doArchive(logListURI, archiveDir); } // Analyze? if (grep || sort) { logalyzer.doAnalyze(archiveDir, outputDirectory, grepPattern, sortColumns, columnSeparator); } } catch (IOException ioe) { ioe.printStackTrace(); System.exit(-1); } }
Example 19
Source File: Logalyzer.java From big-c with Apache License 2.0 | 4 votes |
public static void main(String[] args) { Log LOG = LogFactory.getLog(Logalyzer.class); String version = "Logalyzer.0.0.1"; String usage = "Usage: Logalyzer [-archive -logs <urlsFile>] " + "-archiveDir <archiveDirectory> " + "-grep <pattern> -sort <column1,column2,...> -separator <separator> " + "-analysis <outputDirectory>"; System.out.println(version); if (args.length == 0) { System.err.println(usage); System.exit(-1); } //Command line arguments boolean archive = false; boolean grep = false; boolean sort = false; String archiveDir = ""; String logListURI = ""; String grepPattern = ".*"; String sortColumns = ""; String columnSeparator = " "; String outputDirectory = ""; for (int i = 0; i < args.length; i++) { // parse command line if (args[i].equals("-archive")) { archive = true; } else if (args[i].equals("-archiveDir")) { archiveDir = args[++i]; } else if (args[i].equals("-grep")) { grep = true; grepPattern = args[++i]; } else if (args[i].equals("-logs")) { logListURI = args[++i]; } else if (args[i].equals("-sort")) { sort = true; sortColumns = args[++i]; } else if (args[i].equals("-separator")) { columnSeparator = args[++i]; } else if (args[i].equals("-analysis")) { outputDirectory = args[++i]; } } LOG.info("analysisDir = " + outputDirectory); LOG.info("archiveDir = " + archiveDir); LOG.info("logListURI = " + logListURI); LOG.info("grepPattern = " + grepPattern); LOG.info("sortColumns = " + sortColumns); LOG.info("separator = " + columnSeparator); try { Logalyzer logalyzer = new Logalyzer(); // Archive? if (archive) { logalyzer.doArchive(logListURI, archiveDir); } // Analyze? if (grep || sort) { logalyzer.doAnalyze(archiveDir, outputDirectory, grepPattern, sortColumns, columnSeparator); } } catch (IOException ioe) { ioe.printStackTrace(); System.exit(-1); } }
Example 20
Source File: LogUtils.java From alfresco-bulk-import with Apache License 2.0 | 4 votes |
public final static void info(final Log log, final String message) { log.info(PREFIX + message); }