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


Java FileAppender.createAppender方法代码示例

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


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

示例1: addSuspectFileAppender

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的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

示例2: configureLoggers

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的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

示例3: configureLogging

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的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

示例4: setUpAppender

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
@Before
public void setUpAppender() throws IOException {
    file = folder.newFile();

    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    final LoggerConfig root = ((AbstractConfiguration) config).getRootLogger();

    PatternLayout layout = PatternLayout.createLayout("[%p] %m%n", config, null, null, true, false, null, null);
    FileAppender appender = FileAppender.createAppender(file.getAbsolutePath(), "true", "false", "TestLogFile", "true", "false", "false", "8192", layout, null, "false", null, config);

    appender.start();
    config.addAppender(appender);

    root.addAppender(appender, null, null);
    ctx.updateLoggers();
}
 
开发者ID:DjDCH,项目名称:Log4j-StaticShutdown,代码行数:18,代码来源:Log4jShutdownTest.java

示例5: addFileAppender

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
public static void addFileAppender(final String loggerPath, final File logFile, final AppConfig appConfig)
	throws IOException
{
	// retrieve the logger context
	LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
	Configuration configuration = loggerContext.getConfiguration();
	
	// retrieve the root logger config
	LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
	loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
	
	// Define log pattern layout
	PatternLayout layout = PatternLayout.createLayout(DEFAULT_LOGGER_PATTERN, null, null, null,
		Charset.defaultCharset(), false, false, null, null);
	
	// create the appenders
	FileAppender fileAppender =
		FileAppender.createAppender(logFile.getAbsolutePath(), "true", "false", "fileAppender",
			"true", "true", "true", "8192", layout, null, "false", null, null);
	fileAppender.start();
	
	// add the appenders
	loggerConfig.addAppender(fileAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
	loggerContext.updateLoggers();
}
 
开发者ID:ThreatConnect-Inc,项目名称:threatconnect-java,代码行数:26,代码来源:LoggerUtil.java

示例6: createFileAppender

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
private void createFileAppender(DiagnosticContext ctx) {

      String logDir = ctx.getTempDir() + SystemProperties.fileSeparator + "diagnostics.log";

      final LoggerContext context = (LoggerContext) LogManager.getContext(false);
      final Configuration config = context.getConfiguration();
      Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", null, config, null,
         null,true, true, null, null );
      Appender appender = FileAppender.createAppender(logDir, "false", "false", "File", "true",
         "false", "false", "0", layout, null, "false", null, config);
      appender.start();
      config.addAppender(appender);
      AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
      AppenderRef[] refs = new AppenderRef[] {ref};

      config.getRootLogger().addAppender(appender, null, null);
      context.updateLoggers();
      Logger testLog = LogManager.getLogger();
      testLog.error("Testing");
   }
 
开发者ID:elastic,项目名称:elasticsearch-support-diagnostics,代码行数:21,代码来源:Diagnostic.java

示例7: addFileLogger

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
public static String addFileLogger(String logFile) {

        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration config = ctx.getConfiguration();

        // Default log layout
        Layout<? extends Serializable> layout =
                PatternLayout.createLayout("%d %p [%t] %m%n", null, null, null, true, true, null, null);

        // Create a new file appender for the given filename
        FileAppender appender = FileAppender.createAppender(
                logFile,
                "false",
                "false",
                "FileAppender",
                "false",
                "true",
                "true",
                null,
                layout,
                null,
                null,
                null,
                config);

        appender.start();
        ((Logger) LogManager.getRootLogger()).addAppender(appender);

        return appender.getFileName();
    }
 
开发者ID:wooti,项目名称:onedrive-java-client,代码行数:31,代码来源:LogUtils.java

示例8: appendFileLogger

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
public static void appendFileLogger(Level level, String name, Path filePath) {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    Layout layout = PatternLayout.createLayout("%d{HH:mm} [%-5p] %msg%n", null, config, null, null, true, false, null, null);

    Appender appender = FileAppender.createAppender(filePath.toFile().getAbsolutePath(), "true", "false", name, "true",
            "false", "false", "8192", layout, null, "false", null, config);
    appender.start();

    config.getRootLogger().addAppender(appender, level, null);
    ctx.updateLoggers();
}
 
开发者ID:ldbc,项目名称:ldbc_graphalytics,代码行数:13,代码来源:LogUtil.java

示例9: addFileAppender

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
public static void addFileAppender(String filename) {
    if (instance == null) {
        LOGGER.error("CustomFileAppender hasn't been initalized, ignoring output "
                     + filename);
        return;
    }

    final AbstractOutputStreamAppender<? extends OutputStreamManager> appender;
    if (mmap_appender)
        appender = MemoryMappedFileAppender.createAppender(filename,
                                                           "false", filename,
                                                           "false", "8192", "false",
                                                           instance.getLayout(),
                                                           instance.getFilter(),
                                                           "false", "false",
                                                           new DefaultConfiguration());
    else
        appender = FileAppender.createAppender(filename,
                                               "false", "false",
                                               filename,
                                               "false", "false",
                                               "true", "8192",
                                               instance.getLayout(),
                                               instance.getFilter(),
                                               "false", "false",
                                               new DefaultConfiguration());

    LOGGER.info("registering custom logfile '{}'", appender);
    instance.appenders.add(appender);
}
 
开发者ID:neurord,项目名称:stochdiff,代码行数:31,代码来源:CustomFileAppender.java

示例10: addSuspectFileAppender

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的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,代码行数:27,代码来源:DUnitLauncher.java

示例11: Log4J2Configuration

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
protected Log4J2Configuration(ConfigurationSource configurationSource)
{
	super(ConfigurationSource.NULL_SOURCE);
	
	  setName("Default");
	   PatternLayout layout = PatternLayout.newBuilder().withPattern(Log4J2.DEFALT_LAYOUT).withConfiguration(this).build();
        Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
        appender.start();
        addAppender(appender);
        
        String fileName = Config.getProperty(Log4J2.class,"file","");
        String append = Boolean.TRUE.toString();
        String locking = Boolean.TRUE.toString();
        
        String immediateFlush = Boolean.TRUE.toString();
        String ignore = Boolean.TRUE.toString();
        String bufferedIo = Boolean.TRUE.toString();
        String bufferSizeStr = "8192";
        Filter filter = null;
        String advertise = null;
        String advertiseUri = null;
        
        Appender fileAppender = null;
        if(fileName.length() >  0)
        {
        	String name = Config.getProperty(Log4J2.class,"name","default");
        	
        	 fileAppender = FileAppender.createAppender(fileName, append, locking, name, immediateFlush, ignore,
        			bufferedIo, bufferSizeStr, layout, filter, advertise, advertiseUri, this);
        	 
	        fileAppender.start();
	        addAppender(fileAppender);
	  
        }
        	   
        LoggerConfig root = getRootLogger();
        root.addAppender(appender, null, null);
        if(fileAppender != null)
        {
        	root.addAppender(fileAppender, null, filter);	
        }
        
        String levelName = PropertiesUtil.getProperties().getStringProperty("org.apache.logging.log4j.level");
        Level level = levelName == null || Level.valueOf(levelName) == null ? Level.DEBUG : Level.valueOf(levelName);
        root.setLevel(level);
}
 
开发者ID:nyla-solutions,项目名称:nyla,代码行数:47,代码来源:Log4J2ConfigurationFactory.java

示例12: createFileLogger

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
/**
 * Creates a new file-logger for an addOn. The logger will log to a file with the addOnId as name in the logs folder
 * of Izou
 *
 * @param addOnId the Id of the addOn the logger is created for
 * @param level level of logger (at what level of log the logger should be activated
 * @return the new logger
 */
public synchronized ExtendedLogger createFileLogger(String addOnId, String level) {
    try {
        LoggerContext ctx = LogManager.getContext(false);
        Configuration config = ((org.apache.logging.log4j.core.LoggerContext) ctx).getConfiguration();

        //creates a new pattern layout (what determines how the log is formated, i.e. date, thread etc.)
        Layout layout = PatternLayout.createLayout("%d %-5p [%t] %C{10} (%F:%L) - %m%n", config, null, null, true,
                false, null, null);

        //creates a file appender for the logger (so that it knows what file to log to)
        Appender fileAppender = FileAppender.createAppender("logs" + File.separator + addOnId + ".log", "true",
                "false", "file", "true", "false", "false", "4000", layout, null, "false", null, config);
        fileAppender.start();
        config.addAppender(fileAppender);

        //creates also a console appender for the logger (so that the logger also outputs the log in the console)
        Appender consoleAppender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "console", null, null);
        consoleAppender.start();
        config.addAppender(consoleAppender);

        //adds appenders to an array called refs. It will later serve as references to the logger as to what
        // appenders it has
        AppenderRef fileRef = AppenderRef.createAppenderRef("file", Level.DEBUG, null);
        AppenderRef consoleRef = AppenderRef.createAppenderRef("console", Level.DEBUG, null);
        AppenderRef[] refs = new AppenderRef[]{fileRef, consoleRef};

        //creates the logger configurations for the logger, where the appender-references are also added
        LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.DEBUG, addOnId,
                "true", refs, null, config, null);
        loggerConfig.addAppender(fileAppender, Level.DEBUG, null);
        loggerConfig.addAppender(consoleAppender, Level.DEBUG, null);

        //finally creates the logger and returns it
        config.addLogger(addOnId, loggerConfig);
        ((org.apache.logging.log4j.core.LoggerContext) ctx).updateLoggers();
        ctx.getLogger(addOnId);
        ExtendedLogger logger = ctx.getLogger(addOnId);
        return logger;
    } catch(Exception e) {
        fileLogger.error("Unable to create FileLogger",e);
        return null;
    }
}
 
开发者ID:intellimate,项目名称:Izou,代码行数:52,代码来源:IzouLogger.java

示例13: mdcPattern

import org.apache.logging.log4j.core.appender.FileAppender; //导入方法依赖的package包/类
/**
 * Test case for MDC conversion pattern.
 */
@Test
public void mdcPattern() throws Exception {

    final String mdcMsgPattern1 = "%m : %X%n";
    final String mdcMsgPattern2 = "%m : %X{key1}%n";
    final String mdcMsgPattern3 = "%m : %X{key2}%n";
    final String mdcMsgPattern4 = "%m : %X{key3}%n";
    final String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";

    // set up appender
    final PatternLayout layout = PatternLayout.createLayout(msgPattern, ctx.getConfiguration(), null, null, null);
    //FileOutputStream fos = new FileOutputStream(OUTPUT_FILE + "_mdc");
    final FileAppender appender = FileAppender.createAppender(OUTPUT_FILE + "_mdc", "false", "false", "File", "false",
        "true", "false", layout, null, "false", null, null);
    appender.start();

    // 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");

    ThreadContext.put("key1", "value1");
    ThreadContext.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");

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

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

    assertTrue(Compare.compare(this.getClass(), OUTPUT_FILE + "_mdc", WITNESS_FILE + "_mdc"));

    root.removeAppender(appender);

    appender.stop();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:72,代码来源:PatternLayoutTest.java


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