use of org.apache.log4j.PatternLayout in project ignite by apache.
the class Log4JLogger method createConsoleAppender.
/**
* Creates console appender with some reasonable default logging settings.
*
* @param maxLevel Max logging level.
* @return New console appender.
*/
private Appender createConsoleAppender(Level maxLevel) {
String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
// Configure output that should go to System.out
Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.TRACE);
lvlFilter.setLevelMax(maxLevel);
app.addFilter(lvlFilter);
return app;
}
use of org.apache.log4j.PatternLayout in project ignite by apache.
the class GridLog4jCorrectFileNameTest method createAppender.
/**
* Creates new GridLog4jRollingFileAppender.
*
* @return GridLog4jRollingFileAppender.
* @throws Exception If error occurred.
*/
private static Log4jRollingFileAppender createAppender() throws Exception {
Log4jRollingFileAppender appender = new Log4jRollingFileAppender();
appender.setLayout(new PatternLayout("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"));
appender.setFile("work/log/ignite.log");
appender.setName(Log4jRollingFileAppender.class.getSimpleName());
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.DEBUG);
lvlFilter.setLevelMax(Level.INFO);
appender.addFilter(lvlFilter);
return appender;
}
use of org.apache.log4j.PatternLayout in project Lucee by lucee.
the class Log4jUtil method getLayout.
public static final Layout getLayout(ClassDefinition cd, Map<String, String> layoutArgs) {
if (layoutArgs == null)
layoutArgs = new HashMap<String, String>();
// Layout
Layout layout = null;
if (cd != null && cd.hasClass()) {
// Classic Layout
if (ClassicLayout.class.getName().equalsIgnoreCase(cd.getClassName()))
layout = new ClassicLayout();
else // HTML Layout
if (HTMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
HTMLLayout html = new HTMLLayout();
layout = html;
// Location Info
Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
if (locInfo != null)
html.setLocationInfo(locInfo.booleanValue());
else
locInfo = Boolean.FALSE;
layoutArgs.put("locationinfo", locInfo.toString());
// Title
String title = Caster.toString(layoutArgs.get("title"), "");
if (!StringUtil.isEmpty(title, true))
html.setTitle(title);
layoutArgs.put("title", title);
} else // XML Layout
if (XMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
XMLLayout xml = new XMLLayout();
layout = xml;
// Location Info
Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
if (locInfo != null)
xml.setLocationInfo(locInfo.booleanValue());
else
locInfo = Boolean.FALSE;
layoutArgs.put("locationinfo", locInfo.toString());
// Properties
Boolean props = Caster.toBoolean(layoutArgs.get("properties"), null);
if (props != null)
xml.setProperties(props.booleanValue());
else
props = Boolean.FALSE;
layoutArgs.put("properties", props.toString());
} else // Pattern Layout
if (PatternLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
PatternLayout patt = new PatternLayout();
layout = patt;
// pattern
String pattern = Caster.toString(layoutArgs.get("pattern"), null);
if (!StringUtil.isEmpty(pattern, true))
patt.setConversionPattern(pattern);
else {
patt.setConversionPattern(DEFAULT_PATTERN);
layoutArgs.put("pattern", DEFAULT_PATTERN);
}
} else // class defintion
{
Object obj = ClassUtil.loadInstance(cd.getClazz(null), null, null);
if (obj instanceof Layout) {
layout = (Layout) obj;
Iterator<Entry<String, String>> it = layoutArgs.entrySet().iterator();
Entry<String, String> e;
while (it.hasNext()) {
e = it.next();
try {
Reflector.callSetter(obj, e.getKey(), e.getValue());
} catch (PageException e1) {
// TODO log
SystemOut.printDate(e1);
}
}
}
}
}
if (layout != null)
return layout;
return new ClassicLayout();
}
use of org.apache.log4j.PatternLayout in project janusgraph by JanusGraph.
the class HBaseStoreManagerConfigTest method testShortCfNames.
@Test
public void testShortCfNames() throws Exception {
Logger log = Logger.getLogger(HBaseStoreManager.class);
Level savedLevel = log.getLevel();
log.setLevel(Level.WARN);
StringWriter writer = new StringWriter();
Appender appender = new WriterAppender(new PatternLayout("%p: %m%n"), writer);
log.addAppender(appender);
// Open the HBaseStoreManager and store with default SHORT_CF_NAMES true.
WriteConfiguration config = HBaseStorageSetup.getHBaseGraphConfiguration();
HBaseStoreManager manager = new HBaseStoreManager(new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE));
KeyColumnValueStore store = manager.openDatabase(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME);
store.close();
manager.close();
// Open the HBaseStoreManager and store with SHORT_CF_NAMES false.
config.set(ConfigElement.getPath(HBaseStoreManager.SHORT_CF_NAMES), false);
manager = new HBaseStoreManager(new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE));
writer.getBuffer().setLength(0);
store = manager.openDatabase(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME);
// Verify we get WARN.
assertTrue(writer.toString(), writer.toString().startsWith("WARN: Configuration"));
log.removeAppender(appender);
log.setLevel(savedLevel);
store.close();
manager.close();
}
use of org.apache.log4j.PatternLayout in project scheduling by ow2-proactive.
the class RMNodeUpdater method initLogger.
private static Logger initLogger() {
if (System.getProperty("log4j.configuration") == null) {
// While logger is not configured and it not set with sys properties, use Console logger
Logger.getRootLogger().getLoggerRepository().resetConfiguration();
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%m%n")));
Logger.getRootLogger().setLevel(Level.INFO);
}
return Logger.getLogger(RMNodeUpdater.class);
}
Aggregations