本文整理匯總了Java中org.apache.logging.log4j.core.layout.PatternLayout.createLayout方法的典型用法代碼示例。如果您正苦於以下問題:Java PatternLayout.createLayout方法的具體用法?Java PatternLayout.createLayout怎麽用?Java PatternLayout.createLayout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.core.layout.PatternLayout
的用法示例。
在下文中一共展示了PatternLayout.createLayout方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
/**
* Create a Console Appender.
* @param layout The layout to use (required).
* @param filter The Filter or null.
* @param t The target ("SYSTEM_OUT" or "SYSTEM_ERR"). The default is "SYSTEM_OUT".
* @param follow If true will follow changes to the underlying output stream.
* @param name The name of the Appender (required).
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The ConsoleAppender.
*/
@PluginFactory
public static ConsoleAppender createAppender(
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("target") final String t,
@PluginAttribute("name") final String name,
@PluginAttribute("follow") final String follow,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("No name provided for ConsoleAppender");
return null;
}
if (layout == null) {
layout = PatternLayout.createLayout(null, null, null, null, null);
}
final boolean isFollow = Boolean.parseBoolean(follow);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final Target target = t == null ? Target.SYSTEM_OUT : Target.valueOf(t);
return new ConsoleAppender(name, layout, filter, getManager(isFollow, target, layout), ignoreExceptions);
}
示例2: addSuspectFileAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
/**
* Add an appender to Log4j which sends all INFO+ messages to a separate file which will be used
* later to scan for suspect strings. The pattern of the messages conforms to the original log
* format so that hydra will be able to parse them.
*/
private static void addSuspectFileAppender(final String workspaceDir) {
final String suspectFilename = new File(workspaceDir, SUSPECT_FILENAME).getAbsolutePath();
final LoggerContext appenderContext =
((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogService.BASE_LOGGER_NAME))
.getContext();
final PatternLayout layout = PatternLayout.createLayout(
"[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n",
null, null, null, Charset.defaultCharset(), true, false, "", "");
final FileAppender fileAppender = FileAppender.createAppender(suspectFilename, "true", "false",
DUnitLauncher.class.getName(), "true", "false", "false", "0", layout, null, null, null,
appenderContext.getConfiguration());
fileAppender.start();
LoggerConfig loggerConfig =
appenderContext.getConfiguration().getLoggerConfig(LogService.BASE_LOGGER_NAME);
loggerConfig.addAppender(fileAppender, Level.INFO, null);
}
示例3: createAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
@PluginFactory
public static TerminalConsoleAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Filters") Filter filter,
@PluginElement("Layout") Layout<? extends Serializable> layout, @PluginAttribute("ignoreExceptions") String ignore)
{
if (name == null)
{
LOGGER.error("No name provided for TerminalConsoleAppender");
return null;
}
if (layout == null)
{
layout = PatternLayout.createLayout(null, null, null, null, null);
}
boolean ignoreExceptions = parseBoolean(ignore, true);
// This is handled by jline
System.setProperty("log4j.skipJansi", "true");
return new TerminalConsoleAppender(name, filter, layout, ignoreExceptions);
}
示例4: configureLoggers
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
/**
* Setup the file logger so that it outputs messages to the appropriately named file,
* depending on the subtitle of the current program instance.
*/
private static void configureLoggers( String subtitle )
{
// Remove all characters that are not allowed for Windows filenames.
subtitle = subtitle.replaceAll( "[\\s" + Pattern.quote( "\\/:*?\"<>|" ) + "]", "" );
LoggerContext context = (LoggerContext)LogManager.getContext();
Configuration config = context.getConfiguration();
PatternLayout layout = PatternLayout.createLayout(
"%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%throwable%n",
null, null, null, Charset.defaultCharset(), false, false, null, null
);
FileAppender appender = FileAppender.createAppender(
"logs/log-" + subtitle + ".txt", "false", "false", "LogFile-" + subtitle, "true", "true", "true",
"8192", layout, null, "false", "", config
);
org.apache.logging.log4j.core.Logger rootLogger = (org.apache.logging.log4j.core.Logger)LogManager.getRootLogger();
rootLogger.addAppender( appender );
appender.start();
}
示例5: configureLogging
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
protected void configureLogging() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Layout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, null, config, null, null,
true, false, null, null);
Appender appender = FileAppender.createAppender(workDir + "/logs/camel-standalone.log", "false", "false", "File", "true",
"false", "false", "4000", layout, null, "false", null, config);
appender.start();
config.addAppender(appender);
AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
AppenderRef[] refs = new AppenderRef[] {ref};
LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "StandaloneFileLoggerConfig",
"true", refs, null, config, null );
loggerConfig.addAppender(appender, null, null);
config.addLogger("StandaloneFileLoggerConfig", loggerConfig);
ctx.updateLoggers();
}
示例6: createAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
@PluginFactory
public static ConsoleLogAppender createAppender(@PluginAttribute("name") final String name, @PluginAttribute("ignoreExceptions") final String ignore, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filters") final Filter filter, @PluginAttribute("target") String target) {
final boolean ignoreExceptions = Boolean.parseBoolean(ignore);
if (name == null) {
ConsoleLogAppender.LOGGER.error("No name provided for ConsoleLogAppender");
return null;
}
if (target == null) {
target = name;
}
ConsoleLogAppender.QUEUE_LOCK.writeLock().lock();
BlockingQueue<String> queue = ConsoleLogAppender.QUEUES.get(target);
if (queue == null) {
queue = new LinkedBlockingQueue<>();
ConsoleLogAppender.QUEUES.put(target, queue);
}
ConsoleLogAppender.QUEUE_LOCK.writeLock().unlock();
if (layout == null) {
layout = PatternLayout.createLayout(null, null, null, null, true, !Nukkit.useConsole, null, null);
}
return new ConsoleLogAppender(name, filter, layout, ignoreExceptions, queue);
}
示例7: configureLog4j
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的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");
}
示例8: setUpAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
@Before
public void setUpAppender() throws IOException {
file = folder.newFile();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig root = ((AbstractConfiguration) config).getRootLogger();
PatternLayout layout = PatternLayout.createLayout("[%p] %m%n", config, null, null, true, false, null, null);
FileAppender appender = FileAppender.createAppender(file.getAbsolutePath(), "true", "false", "TestLogFile", "true", "false", "false", "8192", layout, null, "false", null, config);
appender.start();
config.addAppender(appender);
root.addAppender(appender, null, null);
ctx.updateLoggers();
}
示例9: createAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
@PluginFactory
public static TerminalConsoleAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Filters") Filter filter,
@PluginElement("Layout") Layout<? extends Serializable> layout, @PluginAttribute("ignoreExceptions") String ignore) {
if (name == null) {
LOGGER.error("No name provided for TerminalConsoleAppender");
return null;
}
if (layout == null) {
layout = PatternLayout.createLayout(null, null, null, null, null);
}
boolean ignoreExceptions = parseBoolean(ignore, true);
// This is handled by jline
System.setProperty("log4j.skipJansi", "true");
return new TerminalConsoleAppender(name, filter, layout, ignoreExceptions);
}
示例10: createAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
@PluginFactory
public static TerminalConsoleAppender createAppender(
@PluginElement("Layout") @Nullable Layout<? extends Serializable> layout,
@PluginAttribute("name") String name,
@PluginElement("Filter") Filter filter,
@PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) boolean ignoreExceptions) {
if (name == null) {
LOGGER.error("No name provided for TerminalConsoleAppender");
return null;
}
if (layout == null) {
layout = PatternLayout.createLayout(null, null, null, null, null, false, false, null, null);
}
// This is handled by jline
System.setProperty("log4j.skipJansi", "true");
return new TerminalConsoleAppender(name, filter, layout, ignoreExceptions);
}
示例11: addFileAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
public static void addFileAppender(final String loggerPath, final File logFile, final AppConfig appConfig)
throws IOException
{
// retrieve the logger context
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
// retrieve the root logger config
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
// Define log pattern layout
PatternLayout layout = PatternLayout.createLayout(DEFAULT_LOGGER_PATTERN, null, null, null,
Charset.defaultCharset(), false, false, null, null);
// create the appenders
FileAppender fileAppender =
FileAppender.createAppender(logFile.getAbsolutePath(), "true", "false", "fileAppender",
"true", "true", "true", "8192", layout, null, "false", null, null);
fileAppender.start();
// add the appenders
loggerConfig.addAppender(fileAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
loggerContext.updateLoggers();
}
示例12: createFileAppender
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
private void createFileAppender(DiagnosticContext ctx) {
String logDir = ctx.getTempDir() + SystemProperties.fileSeparator + "diagnostics.log";
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration config = context.getConfiguration();
Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", null, config, null,
null,true, true, null, null );
Appender appender = FileAppender.createAppender(logDir, "false", "false", "File", "true",
"false", "false", "0", layout, null, "false", null, config);
appender.start();
config.addAppender(appender);
AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
AppenderRef[] refs = new AppenderRef[] {ref};
config.getRootLogger().addAppender(appender, null, null);
context.updateLoggers();
Logger testLog = LogManager.getLogger();
testLog.error("Testing");
}
示例13: testClassName
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
@Test
public void testClassName() {
final Category category = Category.getInstance("TestCategory");
final Layout<String> layout = PatternLayout.createLayout("%d %p %C{1.} [%t] %m%n", null, null, null, null);
final ListAppender appender = new ListAppender("List2", null, layout, false, false);
appender.start();
category.setAdditivity(false);
category.getLogger().addAppender(appender);
category.error("Test Message");
final List<String> msgs = appender.getMessages();
assertTrue("Incorrect number of messages. Expected 1 got " + msgs.size(), msgs.size() == 1);
final String msg = msgs.get(0);
appender.clear();
final String threadName = Thread.currentThread().getName();
final String expected = "ERROR o.a.l.CategoryTest [" + threadName + "] Test Message" + Constants.LINE_SEP;
assertTrue("Incorrect message \"" + msg + "\"" + " expected \"" + expected +"\"", msg.endsWith(expected));
}
示例14: testLog
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的package包/類
@Test
@SuppressWarnings("deprecation")
public void testLog() {
final PatternLayout layout = PatternLayout.createLayout("%d %C %L %m", null, null, null, null);
final ListAppender appender = new ListAppender("List", null, layout, false, false);
appender.start();
final Logger root = Logger.getRootLogger();
root.getLogger().addAppender(appender);
root.setLevel(Level.INFO);
final MyLogger log = new MyLogger(root);
log.logInfo("This is a test", null);
root.log(Priority.INFO, "Test msg2", null);
root.log(Priority.INFO, "Test msg3");
final List<String> msgs = appender.getMessages();
assertTrue("Incorrect number of messages", msgs.size() == 3);
final String msg = msgs.get(0);
assertTrue("Message contains incorrect class name: " + msg, msg.contains(LoggerTest.class.getName()));
appender.stop();
root.getLogger().removeAppender(appender);
}
示例15: setToDefault
import org.apache.logging.log4j.core.layout.PatternLayout; //導入方法依賴的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);
}