當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。