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


Java PatternLayout.setConversionPattern方法代码示例

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


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

示例1: testNonDefaultSerde

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
@Test
public void testNonDefaultSerde() {
  System.setProperty("samza.container.name", "samza-container-1");
  String streamName = StreamAppender.getStreamName("log4jTest", "1");
  Map<String, String> map = new HashMap<String, String>();
  map.put("job.name", "log4jTest");
  map.put("job.id", "1");
  map.put("serializers.registry.log4j-string.class", LoggingEventStringSerdeFactory.class.getCanonicalName());
  map.put("systems.mock.samza.factory", MockSystemFactory.class.getCanonicalName());
  map.put("systems.mock.streams." + streamName + ".samza.msg.serde", "log4j-string");
  map.put("task.log4j.system", "mock");
  MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender(new MapConfig(map));
  PatternLayout layout = new PatternLayout();
  layout.setConversionPattern("%m");
  systemProducerAppender.setLayout(layout);
  systemProducerAppender.activateOptions();
  assertNotNull(systemProducerAppender.getSerde());
  assertEquals(LoggingEventStringSerde.class, systemProducerAppender.getSerde().getClass());
}
 
开发者ID:apache,项目名称:samza,代码行数:20,代码来源:TestStreamAppender.java

示例2: testSystemProducerAppenderInAM

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
@Test
public void testSystemProducerAppenderInAM() throws InterruptedException {
  System.setProperty("samza.container.name", "samza-job-coordinator");

  MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
  PatternLayout layout = new PatternLayout();
  layout.setConversionPattern("%m");
  systemProducerAppender.setLayout(layout);
  systemProducerAppender.activateOptions();
  log.addAppender(systemProducerAppender);

  log.info("no-received"); // System isn't initialized yet, so this message should be dropped

  systemProducerAppender.setupSystem();
  MockSystemProducerAppender.systemInitialized = true;

  List<String> messages = Lists.newArrayList("testing3", "testing4");
  logAndVerifyMessages(messages);
}
 
开发者ID:apache,项目名称:samza,代码行数:20,代码来源:TestStreamAppender.java

示例3: errorOnlyConsole

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
public static void errorOnlyConsole() {
  LogManager.resetConfiguration();

  final PatternLayout layout = new PatternLayout();
  layout.setConversionPattern("%-5p %c %x: %m%n");

  final ConsoleAppender dst = new ConsoleAppender();
  dst.setLayout(layout);
  dst.setTarget("System.err");
  dst.setThreshold(Level.ERROR);
  dst.activateOptions();

  final Logger root = LogManager.getRootLogger();
  root.removeAllAppenders();
  root.addAppender(dst);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:ErrorLogFile.java

示例4: getLogger

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
/**
    * 
    * Get logger for logging execution status of the running job
    * 
    * @param jobID
    * @param fileLogLocation
    * @return {@link Logger}
    */
public Logger getLogger(String jobID,String fileLogLocation) {
	
	if (executionTrackingLoggers.containsKey(jobID)) {
		return executionTrackingLoggers.get(jobID);
	}
	
	//creates pattern layout
	PatternLayout layout = new PatternLayout();
	layout.setConversionPattern("%m%n");
	
	//create file appender
	FileAppender fileAppender = new FileAppender();
	fileAppender.setFile(fileLogLocation);
	fileAppender.setLayout(layout);
	fileAppender.activateOptions();
	//configures the root logger
	
	Logger logger = Logger.getLogger(jobID);
	logger.setLevel(Level.DEBUG);
	logger.addAppender(fileAppender);
	logger.getRootLogger().setAdditivity(false);
	logger.setAdditivity(false);
	executionTrackingLoggers.put(jobID, logger);
	
       return logger;
   }
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:35,代码来源:ExecutionTrackingLogger.java

示例5: initializeLogger

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
private void initializeLogger()
{
	
	DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM");
	Date date = new Date();
	String curDate = dateFormat.format(date);
	MethodAnalysis meth = new MethodAnalysis();

	String filename = meth.getFilePath()+"logs/SCM_logFile_"+curDate+".log";//+"_"+log_number+".log";
    try
    {
    	 PatternLayout layout = new PatternLayout(); 
    	 layout.setConversionPattern("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
         appender =  new RollingFileAppender();
         appender.setAppend(true);
         appender.setMaxFileSize("10MB");
         appender.setMaxBackupIndex(2);
         appender.setFile(filename);
         appender.setLayout(layout);
         appender.activateOptions(); 
         LOGGER.addAppender(appender);
        
    }
    catch(Exception e)
    {
    	
    	System.out.println("Exception in loading the logger in the Home");
    }
}
 
开发者ID:ccaicedo,项目名称:SCMBAT,代码行数:30,代码来源:Home.java

示例6: configureLogging

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
public static void configureLogging() {
    String fileName = MultiValueConfigLoader.getConfig("LOGGER-file");
    String maxFileSize = MultiValueConfigLoader.getConfig("LOGGER-maxLogSize", "10MB");
    int maxBackups = Integer.parseInt(MultiValueConfigLoader.getConfig("LOGGER-maxBackups", "5"));
    String logLevel = MultiValueConfigLoader.getConfig("LOGGER-level", "DEBUG");
    String logPattern = MultiValueConfigLoader.getConfig("LOGGER-logPattern", DEFAULT_PATTERN);

    Appender stdoutAppender = Logger.getRootLogger().getAppender("stdout");
    if (stdoutAppender != null) {
        PatternLayout layout = new PatternLayout();
        layout.setConversionPattern(logPattern);
        stdoutAppender.setLayout(layout);
    }
    setupTextFileLogger(fileName, maxFileSize, maxBackups, logLevel, logPattern);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:16,代码来源:LogManager.java

示例7: configureStdoutLayout

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
/**
 * Shell output doesn't need to be fancy, just the message and a line break
 */
private void configureStdoutLayout() {
    Appender stdoutAppender = Logger.getRootLogger().getAppender("stdout");
    PatternLayout p = new PatternLayout();
    p.setConversionPattern("%m%n");
    stdoutAppender.setLayout(p);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:10,代码来源:PluginShell.java

示例8: getAppender

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
private static Appender getAppender() {
    if (appender == null) {
        PatternLayout patternLayout = new PatternLayout();
        patternLayout.setConversionPattern("%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c{1}:%L - %m%n");
        appender = new LambdaAppender();
        appender.setLayout(patternLayout);
    }
    return appender;
}
 
开发者ID:lambadaframework,项目名称:lambadaframework,代码行数:10,代码来源:LambdaLogger.java

示例9: ActivityLogger

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
/**
 * Constructeur.
 * @param engineName le nom de l'engine de l'activité
 */
ActivityLogger(final String engineName) {
	Assertion.checkArgNotEmpty(engineName);
	// ---
	// Creates or get the logger
	if (LogManager.exists(engineName) != null) {
		// If it exist we keep it
		loggerActivity = Logger.getLogger(engineName);
	} else {
		Logger tempLogger = null;
		try {
			// If it doesn't exist we create it with the right appender
			tempLogger = Logger.getLogger(engineName);
			// Create the layout
			final PatternLayout layout = new PatternLayout();
			layout.setConversionPattern("%d{yyyyMMdd} %d{HH:mm:ss} [%t] %-5p %-11c{1} - %m %x %n");
			// Create an appender
			final Appender appender = new FileAppender(layout, engineName + LOG_FILE_EXTENSION);
			tempLogger.addAppender(appender);
		} catch (final IOException e) {
			LOGGER.warn("Error creating the file appender for activity engine :" + engineName, e);
			tempLogger = LOGGER;
		} finally {
			loggerActivity = tempLogger;
		}

	}
}
 
开发者ID:KleeGroup,项目名称:alpha-pfm,代码行数:32,代码来源:ActivityLogger.java

示例10: testDefaultSerde

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
@Test
public void testDefaultSerde() {
  System.setProperty("samza.container.name", "samza-container-1");
  MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
  PatternLayout layout = new PatternLayout();
  layout.setConversionPattern("%m");
  systemProducerAppender.setLayout(layout);
  systemProducerAppender.activateOptions();
  assertNotNull(systemProducerAppender.getSerde());
  assertEquals(LoggingEventJsonSerde.class, systemProducerAppender.getSerde().getClass());
}
 
开发者ID:apache,项目名称:samza,代码行数:12,代码来源:TestStreamAppender.java

示例11: testSystemProducerAppenderInContainer

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
@Test
public void testSystemProducerAppenderInContainer() throws InterruptedException {
  System.setProperty("samza.container.name", "samza-container-1");

  MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
  PatternLayout layout = new PatternLayout();
  layout.setConversionPattern("%m");
  systemProducerAppender.setLayout(layout);
  systemProducerAppender.activateOptions();
  log.addAppender(systemProducerAppender);

  List<String> messages = Lists.newArrayList("testing1", "testing2");
  logAndVerifyMessages(messages);
}
 
开发者ID:apache,项目名称:samza,代码行数:15,代码来源:TestStreamAppender.java

示例12: testExceptionsDoNotKillTransferThread

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
@Test
public void testExceptionsDoNotKillTransferThread() throws InterruptedException {
  System.setProperty("samza.container.name", "samza-container-1");

  MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
  PatternLayout layout = new PatternLayout();
  layout.setConversionPattern("%m");
  systemProducerAppender.setLayout(layout);
  systemProducerAppender.activateOptions();
  log.addAppender(systemProducerAppender);

  List<String> messages = Lists.newArrayList("testing5", "testing6", "testing7");

  // Set up latch
  final CountDownLatch allMessagesSent = new CountDownLatch(messages.size());
  MockSystemProducer.listeners.add((source, envelope) -> {
      allMessagesSent.countDown();
      if (allMessagesSent.getCount() == messages.size() - 1) {
        throw new RuntimeException(); // Throw on the first message
      }
    });

  // Log the messages
  messages.forEach((message) -> log.info(message));

  // Wait for messages
  assertTrue("Thread did not send all messages. Count: " + allMessagesSent.getCount(),
      allMessagesSent.await(60, TimeUnit.SECONDS));
}
 
开发者ID:apache,项目名称:samza,代码行数:30,代码来源:TestStreamAppender.java

示例13: setDefaultLayout

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
private void setDefaultLayout() {
    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setConversionPattern(PatternLayout.TTCC_CONVERSION_PATTERN);
    layout = patternLayout;
}
 
开发者ID:marviq,项目名称:log4j-appender-jira,代码行数:6,代码来源:JIRALog4jAppender.java

示例14: main

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
public static void main(String[] args) throws TwitterException {
    PatternLayout layoutStandard = new PatternLayout();
    layoutStandard.setConversionPattern("[%p] %d %c %M - %m%n");

    PatternLayout layoutSimple = new PatternLayout();
    layoutSimple.setConversionPattern("%m%n");

    // Filter for the statuses: we only want INFO messages
    LevelRangeFilter filter = new LevelRangeFilter();
    filter.setLevelMax(Level.INFO);
    filter.setLevelMin(Level.INFO);
    filter.setAcceptOnMatch(true);
    filter.activateOptions();

    TimeBasedRollingPolicy statusesRollingPolicy = new TimeBasedRollingPolicy();
    statusesRollingPolicy.setFileNamePattern("statuses.log" + HOUR_ROLL);
    statusesRollingPolicy.activateOptions();

    RollingFileAppender statusesAppender = new RollingFileAppender();
    statusesAppender.setRollingPolicy(statusesRollingPolicy);
    statusesAppender.addFilter(filter);
    statusesAppender.setLayout(layoutSimple);
    statusesAppender.activateOptions();

    TimeBasedRollingPolicy warningsRollingPolicy = new TimeBasedRollingPolicy();
    warningsRollingPolicy.setFileNamePattern("warnings.log" + HOUR_ROLL);
    warningsRollingPolicy.activateOptions();

    RollingFileAppender warningsAppender = new RollingFileAppender();
    warningsAppender.setRollingPolicy(statusesRollingPolicy);
    warningsAppender.setThreshold(Level.WARN);
    warningsAppender.setLayout(layoutStandard);
    warningsAppender.activateOptions();

    ConsoleAppender consoleAppender = new ConsoleAppender();
    consoleAppender.setThreshold(Level.WARN);
    consoleAppender.setLayout(layoutStandard);
    consoleAppender.activateOptions();

    // configures the root logger
    Logger rootLogger = Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    rootLogger.removeAllAppenders();
    rootLogger.addAppender(consoleAppender);
    rootLogger.addAppender(statusesAppender);
    rootLogger.addAppender(warningsAppender);

    // creates a custom logger and log messages
    final Logger logger = Logger.getLogger(SimpleStreamCollector.class);

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    RawStreamListener rawListener = new RawStreamListener() {

        @Override
        public void onMessage(String rawString) {
            cnt++;
            logger.info(rawString);
            if (cnt % 1000 == 0) {
                System.out.println(cnt + " messages received.");
            }
        }

        @Override
        public void onException(Exception ex) {
            logger.warn(ex);
        }

    };

    twitterStream.addListener(rawListener);
    twitterStream.sample();
}
 
开发者ID:Remper,项目名称:sociallink,代码行数:73,代码来源:SimpleStreamCollector.java

示例15: mdcPattern

import org.apache.log4j.PatternLayout; //导入方法依赖的package包/类
/**
  Test case for MDC conversion pattern. */
public void mdcPattern() throws Exception {
  
  String mdcMsgPattern1 = "%m : %X%n";
  String mdcMsgPattern2 = "%m : %X{key1}%n";
  String mdcMsgPattern3 = "%m : %X{key2}%n";
  String mdcMsgPattern4 = "%m : %X{key3}%n";
  String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
  
  // set up appender
  PatternLayout layout = new PatternLayout(msgPattern);
  Appender appender = new FileAppender(layout, OUTPUT_FILE+"_mdc", false);
          
  // set appender on root and set level to debug
  root.addAppender(appender);
  root.setLevel(Level.DEBUG);
  
  // output starting message
  root.debug("starting mdc pattern test");
 
  layout.setConversionPattern(mdcMsgPattern1);
  root.debug("empty mdc, no key specified in pattern");
  
  layout.setConversionPattern(mdcMsgPattern2);
  root.debug("empty mdc, key1 in pattern");
  
  layout.setConversionPattern(mdcMsgPattern3);
  root.debug("empty mdc, key2 in pattern");
  
  layout.setConversionPattern(mdcMsgPattern4);
  root.debug("empty mdc, key3 in pattern");
  
  layout.setConversionPattern(mdcMsgPattern5);
  root.debug("empty mdc, key1, key2, and key3 in pattern");

  MDC.put("key1", "value1");
  MDC.put("key2", "value2");

  layout.setConversionPattern(mdcMsgPattern1);
  root.debug("filled mdc, no key specified in pattern");
  
  layout.setConversionPattern(mdcMsgPattern2);
  root.debug("filled mdc, key1 in pattern");
  
  layout.setConversionPattern(mdcMsgPattern3);
  root.debug("filled mdc, key2 in pattern");
  
  layout.setConversionPattern(mdcMsgPattern4);
  root.debug("filled mdc, key3 in pattern");
  
  layout.setConversionPattern(mdcMsgPattern5);
  root.debug("filled mdc, key1, key2, and key3 in pattern");

  MDC.remove("key1");
  MDC.remove("key2");

  layout.setConversionPattern(msgPattern);
  root.debug("finished mdc pattern test");

  assertTrue(Compare.compare(OUTPUT_FILE+"_mdc", WITNESS_FILE+"_mdc"));
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:63,代码来源:PatternParserTestCase.java


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