use of org.apache.log4j.PatternLayout in project intellij-community by JetBrains.
the class StartupUtil method prepareAndStart.
static void prepareAndStart(String[] args, AppStarter appStarter) {
boolean newConfigFolder = false;
if (!Main.isHeadless()) {
AppUIUtil.updateFrameClass();
newConfigFolder = !new File(PathManager.getConfigPath()).exists();
}
if (!checkJdkVersion()) {
System.exit(Main.JDK_CHECK_FAILED);
}
// avoiding "log4j:WARN No appenders could be found"
System.setProperty("log4j.defaultInitOverride", "true");
try {
org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
if (!root.getAllAppenders().hasMoreElements()) {
root.setLevel(Level.WARN);
root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.DEFAULT_CONVERSION_PATTERN)));
}
} catch (Throwable e) {
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
// note: uses config folder!
if (!checkSystemFolders()) {
System.exit(Main.DIR_CHECK_FAILED);
}
ActivationResult result = lockSystemFolders(args);
if (result == ActivationResult.ACTIVATED) {
System.exit(0);
} else if (result != ActivationResult.STARTED) {
System.exit(Main.INSTANCE_CHECK_FAILED);
}
if (newConfigFolder) {
appStarter.beforeImportConfigs();
ConfigImportHelper.importConfigsTo(PathManager.getConfigPath());
}
Logger.setFactory(LoggerFactory.class);
Logger log = Logger.getInstance(Main.class);
startLogging(log);
loadSystemLibraries(log);
fixProcessEnvironment(log);
if (!Main.isHeadless()) {
AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame());
AppUIUtil.registerBundledFonts();
AppUIUtil.showPrivacyPolicy();
}
appStarter.start(newConfigFolder);
}
use of org.apache.log4j.PatternLayout in project sling by apache.
the class WithholdingAppender method install.
/**
* Install the WithholdingAppender, essentially muting all logging
* and withholding it until release() is called
* @return the WithholdingAppender that can be used to get the
* withheld log output
*/
public static WithholdingAppender install() {
LogManager.getRootLogger().removeAllAppenders();
final WithholdingAppender withholdingAppender = new WithholdingAppender(new PatternLayout("%d{dd.MM.yyyy HH:mm:ss.SSS} *%-5p* [%t] %c{1}: %m\n"));
LogManager.getRootLogger().addAppender(withholdingAppender);
return withholdingAppender;
}
use of org.apache.log4j.PatternLayout in project samza by apache.
the class TestStreamAppender method testSystemProducerAppenderInAM.
@Test
public void testSystemProducerAppenderInAM() {
System.setProperty("samza.container.name", "samza-job-coordinator");
MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%m");
systemProducerAppender.setLayout(layout);
systemProducerAppender.activateOptions();
log.addAppender(systemProducerAppender);
log.info("no-received");
systemProducerAppender.flushSystemProducer();
// it should not receive anything because the system is not setup
assertEquals(0, MockSystemProducer.messagesReceived.size());
systemProducerAppender.setupSystem();
MockSystemProducerAppender.systemInitialized = true;
log.info("testing3");
log.info("testing4");
systemProducerAppender.flushSystemProducer();
// be able to received msgs now
assertEquals(2, MockSystemProducer.messagesReceived.size());
assertTrue(new String((byte[]) MockSystemProducer.messagesReceived.get(0)).contains("\"message\":\"testing3\""));
assertTrue(new String((byte[]) MockSystemProducer.messagesReceived.get(1)).contains("\"message\":\"testing4\""));
// reset
log.removeAllAppenders();
MockSystemProducer.messagesReceived.clear();
}
use of org.apache.log4j.PatternLayout in project samza by apache.
the class TestStreamAppender method testDefaultSerde.
@Test
public void testDefaultSerde() {
System.setProperty("samza.container.name", "samza-container-1");
MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%m");
systemProducerAppender.setLayout(layout);
systemProducerAppender.activateOptions();
assertNotNull(systemProducerAppender.getSerde());
assertEquals(LoggingEventJsonSerde.class, systemProducerAppender.getSerde().getClass());
}
use of org.apache.log4j.PatternLayout in project ignite by apache.
the class GridSingleExecutionTest method initLogger.
/**
* Initializes logger.
*
* @param log Log file name.
* @return Logger.
* @throws IgniteCheckedException If file initialization failed.
*/
private static IgniteLogger initLogger(String log) throws IgniteCheckedException {
Logger impl = Logger.getRootLogger();
impl.removeAllAppenders();
String fileName = U.getIgniteHome() + "/work/log/" + log;
// Configure output that should go to System.out
RollingFileAppender fileApp;
String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
try {
fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
fileApp.setMaxBackupIndex(0);
fileApp.rollOver();
} catch (IOException e) {
throw new IgniteCheckedException("Unable to initialize file appender.", e);
}
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.DEBUG);
fileApp.addFilter(lvlFilter);
impl.addAppender(fileApp);
// Configure output that should go to System.out
ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.INFO);
lvlFilter.setLevelMax(Level.INFO);
conApp.addFilter(lvlFilter);
impl.addAppender(conApp);
// Configure output that should go to System.err
conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
conApp.setThreshold(Level.WARN);
impl.addAppender(conApp);
impl.setLevel(Level.INFO);
Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG);
return new GridTestLog4jLogger(false);
}
Aggregations