use of org.apache.logging.log4j.simple.SimpleLogger in project pyroscope-java by pyroscope-io.
the class PyroscopeAgent method premain.
public static void premain(final String agentArgs, final Instrumentation inst) {
final Config config;
final Logger logger;
try {
Profiler.init();
config = Config.build();
logger = new SimpleLogger("PyroscopeAgent", config.logLevel, false, true, true, false, "yyyy-MM-dd HH:mm:ss.SSS", ParameterizedNoReferenceMessageFactory.INSTANCE, new PropertiesUtil(new Properties()), System.err);
} catch (final Throwable e) {
PreConfigLogger.LOGGER.error("Error starting profiler", e);
return;
}
logger.debug("Config {}", config);
final OverfillQueue<Snapshot> pushQueue = new OverfillQueue<>(config.pushQueueCapacity);
try {
final Profiler profiler = new Profiler(logger, config.profilingEvent, config.profilingAlloc, config.profilingLock, config.profilingInterval, config.format);
final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
}
});
profiler.start();
final Runnable dumpProfile = () -> {
try {
pushQueue.put(profiler.dump());
} catch (final InterruptedException ignored) {
// It's fine to swallow InterruptedException here and exit.
// It's a cue to end the work and exit and we have nothing to clean up.
}
};
executor.scheduleAtFixedRate(dumpProfile, config.uploadInterval.toMillis(), config.uploadInterval.toMillis(), TimeUnit.MILLISECONDS);
final Thread uploaderThread = new Thread(new Uploader(logger, pushQueue, config));
uploaderThread.setDaemon(true);
uploaderThread.start();
} catch (final Throwable e) {
logger.error("Error starting profiler", e);
}
}
use of org.apache.logging.log4j.simple.SimpleLogger in project Javacord by BtoBastian.
the class LoggerUtil method getLogger.
/**
* 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));
}
}
use of org.apache.logging.log4j.simple.SimpleLogger in project james by tomtom-international.
the class Log4j2PublisherTest method shouldLogEvent.
@Test
public void shouldLogEvent() {
SimpleLogger logger = (SimpleLogger) LogManager.getLogger(LOGGER_NAME);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
logger.setStream(new PrintStream(byteArrayOutputStream));
createPublisher().publish(new Event(Collections.singletonMap("key", "value"), Instant.EPOCH));
assertThat(byteArrayOutputStream.toString().trim()).isEqualTo("INFO logger @created=\"1970-01-01T00:00:00Z\" key=\"value\" type=\"james\"");
}
use of org.apache.logging.log4j.simple.SimpleLogger in project Javacord by Javacord.
the class LoggerUtil method getLogger.
/**
* 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));
}
}
Aggregations