Java Code Examples for org.apache.logging.log4j.LogManager#getLogger()
The following examples show how to use
org.apache.logging.log4j.LogManager#getLogger() .
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: FileAppenderBenchmark.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Setup public void setUp() throws Exception { System.setProperty("log4j.configurationFile", "log4j2-perf.xml"); System.setProperty("log4j.configuration", "log4j12-perf.xml"); System.setProperty("logback.configurationFile", "logback-perf.xml"); deleteLogFiles(); log4j2Logger = LogManager.getLogger(FileAppenderBenchmark.class); log4j2AsyncAppender = LogManager.getLogger("AsyncAppender"); log4j2AsyncDisruptor = LogManager.getLogger("AsyncDisruptorAppender"); log4j2AsyncLogger = LogManager.getLogger("AsyncLogger"); log4j2MemoryLogger = LogManager.getLogger("MemoryMapped"); log4j2RandomLogger = LogManager.getLogger("TestRandom"); slf4jLogger = LoggerFactory.getLogger(FileAppenderBenchmark.class); slf4jAsyncLogger = LoggerFactory.getLogger("Async"); log4j1Logger = org.apache.log4j.Logger.getLogger(FileAppenderBenchmark.class); julFileHandler = new FileHandler("target/testJulLog.log"); julLogger = java.util.logging.Logger.getLogger(getClass().getName()); julLogger.setUseParentHandlers(false); julLogger.addHandler(julFileHandler); julLogger.setLevel(Level.ALL); }
Example 2
Source File: MCRLoggingCommands.java From mycore with GNU General Public License v3.0 | 6 votes |
/** * @param name * the name of the java class or java package to set the log * level for * @param logLevelToSet * the log level to set e.g. TRACE, DEBUG, INFO, WARN, ERROR and * FATAL, providing any other value will lead to DEBUG as new log * level */ @MCRCommand(syntax = "change log level of {0} to {1}", help = "{0} the package or class name for which to change the log level, {1} the log level to set.", order = 10) public static synchronized void changeLogLevel(String name, String logLevelToSet) { LOGGER.info("Setting log level for \"{}\" to \"{}\"", name, logLevelToSet); Level newLevel = Level.getLevel(logLevelToSet); if (newLevel == null) { LOGGER.error("Unknown log level \"{}\"", logLevelToSet); return; } Logger log = "ROOT".equals(name) ? LogManager.getRootLogger() : LogManager.getLogger(name); if (log == null) { LOGGER.error("Could not get logger for \"{}\"", name); return; } LOGGER.info("Change log level from {} to {}", log.getLevel(), newLevel); Configurator.setLevel(log.getName(), newLevel); }
Example 3
Source File: AnnotatedVariantProducerUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test(dataProvider = "evidenceTargetLinksAndPreciseVariants", groups = "sv") public void testProcessEvidenceTargetLinks(final List<EvidenceTargetLink> etls, final List<VariantContext> inputVariants, final List<VariantContext> expectedVariants) { final Logger localLogger = LogManager.getLogger(AnnotatedVariantProducer.class); final StructuralVariationDiscoveryArgumentCollection.DiscoverVariantsFromContigAlignmentsSparkArgumentCollection params = new StructuralVariationDiscoveryArgumentCollection.DiscoverVariantsFromContigAlignmentsSparkArgumentCollection(); ReadMetadata metadata = Mockito.mock(ReadMetadata.class); when(metadata.getMaxMedianFragmentSize()).thenReturn(300); when(metadata.getContigName(0)).thenReturn("20"); PairedStrandedIntervalTree<EvidenceTargetLink> evidenceTree = new PairedStrandedIntervalTree<>(); etls.forEach(e -> evidenceTree.put(e.getPairedStrandedIntervals(), e)); final List<VariantContext> processedVariantContexts = AnnotatedVariantProducer.annotateBreakpointBasedCallsWithImpreciseEvidenceLinks(inputVariants, evidenceTree, metadata, TestUtilsForAssemblyBasedSVDiscovery.b37_reference, params, localLogger); VariantContextTestUtils.assertEqualVariants(processedVariantContexts, expectedVariants); }
Example 4
Source File: FlumeAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testStructured() throws IOException { final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort) }; final FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, null, "false", "Avro", null, "1000", "1000", "1", "1000", "avro", "false", null, null, null, "ReqCtx_", null, "true", "1", null, null, null, null); avroAppender.start(); final Logger eventLogger = (Logger) LogManager.getLogger("EventLogger"); Assert.assertNotNull(eventLogger); eventLogger.addAppender(avroAppender); eventLogger.setLevel(Level.ALL); final StructuredDataMessage msg = new StructuredDataMessage("Transfer", "Success", "Audit"); msg.put("memo", "This is a memo"); msg.put("acct", "12345"); msg.put("amount", "100.00"); ThreadContext.put("id", UUID.randomUUID().toString()); ThreadContext.put("memo", null); ThreadContext.put("test", "123"); EventLogger.logEvent(msg); final Transaction transaction = channel.getTransaction(); transaction.begin(); final Event event = channel.take(); Assert.assertNotNull(event); Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Success")); transaction.commit(); transaction.close(); eventSource.stop(); eventLogger.removeAppender(avroAppender); avroAppender.stop(); }
Example 5
Source File: LoggerUtil.java From Javacord with Apache License 2.0 | 5 votes |
/** * Get or create a logger with the given name. * * @param name The name of the logger. * @return The logger with the given name. */ public static Logger getLogger(String name) { AtomicBoolean logWarning = new AtomicBoolean(false); initialized.updateAndGet(initialized -> { if (!initialized && !ProviderUtil.hasProviders()) { noLogger.set(true); logWarning.set(true); } return true; }); if (noLogger.get()) { return loggers.computeIfAbsent(name, key -> { Level level = FallbackLoggerConfiguration.isTraceEnabled() ? Level.TRACE : (FallbackLoggerConfiguration.isDebugEnabled() ? Level.DEBUG : Level.INFO); Logger logger = new SimpleLogger(name, level, true, false, true, true, "yyyy-MM-dd HH:mm:ss.SSSZ", null, new PropertiesUtil(new Properties()), System.out); if (logWarning.get()) { logger.info("No Log4j2 compatible logger was found. Using default Javacord implementation!"); } return new PrivacyProtectionLogger(logger); }); } else { return new PrivacyProtectionLogger(LogManager.getLogger(name)); } }
Example 6
Source File: Debug.java From scipio-erp with Apache License 2.0 | 5 votes |
public static Logger getLogger(String module) { // SCIPIO: refactored for checkStripModuleExt if (module != null && !module.isEmpty()) { return LogManager.getLogger(checkStripModuleExt(module)); } else { return root; } }
Example 7
Source File: AsyncAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testException() throws Exception { final Logger logger = LogManager.getLogger(AsyncAppender.class); final Exception parent = new IllegalStateException("Test"); final Throwable child = new LoggingException("This is a test", parent); logger.error("This is a test", child); final long timeoutMillis = TIMEOUT_MILLIS; final TimeUnit timeUnit = TimeUnit.MILLISECONDS; final List<String> list = listAppender.getMessages(1, timeoutMillis, timeUnit); assertNotNull("No events generated", list); assertTrue("Incorrect number of events after " + timeoutMillis + " " + timeUnit + ". Expected 1, got " + list.size(), list.size() == 1); final String msg = list.get(0); assertTrue("No parent exception", msg.contains("java.lang.IllegalStateException")); }
Example 8
Source File: TestConfigurator.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testReconfiguration() throws Exception { final File file = new File("target/test-classes/log4j2-config.xml"); assertTrue("setLastModified should have succeeded.", file.setLastModified(System.currentTimeMillis() - 120000)); ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-config.xml"); final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator"); Configuration config = ctx.getConfiguration(); assertNotNull("No configuration", config); assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName()); final Map<String, Appender> map = config.getAppenders(); assertNotNull("Appenders map should not be null.", map); assertThat(map, hasSize(greaterThan(0))); assertThat("Wrong configuration", map, hasKey("List")); // Sleep and check Thread.sleep(50); if (!file.setLastModified(System.currentTimeMillis())) { Thread.sleep(500); } assertTrue("setLastModified should have succeeded.", file.setLastModified(System.currentTimeMillis())); TimeUnit.SECONDS.sleep(config.getWatchManager().getIntervalSeconds()+1); for (int i = 0; i < 17; ++i) { logger.debug("Test message " + i); } // Sleep and check Thread.sleep(50); if (is(theInstance(config)).matches(ctx.getConfiguration())) { Thread.sleep(500); } final Configuration newConfig = ctx.getConfiguration(); assertThat("Configuration not reset", newConfig, is(not(theInstance(config)))); Configurator.shutdown(ctx); config = ctx.getConfiguration(); assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName()); }
Example 9
Source File: ForwardLogHandler.java From Kettle with GNU General Public License v3.0 | 5 votes |
private Logger getLogger(String name) { Logger logger = cachedLoggers.get(name); if (logger == null) { logger = LogManager.getLogger(name); cachedLoggers.put(name, logger); } return logger; }
Example 10
Source File: RakNetClient.java From JRakNet with MIT License | 5 votes |
/** * Creates a RakNet client. * * @param address * the address the client will bind to during connection. A * <code>null</code> address will have the client bind to the * wildcard address along with the client giving Netty the * responsibility of choosing which port to bind to. */ public RakNetClient(InetSocketAddress address) { this.bindingAddress = address; this.guid = UUID.randomUUID().getMostSignificantBits(); this.logger = LogManager .getLogger(RakNetClient.class.getSimpleName() + "[" + Long.toHexString(guid).toUpperCase() + "]"); this.timestamp = System.currentTimeMillis(); this.listeners = new ConcurrentLinkedQueue<RakNetClientListener>(); if (this.getClass() != RakNetClient.class && RakNetClientListener.class.isAssignableFrom(this.getClass())) { this.addSelfListener(); } }
Example 11
Source File: YEngineRestorer.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
protected YEngineRestorer(YEngine engine, YPersistenceManager pmgr) { _engine = engine; _pmgr = pmgr; _idLookupTable = new HashMap<String, YIdentifier>(); _taskLookupTable = new HashMap<String, YTask>(); _log = LogManager.getLogger(this.getClass()); }
Example 12
Source File: OutputStreamAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testOutputStreamAppenderToByteArrayOutputStream() { final OutputStream out = new ByteArrayOutputStream(); final String name = getName(out); final Logger logger = LogManager.getLogger(name); addAppender(out, name); logger.error(TEST_MSG); final String actual = out.toString(); Assert.assertTrue(actual, actual.contains(TEST_MSG)); }
Example 13
Source File: MetaDataIndexUpgrader.java From crate with Apache License 2.0 | 4 votes |
public MetaDataIndexUpgrader() { this.logger = LogManager.getLogger(MetaDataIndexUpgrader.class); }
Example 14
Source File: ActivityHelper.java From fess with Apache License 2.0 | 4 votes |
@PostConstruct public void init() { logger = LogManager.getLogger(loggerName); }
Example 15
Source File: MinecraftPEServer.java From BouncyBall with MIT License | 4 votes |
public MinecraftPEServer(int bindPort){ this.port = bindPort; packetIntercepter = new PacketIntercepter(this); logger = LogManager.getLogger("BouncyBall"); }
Example 16
Source File: ComposedMappingConfiguration.java From tutorials with MIT License | 4 votes |
@Bean @Scope("prototype") public Logger logger(InjectionPoint injectionPoint) { return LogManager.getLogger(injectionPoint.getField().getDeclaringClass()); }
Example 17
Source File: WorkletEventServer.java From yawl with GNU Lesser General Public License v3.0 | 4 votes |
/** * Constructs a new event server */ public WorkletEventServer() { _log = LogManager.getLogger(WorkletEventServer.class); }
Example 18
Source File: LDAPSource.java From yawl with GNU Lesser General Public License v3.0 | 4 votes |
public LDAPSource() { _log = LogManager.getLogger(this.getClass()); loadProperties(); initMaps(); }
Example 19
Source File: caseMgt.java From yawl with GNU Lesser General Public License v3.0 | 4 votes |
private void downloadLog() { Logger logger = LogManager.getLogger(this.getClass()); logger.info("XES #downloadLog: begins ->"); InputStream is = null; OutputStream os = null; try { Integer selectedRowIndex = new Integer((String) hdnRowIndex.getValue()); SpecificationData spec = _sb.getLoadedSpec(selectedRowIndex); if (spec != null) { String log = LogMiner.getInstance().getMergedXESLog(spec.getID(), true); logger.info("XES #downloadLog: merged log returned, response prep begins"); if (log != null) { String filename = String.format("%s%s.xes", spec.getSpecURI(), spec.getSpecVersion()); FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = ( HttpServletResponse ) context.getExternalContext().getResponse(); response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\""); logger.info("XES #downloadLog: response prep ends, output begins"); is = new ByteArrayInputStream(log.getBytes("UTF-8")); os = response.getOutputStream(); IOUtils.copy(is, os); FacesContext.getCurrentInstance().responseComplete(); logger.info("XES #downloadLog: output ends"); } else msgPanel.error("Unable to create export file: malformed xml."); } } catch (IOException ioe) { msgPanel.error("Unable to create export file. Please see the log for details."); } catch (NumberFormatException nfe) { msgPanel.error("Please select a specification to download the log for.") ; } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); logger.info("XES #downloadLog: -> ends"); } }
Example 20
Source File: YNetLocalVarVerifier.java From yawl with GNU Lesser General Public License v3.0 | 4 votes |
/** * Constructor * @param net the net to verify */ public YNetLocalVarVerifier(YNet net) { _net = net; _uninitialisedLocalVars = new Hashtable<String, LocalTaskMap>(); _log = LogManager.getLogger(this.getClass()); }