本文整理汇总了Java中org.apache.logging.log4j.core.appender.ConsoleAppender类的典型用法代码示例。如果您正苦于以下问题:Java ConsoleAppender类的具体用法?Java ConsoleAppender怎么用?Java ConsoleAppender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConsoleAppender类属于org.apache.logging.log4j.core.appender包,在下文中一共展示了ConsoleAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuilder
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
@Test
public void testBuilder() throws Exception {
final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ERROR);
builder.setConfigurationName("BuilderTest");
builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.NEUTRAL)
.addAttribute("level", Level.DEBUG));
final AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target",
ConsoleAppender.Target.SYSTEM_OUT);
appenderBuilder.add(builder.newLayout("PatternLayout").
addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable"));
appenderBuilder.add(builder.newFilter("MarkerFilter", Filter.Result.DENY,
Filter.Result.NEUTRAL).addAttribute("marker", "FLOW"));
builder.add(appenderBuilder);
builder.add(builder.newLogger("org.apache.logging.log4j", Level.DEBUG).
add(builder.newAppenderRef("Stdout")).
addAttribute("additivity", false));
builder.add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef("Stdout")));
ctx = Configurator.initialize(builder.build());
final Configuration config = ctx.getConfiguration();
assertNotNull("No configuration", config);
assertEquals("Unexpected Configuration", "BuilderTest", config.getName());
assertThat(config.getAppenders(), hasSize(equalTo(1)));
}
示例2: createConfiguration
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
private Configuration createConfiguration(final String name, ConfigurationBuilder<BuiltConfiguration> builder) {
builder.setConfigurationName(name);
/* Only internal Log4J2 messages with level ERROR will be logged */
builder.setStatusLevel(Level.ERROR);
/* Create appender that logs to System.out */
AppenderComponentBuilder appenderBuilder = builder.newAppender("STDOUT", "CONSOLE")
.addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
/* Create pattern for log messages */
appenderBuilder.add(builder.newLayout("PatternLayout")
.addAttribute("pattern", "[%d{HH:mm:ss}] (%c{1}) [%level] %msg%n%throwable"));
/*timestamp logger name level log message & optional throwable */
builder.add(appenderBuilder);
/* Create logger that uses STDOUT appender */
builder.add(builder.newLogger("JukeBot", JUKEBOT_LOG_LEVEL)
.add(builder.newAppenderRef("STDOUT"))
.addAttribute("additivity", false));
/* Create root logger--messages not from the above logger will all go through this one */
builder.add(builder.newRootLogger(LIB_LOG_LEVEL).add(builder.newAppenderRef("STDOUT")));
return builder.build();
}
示例3: addAttributes
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
private static <T, K extends ComponentBuilder <K>> void addAttributes (final ComponentBuilder <K> appender,
final Map <String, T> attributes) {
for (final Entry <String, T> entry : attributes.entrySet ()) {
final String key = entry.getKey ();
final T val = entry.getValue ();
boolean isEnum = false;
for (final Target target : ConsoleAppender.Target.values ())
if (target .name ()
.equalsIgnoreCase (val.toString ())) {
appender.addAttribute (key, Target.valueOf (val.toString ()));
isEnum = true;
}
if (!isEnum) {
if (val instanceof Status) {
appender.addAttribute (key, ((Status) val).getStatus ());
}
else {
appender.addAttribute (key, val);
}
}
}
}
示例4: buildConfiguration
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
protected Configuration buildConfiguration() {
ConfigurationBuilder<BuiltConfiguration> builder = newConfigurationBuilder();
builder.setConfigurationName(Log4j2RedactorTest.class.getName());
builder.setStatusLevel(Level.INFO);
AppenderComponentBuilder appenderBuilder = builder.newAppender("Stderr", "CONSOLE")
.addAttribute("target", ConsoleAppender.Target.SYSTEM_ERR);
appenderBuilder.add(builder.newLayout("PatternLayout")
.addAttribute("pattern", "%msg"));
builder.add(appenderBuilder);
AppenderComponentBuilder rewriteBuilder = builder.newAppender("Redactor", "Rewrite")
.addComponent(builder.newComponent("RedactorPolicy", "RedactorPolicy")
.addAttribute("rules", resourcePath + getPolicyFilename()))
.addComponent(builder.newAppenderRef("Stderr"));
builder.add(rewriteBuilder);
builder.add(builder.newRootLogger(Level.INFO)
.add(builder.newAppenderRef("Redactor")));
return builder.build();
}
示例5: configureLog4j
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
private static Logger configureLog4j() {
LoggerContext context = (LoggerContext) LogManager.getContext();
Configuration config = context.getConfiguration();
PatternLayout layout = PatternLayout.createLayout("%m%n", null, null, Charset.defaultCharset(), false, false, null, null);
Appender appender = ConsoleAppender.createAppender(layout, null, null, "CONSOLE_APPENDER", null, null);
appender.start();
AppenderRef ref = AppenderRef.createAppenderRef("CONSOLE_APPENDER", null, null);
AppenderRef[] refs = new AppenderRef[]{ref};
LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "CONSOLE_LOGGER", "com", refs, null, null, null);
loggerConfig.addAppender(appender, null, null);
config.addAppender(appender);
config.addLogger("Main.class", loggerConfig);
context.updateLoggers(config);
return LogManager.getContext().getLogger("Main.class");
}
示例6: main
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
public static void main(String[] args) throws UnRetriableException{
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
ConsoleAppender appender = ConsoleAppender.createDefaultAppenderForLayout(PatternLayout.createDefaultLayout());
appender.start();
config.addAppender(appender);
AppenderRef[] refs = new AppenderRef[] { AppenderRef.createAppenderRef(appender.getName(), null, null) };
LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, LogManager.ROOT_LOGGER_NAME, "true", refs, null, config, null);
loggerConfig.addAppender(appender, null, null);
config.addLogger(LogManager.ROOT_LOGGER_NAME, loggerConfig);
ctx.updateLoggers();
Runner runner = defaultRunner();
runner.init();
runner.start();
}
示例7: main
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
public static void main(String[] args) throws UnRetriableException {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
ConsoleAppender appender = ConsoleAppender.createDefaultAppenderForLayout(PatternLayout.createDefaultLayout());
appender.start();
config.addAppender(appender);
AppenderRef[] refs = new AppenderRef[] { AppenderRef.createAppenderRef(appender.getName(), null, null) };
LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.WARN, LogManager.ROOT_LOGGER_NAME, "true", refs, null, config, null);
loggerConfig.addAppender(appender, null, null);
config.addLogger(LogManager.ROOT_LOGGER_NAME, loggerConfig);
ctx.updateLoggers();
Runner runner = defaultRunner();
runner.init();
runner.start();
}
示例8: preInit
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
// logging stuff.
if (!FMLForgePlugin.RUNTIME_DEOBF) // not runtime deobf = dev env
{
String packageName = this.getClass().getPackage().getName();
Logger baseLogger = (Logger) LogManager.getLogger(packageName);
ConsoleAppender appender = ConsoleAppender.createAppender(null, null, Target.SYSTEM_OUT.toString(), "console", "true", "false");
baseLogger.addAppender(appender);
baseLogger.setLevel(Level.DEBUG);
appender.start();
// testing levels..
for (Level l : Level.values())
{
baseLogger.log(l, "TESTING {} on level {}", baseLogger.getName(), l);
LogManager.getLogger().log(l, "TESTING {} on level {}", this.getClass().getName(), l);
}
}
Configuration c = new Configuration(event.getSuggestedConfigurationFile());
OUR_SERVER = c.get("main", "globalbloodstain", 1, "Turn on global bloodstains?0=no, 1=yes").getInt() == 0 ? false : true;
c.save();
}
示例9: setToDefault
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
private void setToDefault() {
setName(DefaultConfiguration.DEFAULT_NAME);
final Layout<? extends Serializable> layout =
PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n",
null, null, null, null);
final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false",
"true");
appender.start();
addAppender(appender);
final LoggerConfig root = getRootLogger();
root.addAppender(appender, null, null);
final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL);
final Level level = levelName != null && Level.valueOf(levelName) != null ?
Level.valueOf(levelName) : Level.ERROR;
root.setLevel(level);
}
示例10: DefaultConfiguration
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
/**
* Constructor to create the default configuration.
*/
public DefaultConfiguration() {
setName(DEFAULT_NAME);
final Layout<? extends Serializable> layout =
PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n", null, null, null, null);
final Appender appender =
ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
appender.start();
addAppender(appender);
final LoggerConfig root = getRootLogger();
root.addAppender(appender, null, null);
final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
final Level level = levelName != null && Level.valueOf(levelName) != null ?
Level.valueOf(levelName) : Level.ERROR;
root.setLevel(level);
}
示例11: CustomConfiguration
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
/**
* Constructor to create the default configuration.
*/
public CustomConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
super(loggerContext, source);
setName(CONFIG_NAME);
final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
.withPattern(DEFAULT_PATTERN)
.withConfiguration(this)
.build();
final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
appender.start();
addAppender(appender);
final LoggerConfig root = getRootLogger();
root.addAppender(appender, null, null);
final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
final Level level = levelName != null && Level.valueOf(levelName) != null ?
Level.valueOf(levelName) : Level.ERROR;
root.setLevel(level);
}
示例12: setToDefault
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
protected void setToDefault() {
// LOG4J2-1176 facilitate memory leak investigation
setName(DefaultConfiguration.DEFAULT_NAME + "@" + Integer.toHexString(hashCode()));
final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
.withPattern(DefaultConfiguration.DEFAULT_PATTERN)
.withConfiguration(this)
.build();
final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
appender.start();
addAppender(appender);
final LoggerConfig rootLoggerConfig = getRootLogger();
rootLoggerConfig.addAppender(appender, null, null);
final Level defaultLevel = Level.ERROR;
final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL,
defaultLevel.name());
final Level level = Level.valueOf(levelName);
rootLoggerConfig.setLevel(level != null ? level : defaultLevel);
}
示例13: addTestFixtures
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
private void addTestFixtures(final String name, final ConfigurationBuilder<BuiltConfiguration> builder) {
builder.setConfigurationName(name);
builder.setStatusLevel(Level.ERROR);
builder.setShutdownTimeout(5000, TimeUnit.MILLISECONDS);
builder.add(builder.newScriptFile("target/test-classes/scripts/filter.groovy").addIsWatched(true));
builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.NEUTRAL)
.addAttribute("level", Level.DEBUG));
final AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
appenderBuilder.add(builder.newLayout("PatternLayout").
addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable"));
appenderBuilder.add(builder.newFilter("MarkerFilter", Filter.Result.DENY,
Filter.Result.NEUTRAL).addAttribute("marker", "FLOW"));
builder.add(appenderBuilder);
builder.add(builder.newLogger("org.apache.logging.log4j", Level.DEBUG, true).
add(builder.newAppenderRef("Stdout")).
addAttribute("additivity", false));
builder.add(builder.newLogger("org.apache.logging.log4j.core").
add(builder.newAppenderRef("Stdout")));
builder.add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef("Stdout")));
builder.addProperty("MyKey", "MyValue");
builder.add(builder.newCustomLevel("Panic", 17));
builder.setPackages("foo,bar");
}
示例14: addTestFixtures
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
public static Configuration addTestFixtures(final String name, final ConfigurationBuilder<BuiltConfiguration> builder) {
builder.setConfigurationName(name);
builder.setStatusLevel(Level.ERROR);
builder.add(builder.newScriptFile("target/test-classes/scripts/filter.groovy").addIsWatched(true));
builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.NEUTRAL)
.addAttribute("level", Level.DEBUG));
final AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
appenderBuilder.add(builder.
newLayout("PatternLayout").
addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable"));
appenderBuilder.add(builder.
newFilter("MarkerFilter", Filter.Result.DENY, Filter.Result.NEUTRAL).
addAttribute("marker", "FLOW"));
builder.add(appenderBuilder);
builder.add(builder.newLogger("org.apache.logging.log4j", Level.DEBUG, true).
add(builder.newAppenderRef("Stdout")).
addAttribute("additivity", false));
builder.add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef("Stdout")));
builder.add(builder.newCustomLevel("Panic", 17));
return builder.build();
}
示例15: testFindAppender
import org.apache.logging.log4j.core.appender.ConsoleAppender; //导入依赖的package包/类
public void testFindAppender() throws IOException, UserException {
setupLogging("find_appender");
final Logger hasConsoleAppender = ESLoggerFactory.getLogger("has_console_appender");
final Appender testLoggerConsoleAppender = Loggers.findAppender(hasConsoleAppender, ConsoleAppender.class);
assertNotNull(testLoggerConsoleAppender);
assertThat(testLoggerConsoleAppender.getName(), equalTo("console"));
final Logger hasCountingNoOpAppender = ESLoggerFactory.getLogger("has_counting_no_op_appender");
assertNull(Loggers.findAppender(hasCountingNoOpAppender, ConsoleAppender.class));
final Appender countingNoOpAppender = Loggers.findAppender(hasCountingNoOpAppender, CountingNoOpAppender.class);
assertThat(countingNoOpAppender.getName(), equalTo("counting_no_op"));
}