当前位置: 首页>>代码示例>>Java>>正文


Java PatternLayout类代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.layout.PatternLayout的典型用法代码示例。如果您正苦于以下问题:Java PatternLayout类的具体用法?Java PatternLayout怎么用?Java PatternLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PatternLayout类属于org.apache.logging.log4j.core.layout包,在下文中一共展示了PatternLayout类的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);
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:32,代码来源:ConsoleAppender.java

示例2: createAppender

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
/**
 * Factory method. Log4j will parse the configuration and call this factory
 * method to construct the appender with
 * the configured attributes.
 *
 * @param name Name of appender
 * @param layout Log layout of appender
 * @param filter Filter for appender
 * @return The TextAreaAppender
 */
@PluginFactory
public static TextAreaAppender createAppender(
	@PluginAttribute("name")
		String name,
	@PluginElement("Layout")
		Layout<? extends Serializable> layout,
	@PluginElement("Filter")
	final Filter filter) {
	if (name == null) {
		LOGGER.error("No name provided for TextAreaAppender");
		return null;
	}
	if (layout == null) {
		layout = PatternLayout.createDefaultLayout();
	}
	return new TextAreaAppender(name, filter, layout, true);
}
 
开发者ID:HearthProject,项目名称:OneClient,代码行数:28,代码来源:TextAreaAppender.java

示例3: watch

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
public void watch(Class<?> loggerClass, Level level) {
    this.loggerClass = loggerClass;
    Appender appender = new AbstractAppender(APPENDER_NAME, null, PatternLayout.createDefaultLayout()) {
        @Override
        public void append(LogEvent event) {
            logEvents.add(event);
        }
    };
    appender.start();
    final LoggerContext ctx = getLoggerContext();
    LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(loggerClass.getName());
    oldLevel = loggerConfig.getLevel();
    loggerConfig.setLevel(level);
    loggerConfig.addAppender(appender, level, null);
    ctx.updateLoggers();
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:17,代码来源:LogTestRule.java

示例4: 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);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:DUnitLauncher.java

示例5: 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);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:22,代码来源:TerminalConsoleAppender.java

示例6: 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();
}
 
开发者ID:kartoFlane,项目名称:hiervis,代码行数:27,代码来源:HierarchyVisualizer.java

示例7: ProcessCallable

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
public ProcessCallable(MCRSession session, Session webSocketSession) {
    this.commands = new ObservableCommandList();
    this.session = session;
    this.webSocketSession = webSocketSession;
    this.logs = new ObservableLogEventDeque();
    this.logGrabber = new Log4JGrabber(MCRWebCLIContainer.class.getSimpleName() + session.getID(), null,
        PatternLayout.createDefaultLayout());
    this.logGrabber.start();

    this.commandListObserver = new CommandListObserver(commands, webSocketSession);
    commands.addObserver(commandListObserver);
    this.logEventQueueObserver = new LogEventDequeObserver(logs, webSocketSession);
    logs.addObserver(logEventQueueObserver);
    this.currentCommand = "";
    this.continueIfOneFails = false;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:17,代码来源:MCRWebCLIContainer.java

示例8: addFileAppender

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
private static void addFileAppender() throws IOException {
  final String tempDir = System.getProperty("java.io.tmpdir");
  final File logFile = new File(tempDir, "meghanada_server.log");
  final LoggerContext context = (LoggerContext) LogManager.getContext(false);
  final Configuration configuration = context.getConfiguration();
  final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
  final FileAppender fileAppender =
      FileAppender.newBuilder()
          .withName("file")
          .withLayout(
              PatternLayout.newBuilder()
                  .withPattern("[%d][%-5.-5p][%-14.-14c{1}:%4L] %-22.-22M - %m%n")
                  .build())
          .withFileName(logFile.getCanonicalPath())
          .build();
  configuration.addAppender(fileAppender);
  loggerConfig.addAppender(fileAppender, Level.ERROR, null);
  context.updateLoggers();
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:20,代码来源:Main.java

示例9: createLayout

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
public static PatternLayout createLayout(String logFormat) throws ReflectiveOperationException {
    try {
        Method builder = PatternLayout.class
                .getDeclaredMethod("createLayout", String.class, Configuration.class, RegexReplacement.class
                        , String.class, String.class);

        return (PatternLayout) builder.invoke(null, logFormat, new DefaultConfiguration(), null
                , Charset.defaultCharset().name(), "true");
    } catch (NoSuchMethodException methodEx) {
        return PatternLayout.newBuilder()
                .withCharset(Charset.defaultCharset())
                .withPattern(logFormat)
                .withConfiguration(new DefaultConfiguration())
                .withAlwaysWriteExceptions(true)
                .build();
    }
}
 
开发者ID:games647,项目名称:ColorConsole,代码行数:18,代码来源:CommonLogInstaller.java

示例10: updateLogConfig

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
/**
 * Update the log configuration based on command line options
 * 
 * @param cl
 */
protected final void updateLogConfig(CommandLine cl) {
	String logFile = cl.getOptionValue(OPT_LOG_FILE.getLongOpt(), null);
	String logLevel = cl.getOptionValue(OPT_LOG_LEVEL.getLongOpt(), null);
	if (logFile != null || logLevel != null) {
		logFile = logFile != null ? logFile : getDefaultLogFileName();
		logLevel = logLevel != null ? logLevel : DEFAULT_LOG_LEVEL;
		LoggerContext context = (LoggerContext) LogManager.getContext(false);
	    Configuration configuration = context.getConfiguration();
	    FileAppender appender = FileAppender.newBuilder()
	    		.withName("File")
	    		.withFileName(logFile)
	    		.withLayout(PatternLayout.newBuilder().withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN).build())
	    		.withAppend(false)
	    		.build();
	    appender.start();
	    configuration.getRootLogger().addAppender(appender, Level.getLevel(logLevel), null);
	    configuration.getRootLogger().setLevel(Level.getLevel(logLevel));
	    context.updateLoggers();
	}
}
 
开发者ID:fod-dev,项目名称:FoDBugTrackerUtility,代码行数:26,代码来源:RunProcessRunnerFromCLI.java

示例11: newInstance

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
/**
 * Creates a new instance of the class. Required by Log4J2.
 *
 * @param config the configuration
 * @param options the options
 * @return a new instance, or {@code null} if the options are invalid
 */
public static ColorConverter newInstance(Configuration config, String[] options) {
	if (options.length < 1) {
		LOGGER.error("Incorrect number of options on style. "
				+ "Expected at least 1, received {}", options.length);
		return null;
	}
	if (options[0] == null) {
		LOGGER.error("No pattern supplied on style");
		return null;
	}
	PatternParser parser = PatternLayout.createPatternParser(config);
	List<PatternFormatter> formatters = parser.parse(options[0]);
	AnsiElement element = (options.length == 1 ? null : ELEMENTS.get(options[1]));
	return new ColorConverter(formatters, element);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:ColorConverter.java

示例12: 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();
}
 
开发者ID:Steve973,项目名称:camel-standalone,代码行数:18,代码来源:Standalone.java

示例13: SimpleJSONLayout

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
protected SimpleJSONLayout(final Configuration config, final boolean locationInfo,
		final boolean properties, final boolean complete, final boolean eventEol,
		final String headerPattern, final String footerPattern, final Charset charset,
		final KeyValuePair[] additionalFields) {
	super(config, charset, //
			PatternLayout.newSerializerBuilder() //
					.setConfiguration(config).setReplace(null).setPattern(headerPattern) //
					.setDefaultPattern(DEFAULT_HEADER) //
					.setPatternSelector(null).setAlwaysWriteExceptions(false).setNoConsoleNoAnsi(false) //
					.build(), //
			PatternLayout.newSerializerBuilder() //
					.setConfiguration(config).setReplace(null).setPattern(footerPattern) //
					.setDefaultPattern(DEFAULT_FOOTER) //
					.setPatternSelector(null).setAlwaysWriteExceptions(false).setNoConsoleNoAnsi(false) //
					.build());
	this.locationInfo = locationInfo;
	this.properties = properties;
	this.complete = complete;
	this.additionalFields = additionalFields;
	this.layoutStartTime = System.currentTimeMillis();
	this.layoutSequence = new AtomicLong();
	this.interpolator = new Interpolator(new MapLookup(getConfiguration().getProperties()),
			getConfiguration().getPluginPackages());
	this.eol = !eventEol ? COMPACT_EOL : DEFAULT_EOL;
}
 
开发者ID:ggrandes,项目名称:log4j2-simplejson,代码行数:26,代码来源:SimpleJSONLayout.java

示例14: 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);
}
 
开发者ID:MagicDroidX,项目名称:Brynhildr,代码行数:23,代码来源:ConsoleLogAppender.java

示例15: createAppender

import org.apache.logging.log4j.core.layout.PatternLayout; //导入依赖的package包/类
@PluginFactory
public static WorkspaceLogAppender createAppender(@PluginAttribute("name") String name,
                                                  @PluginElement("Layout") Layout<? extends Serializable> layout,
                                                  @PluginElement("Filter") final Filter filter) {

    if (name == null) {
        LOGGER.error("No name provided for WorkspaceLogAppender");
        return null;
    }

    if (layout == null) {
        layout = PatternLayout.createDefaultLayout();
    }

    return new WorkspaceLogAppender(name, filter, layout, true);
}
 
开发者ID:PlayPen,项目名称:PVI,代码行数:17,代码来源:WorkspaceLogAppender.java


注:本文中的org.apache.logging.log4j.core.layout.PatternLayout类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。