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


Java PatternLayout类代码示例

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


PatternLayout类属于org.apache.log4j包,在下文中一共展示了PatternLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initLogger

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
private static void initLogger() {
	Logger rootLogger = Logger.getRootLogger();
	PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");

	try {
		RollingFileAppender fileAppender = new RollingFileAppender(layout, System.getProperty("log.file", "./vnt.log"));
		fileAppender.setImmediateFlush(true);
		fileAppender.setThreshold(Level.DEBUG);
		fileAppender.setAppend(true);
		fileAppender.setMaxFileSize("5MB");
		fileAppender.setMaxBackupIndex(2);

		rootLogger.addAppender(fileAppender);
	} catch (IOException e) {
		log.error("Failed to add appender !!", e);
	}
}
 
开发者ID:crsmoro,项目名称:vntscraper,代码行数:18,代码来源:VntMain.java

示例2: initLogger

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
private RollingFileAppender initLogger(String loggerName, String filePrefix) {
  String fileName = Paths.get(rootPath, filePrefix + "." + loggerName + ".dat").toString();
  RollingFileAppender fileAppender = new RollingFileAppender();
  fileAppender.setName(loggerName);
  fileAppender.setFile(fileName);
  fileAppender.setLayout(new PatternLayout("%m%n"));
  fileAppender.setAppend(true);
  fileAppender.setMaxFileSize(maxFileSize);
  fileAppender.setMaxBackupIndex(maxFileCount);
  fileAppender.activateOptions();
  return fileAppender;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:Log4JMetricsFileWriter.java

示例3: setUpClass

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
    //Configure log4j
    ConsoleAppender console = new ConsoleAppender(); 
    String PATTERN = "%d [%p|%c|%C{1}] %m%n";
    console.setLayout(new PatternLayout(PATTERN)); 
    console.setThreshold(Level.DEBUG);
    console.activateOptions();

    Logger.getRootLogger().addAppender(console);

    System.out.println("SETUP: Starting SPLGroundControl...");
    config.init(args);

    daemon.init(new SPLGroundControl.SPLDaemonContext(args));
    daemon.start();
}
 
开发者ID:envirover,项目名称:SPLGroundControl,代码行数:18,代码来源:SPLGroungControlTest.java

示例4: setupLogging

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
private void setupLogging() {
    LogManager.getLogManager().reset();
    Logger.getRootLogger().getLoggerRepository().resetConfiguration();

    final Logger rootLogger = Logger.getRootLogger();
    final PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
    final Level level = endPointHealthConfiguration.logLevel();

    final ConsoleAppender consoleAppender = new ConsoleAppender(layout, ConsoleAppender.SYSTEM_ERR);

    consoleAppender.setThreshold(level);
    consoleAppender.activateOptions();

    final FileAppender fileAppender = new FileAppender();

    fileAppender.setFile(endPointHealthConfiguration.logFile().getAbsolutePath());
    fileAppender.setLayout(layout);
    fileAppender.setThreshold(level);
    fileAppender.setAppend(true);
    fileAppender.setErrorHandler(new FallbackAppenderErrorHandler(rootLogger, fileAppender, consoleAppender));

    rootLogger.addAppender(fileAppender);

    fileAppender.activateOptions();
}
 
开发者ID:spypunk,项目名称:endpoint-health,代码行数:26,代码来源:EndPointHealthServiceImpl.java

示例5: attachPassiveDbAppender

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
private void attachPassiveDbAppender(
                                      DbAppenderConfiguration appenderConfiguration,
                                      long timestamp ) {

    // create the new appender
    PassiveDbAppender attachedAppender = new PassiveDbAppender(ThreadsPerCaller.getCaller());

    // calculate the time stamp offset, between the test executor and the agent
    attachedAppender.calculateTimeOffset(timestamp);

    attachedAppender.setAppenderConfig(appenderConfiguration);
    // use a default pattern, as we log in the db
    attachedAppender.setLayout(new PatternLayout("%c{2}: %m%n"));
    attachedAppender.activateOptions();

    // attach the appender to the logging system
    Category log = Logger.getRootLogger();

    log.setLevel(Level.toLevel(appenderConfiguration.getLoggingThreshold().toInt()));
    log.addAppender(attachedAppender);

}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:23,代码来源:AgentConfigurationServiceImpl.java

示例6: testAsciiMessageFromEventDefaultLayout

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
@Test
public void testAsciiMessageFromEventDefaultLayout() throws Exception
{
    final long timestamp = System.currentTimeMillis();
    final String text = "test";

    LoggingEvent event = createLoggingEvent(timestamp, text, null);
    LogMessage message = new LogMessage(event, new PatternLayout());

    // the default pattern appends a newline
    String expectedText = text + "\n";

    assertEquals("timestmap",               timestamp,                      message.getTimestamp());
    assertEquals("message",                 expectedText,                   message.getMessage());
    assertArrayEquals("message as bytes",   expectedText.getBytes("UTF-8"), message.getBytes());
    assertEquals("size",                    5,                              message.size());
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:18,代码来源:TestLogMessage.java

示例7: testUnicodeMessageFromEventDefaultLayout

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
@Test
public void testUnicodeMessageFromEventDefaultLayout() throws Exception
{
    final long timestamp = System.currentTimeMillis();
    final String text = "\u0024\u00a2\u20ac";

    LoggingEvent event = createLoggingEvent(timestamp, text, null);
    LogMessage message = new LogMessage(event, new PatternLayout());

    // the default pattern appends a newline
    String expectedText = text + "\n";

    assertEquals("timestmap",               timestamp,                      message.getTimestamp());
    assertEquals("message",                 expectedText,                   message.getMessage());
    assertArrayEquals("message as bytes",   expectedText.getBytes("UTF-8"), message.getBytes());
    assertEquals("size",                    7,                              message.size());
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:18,代码来源:TestLogMessage.java

示例8: testAsciiMessageFromEventDefaultLayoutWithException

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
@Test
// at this point we'll assume that UTF-8 conversion works as expected
public void testAsciiMessageFromEventDefaultLayoutWithException() throws Exception
{
    final long timestamp = System.currentTimeMillis();
    final String text = "test";
    final Exception ex = new Exception();

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.println(text);
    ex.printStackTrace(pw);
    pw.close();
    String expectedText = sw.toString();

    LoggingEvent event = createLoggingEvent(timestamp, text, ex);
    LogMessage message = new LogMessage(event, new PatternLayout());

    assertEquals("explicit timestamp",  timestamp,      message.getTimestamp());
    assertEquals("message as string",   expectedText,   message.getMessage());
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:22,代码来源:TestLogMessage.java

示例9: setUp

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
public void setUp() {

		Logger root = Logger.getRootLogger();
		root.setLevel(Level.DEBUG);
		root.addAppender(new ConsoleAppender(
				new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
		// setup TLS properties
		System.setProperty( "javax.net.ssl.keyStore",  TlsTest.class.getResource("testkeys").getPath() );
		System.setProperty( "javax.net.ssl.trustStore", TlsTest.class.getResource("testkeys").getPath() );
		System.setProperty( "javax.net.ssl.keyStorePassword", "passphrase" );
		System.setProperty( "javax.net.ssl.keyStoreType", "jks" );
		this.shootist = new BadShootist();
		this.shootme = new BadShootme();
		shootist.setSocketDisconnectWorstCase(true);
		shootme.setSocketDisconnectWorstCase(true);
		this.shootme.init();
	}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:18,代码来源:DeadSocketTlsTest.java

示例10: main

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
public static void main(String[] args) throws TaskExecutionException {

        ConsoleAppender ca = new ConsoleAppender();
        ca.setWriter(new OutputStreamWriter(System.out));
        ca.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
        ca.setThreshold(Level.TRACE);

        logger.getRootLogger().addAppender(ca);

        final MarkLogicMonitor monitor = new MarkLogicMonitor();

        final Map<String, String> taskArgs = new HashMap<String, String>();
        taskArgs.put("config-file", "src/main/resources/conf/config.yml");
        taskArgs.put("metrics-file", "src/main/resources/conf/metrics.xml");
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        scheduler.scheduleAtFixedRate(new Runnable() {
            public void run() {
                try {
                    monitor.execute(taskArgs, null);
                } catch (Exception e) {
                    logger.error("Error while running the task", e);
                }
            }
        }, 2, 30, TimeUnit.SECONDS);
    }
 
开发者ID:Appdynamics,项目名称:marklogic-monitoring-extension,代码行数:26,代码来源:MarkLogicMonitor.java

示例11: setUpExperimentalLogger

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
private static void setUpExperimentalLogger(File pathF) throws IOException {
	
	Logger.getRootLogger().removeAllAppenders();
	log.removeAllAppenders();
	
	PropertyConfigurator.configure("resource/log4jproperties.txt");
	
	FileAppender resultAppender = new FileAppender(
			new PatternLayout("%m"),
			new File(pathF, "result.txt").toString(), false);
	
	LevelRangeFilter infoFilter = new LevelRangeFilter();
	infoFilter.setLevelMin(Level.INFO);
	infoFilter.setLevelMax(Level.FATAL);
	infoFilter.setAcceptOnMatch(true);
	resultAppender.addFilter(infoFilter);
	log.addAppender(resultAppender);
	Logger.getLogger(iBench.class).addAppender(resultAppender);
	
}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:21,代码来源:iBenchDriver.java

示例12: setUpConfigLogger

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
private static void setUpConfigLogger(File pathF, String configName) throws IOException {
	Logger.getRootLogger().removeAllAppenders();
	
	String nameSuffix = configName.replace(".txt", "");
	
	PropertyConfigurator.configure("resource/log4jproperties.txt");	
	
	FileAppender logFileAppender = new FileAppender(
			new PatternLayout("%-4r [%t] %-5p %c %x - %m%n"),
			new File(pathF, "log_" + nameSuffix + ".txt").toString(), false);
	Logger.getRootLogger().addAppender(logFileAppender);
	
	if (opt.logToConsole)
		Logger.getRootLogger().addAppender(new ConsoleAppender(
				new PatternLayout("%-4r [%t] %-5p %c %x - %m%n")));
}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:17,代码来源:iBenchDriver.java

示例13: setupLogger

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
public static void setupLogger(Config config) throws IOException {

        Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");

        Appender appender = new DailyRollingFileAppender(
                layout, config.getString("logger.file"), "'.'yyyyMMdd");

        LogManager.resetConfiguration();
        LogManager.getRootLogger().addAppender(new NullAppender());

        logger = Logger.getLogger(LOGGER_NAME);
        logger.addAppender(appender);
        logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));

        // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
        InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
            @Override
            public InternalLogger newInstance(String string) {
                return new NettyInternalLogger();
            }
        });

        Log.logSystemInfo();
        Log.info("Version: " + getAppVersion());
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:26,代码来源:Log.java

示例14: LogUtil

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
public LogUtil(LogConfig config, Object obj){
	this.logConfig = config;
	if(LogConfig.logType == 0){
		report = new ExtentReports(config.getExtentLogPath(),false);
		File configFile = new File(System.getProperty("user.dir") + "\\configs\\extent-config.xml");
		if(configFile.exists()) {
			report.loadConfig(configFile);		
		}		
		testLog = report.startTest(String.valueOf(obj));
	}else{
		logger = Logger.getLogger(String.valueOf(obj));
		Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} [%p] %c:%L �� %m%n");  
		try {
			Appender appender = new FileAppender(layout, config.getLog4jPath());
			logger.addAppender(appender);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
}
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:21,代码来源:LogUtil.java

示例15: testAppendInClose

import org.apache.log4j.PatternLayout; //导入依赖的package包/类
@Test
public void testAppendInClose() throws Exception {
  final ContainerLogAppender claAppender = new ContainerLogAppender();
  claAppender.setName("testCLA");
  claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
  claAppender.setContainerLogDir("target/testAppendInClose/logDir");
  claAppender.setContainerLogFile("syslog");
  claAppender.setTotalLogFileSize(1000);
  claAppender.activateOptions();
  final Logger claLog = Logger.getLogger("testAppendInClose-catergory");
  claLog.setAdditivity(false);
  claLog.addAppender(claAppender);
  claLog.info(new Object() {
    public String toString() {
      claLog.info("message1");
      return "return message1";
    }
  });
  claAppender.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestContainerLogAppender.java


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