org.apache.logging.log4j.core.pattern.PatternConverter Java Examples

The following examples show how to use org.apache.logging.log4j.core.pattern.PatternConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PatternProcessor.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 * @param pattern The file pattern.
 */
public PatternProcessor(final String pattern) {
    this.pattern = pattern;
    final PatternParser parser = createPatternParser();
    // FIXME: this seems to expect List<ArrayPatternConverter> in practice; types need to be fixed around this
    final List<PatternConverter> converters = new ArrayList<>();
    final List<FormattingInfo> fields = new ArrayList<>();
    parser.parse(pattern, converters, fields, false, false, false);
    final FormattingInfo[] infoArray = new FormattingInfo[fields.size()];
    patternFields = fields.toArray(infoArray);
    final ArrayPatternConverter[] converterArray = new ArrayPatternConverter[converters.size()];
    patternConverters = converters.toArray(converterArray);
    this.fileExtension = FileExtension.lookupForFile(pattern);

    for (final ArrayPatternConverter converter : patternConverters) {
        // TODO: extract common interface
        if (converter instanceof DatePatternConverter) {
            final DatePatternConverter dateConverter = (DatePatternConverter) converter;
            frequency = calculateFrequency(dateConverter.getPattern());
        } else if (converter instanceof FileDatePatternConverter) {
            frequency = calculateFrequency(((FileDatePatternConverter) converter).getPattern());
        }
    }
}
 
Example #2
Source File: LogTest.java    From x-pipe with Apache License 2.0 3 votes vote down vote up
@Test
public void testPlugin(){
	
	PluginManager pm = new PluginManager(PatternConverter.CATEGORY);
	pm.collectPlugins();
	for(Entry<String, PluginType<?>> entry : pm.getPlugins().entrySet()){
		
		logger.info("{} : {}", entry.getKey(), entry.getValue());
		
	}
	
	logger.error("[testPlugin]", new IOException("io exception message..."));
}