當前位置: 首頁>>代碼示例>>Java>>正文


Java PatternLayoutEncoder.setCharset方法代碼示例

本文整理匯總了Java中ch.qos.logback.classic.encoder.PatternLayoutEncoder.setCharset方法的典型用法代碼示例。如果您正苦於以下問題:Java PatternLayoutEncoder.setCharset方法的具體用法?Java PatternLayoutEncoder.setCharset怎麽用?Java PatternLayoutEncoder.setCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ch.qos.logback.classic.encoder.PatternLayoutEncoder的用法示例。


在下文中一共展示了PatternLayoutEncoder.setCharset方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
protected Appender buildAppender(String name, String fileName, String pattern) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    layout.start();
    appender.setEncoder(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:25,代碼來源:DynamicLogbackLogger.java

示例2: buildDailyMaxRollingAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
protected Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    layout.start();
    appender.setEncoder(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:26,代碼來源:DynamicLogbackLogger.java

示例3: buildAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
private Appender buildAppender(String name, String fileName, String pattern) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    appender.setEncoder(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:20,代碼來源:DynamicLogbackLogger.java

示例4: buildDailyMaxRollingAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
private Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    appender.setEncoder(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:21,代碼來源:DynamicLogbackLogger.java

示例5: configure

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
public static void configure(LoggerContext loggerContext) {
    loggerContext.reset();

    StatusManager sm = loggerContext.getStatusManager();
    if (sm != null) {
        sm.add(new InfoStatus("Setting up default Pipes configuration.", loggerContext));
    }

    ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
    ca.setContext(loggerContext);
    ca.setWithJansi(true);
    ca.setName("console");

    PatternLayoutEncoder pl = new PatternLayoutEncoder();
    pl.setCharset(Charset.forName("UTF-8"));
    pl.setContext(loggerContext);
    //pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
    pl.setPattern("%msg%n");
    pl.start();

    ca.setEncoder(pl);
    ca.start();
    ch.qos.logback.classic.Logger rootLogger = loggerContext.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);
    rootLogger.addAppender(ca);
}
 
開發者ID:wmluke,項目名稱:pipes,代碼行數:27,代碼來源:LogbackConfig.java

示例6: getStdErrAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
/**
 * Create a stderr appender.
 *
 * @param context The logger context to use.
 * @return An appender writing to stderr.
 */
private static Appender<ILoggingEvent> getStdErrAppender(final LoggerContext context) {

  // Setup format
  final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
  encoder.setContext(context);
  encoder.setPattern(
      "%date{HH:mm:ss.SSS} %property{ident}[%property{pid}]: %-5level [%thread] %logger{0}: %msg%n");
  encoder.setCharset(Charsets.UTF_8);
  encoder.start();

  // Setup stderr appender
  final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
  appender.setTarget("System.err");
  appender.setName("stderr");
  appender.setEncoder(encoder);
  appender.setContext(context);
  appender.start();

  return appender;
}
 
開發者ID:spotify,項目名稱:logging-java,代碼行數:27,代碼來源:LoggingConfigurator.java

示例7: consoleAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) {
	ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	String logPattern = this.patterns.getProperty("console", CONSOLE_LOG_PATTERN);
	encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
	encoder.setCharset(UTF8);
	config.start(encoder);
	appender.setEncoder(encoder);
	config.appender("CONSOLE", appender);
	return appender;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:DefaultLogbackConfiguration.java

示例8: configure

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
/**
 * Configure logging based on a list of builders provided to it. Injects the
 * configured logging to replace the default UIMA loggers, and also sets up
 * metrics on the logging.
 *
 * @param builders
 *            The builders to use to configure the logging
 */
public void configure(List<BaleenLoggerBuilder> builders) {
	// Install JUL to SLF4J handling (JUL is default for UIMA)
	SLF4JBridgeHandler.removeHandlersForRootLogger();
	SLF4JBridgeHandler.install();

	// Configure Logback
	LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
	Logger rootLogger = context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);

	// Install the level change propagator to reduce the impact of JUL logging
	context.addListener(new LevelChangePropagator());

	// Remove all the existing appenders
	rootLogger.detachAndStopAllAppenders();

	for (BaleenLoggerBuilder builder : builders) {
		PatternLayoutEncoder ple = new PatternLayoutEncoder();
		ple.setCharset(StandardCharsets.UTF_8);
		ple.setContext(context);
		ple.setPattern(builder.getPattern());
		ple.start();

		Appender<ILoggingEvent> appender = builder.build(context, ple);
		if (!appender.isStarted()) {
			appender.start();
		}

		rootLogger.addAppender(appender);
	}

	LOGGER.debug("Adding instrumented metrics for logging");
	// Add an instrumented appender so we get the information about logging
	// through metrics
	InstrumentedAppender instrumentedAppender = new InstrumentedAppender(MetricsFactory.getInstance().getRegistry());
	instrumentedAppender.setContext(context);
	instrumentedAppender.start();
	rootLogger.addAppender(instrumentedAppender);
}
 
開發者ID:dstl,項目名稱:baleen,代碼行數:47,代碼來源:BaleenLogging.java

示例9: buildPatternLayoutEncoder

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
private PatternLayoutEncoder buildPatternLayoutEncoder(String pattern) {
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setCharset(StandardCharsets.UTF_8);
    encoder.setPattern(pattern);

    return this.buildLifeCycle(encoder, true);
}
 
開發者ID:esacinc,項目名稱:sdcct,代碼行數:8,代碼來源:LoggingInitializerRunListener.java

示例10: configureLogback

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
private static void configureLogback(Service.Instance instance) {
  final Config config = instance.getConfig();
  final int level = config.hasPath("logging.verbosity")
      ? config.getInt("logging.verbosity")
      : 0;

  final ch.qos.logback.classic.Logger
      floLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.spotify.flo");

  if (level > 1) {
    floLogger.setLevel(Level.TRACE);
  } else if (level > 0) {
    floLogger.setLevel(Level.DEBUG);
  }

  if (level > 0) {
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final ch.qos.logback.classic.Logger
        rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
        ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    final ConsoleAppender<ILoggingEvent> stdout =
        (ConsoleAppender<ILoggingEvent>) rootLogger.getAppender("STDOUT");
    final PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setPattern("%gray(%d{HH:mm:ss.SSS} %-28thread) %highlight(| %-5level| %-10logger{0}) "
                      + "%green(|>) %msg%n");
    layout.setCharset(StandardCharsets.UTF_8);
    layout.setContext(lc);
    layout.start();

    stdout.setEncoder(layout);
    stdout.start();
  }
}
 
開發者ID:spotify,項目名稱:flo,代碼行數:34,代碼來源:ConsoleLogging.java

示例11: dynamic

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
private static Logger dynamic(String name, LogLevel level) {
	// ( LoggerContext ) LoggerFactory.getILoggerFactory();
	/*
	 * String thName = Thread.currentThread().getName(); if( thName != null
	 * && !thName.trim().isEmpty() ) name = name + "_" +
	 * thName.trim().replaceAll( " ", "_" );
	 */
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	encoder.setPattern("%d{HH:mm:ss.SSS} [%thread][%-5level][%logger{36}] - %msg%n");
	encoder.setContext(context);
	encoder.setCharset(Charset.forName("UTF-8"));

	DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent> timeBasedTriggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent>();
	timeBasedTriggeringPolicy.setContext(context);

	TimeBasedRollingPolicy<ILoggingEvent> timeBasedRollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
	timeBasedRollingPolicy.setContext(context);
	String workspace = System.getenv("WORKSPACE");
	if (workspace == null)
		workspace = "";
	if (!workspace.isEmpty() && !workspace.endsWith("/"))
		workspace += "/";
	timeBasedRollingPolicy.setFileNamePattern(workspace + "logs/" + name + "-%d{yyyy-MM-dd}.log");
	timeBasedRollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(timeBasedTriggeringPolicy);

	timeBasedTriggeringPolicy.setTimeBasedRollingPolicy(timeBasedRollingPolicy);

	RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
	rollingFileAppender.setAppend(false);
	rollingFileAppender.setContext(context);
	rollingFileAppender.setEncoder(encoder);
	rollingFileAppender.setFile("logs/" + name + ".log");
	rollingFileAppender.setName(name + "Appender");
	rollingFileAppender.setPrudent(true); // set to true to release the hold
											// of log files.
	rollingFileAppender.setRollingPolicy(timeBasedRollingPolicy);
	rollingFileAppender.setTriggeringPolicy(timeBasedTriggeringPolicy);

	timeBasedRollingPolicy.setParent(rollingFileAppender);

	encoder.start();
	timeBasedRollingPolicy.start();

	rollingFileAppender.stop();
	rollingFileAppender.start();

	Logger logger = context.getLogger(name);
	logger.setLevel(level.convert());
	logger.setAdditive(false);
	logger.addAppender(rollingFileAppender);

	return logger;
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:54,代碼來源:LogUtils.java

示例12: main

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
public static void main( String[] args ) {
	// Redirect any libraries' java.util.Logging messages.
	SLF4JBridgeHandler.removeHandlersForRootLogger();
	SLF4JBridgeHandler.install();

	// Doing this here instead of in "logback.xml", allows for conditional log files.
	// For example, the app could decide not to or in a different place.

	// Fork log into a file.
	LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();

	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	encoder.setContext( lc );
	encoder.setCharset( Charset.forName( "UTF-8" ) );
	encoder.setPattern( "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" );
	encoder.start();

	FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
	fileAppender.setContext( lc );
	fileAppender.setName( "LogFile" );
	fileAppender.setFile( new File( "./modman-log.txt" ).getAbsolutePath() );
	fileAppender.setAppend( false );
	fileAppender.setEncoder( encoder );
	fileAppender.start();

	lc.getLogger( Logger.ROOT_LOGGER_NAME ).addAppender( fileAppender );

	// Log a welcome message.
	log.debug( "Started: {}", new Date() );
	log.debug( "{} v{}", APP_NAME, APP_VERSION );
	log.debug( "OS: {} {}", System.getProperty( "os.name" ), System.getProperty( "os.version" ) );
	log.debug( "VM: {}, {}, {}", System.getProperty( "java.vm.name" ), System.getProperty( "java.version" ), System.getProperty( "os.arch" ) );

	Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
		@Override
		public void uncaughtException( Thread t, Throwable e ) {
			log.error( "Uncaught exception in thread: "+ t.toString(), e );
		}
	});

	if ( args.length > 0 ) {
		SlipstreamCLI.main( args );
		return;
	}

	// Ensure all popups are triggered from the event dispatch thread.

	SwingUtilities.invokeLater(new Runnable() {
		@Override
		public void run() {
			guiInit();
		}
	});
}
 
開發者ID:Vhati,項目名稱:Slipstream-Mod-Manager,代碼行數:55,代碼來源:FTLModManager.java

示例13: initLogs

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入方法依賴的package包/類
private static void initLogs() {
    Logger logbackLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    LoggerContext lc = logbackLogger.getLoggerContext();

    Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.detachAndStopAllAppenders();

    TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
    rollingPolicy.setMaxHistory(3);
    SizeAndTimeBasedFNATP<ILoggingEvent> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<ILoggingEvent>();
    sizeAndTimeBasedFNATP.setMaxFileSize("2MB");
    rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(sizeAndTimeBasedFNATP);
    rollingPolicy.setFileNamePattern(context.getFilesDir().getPath() + "/logs/old/flickruploader.%d{yyyy-MM-dd}.%i.log");
    rollingPolicy.setContext(lc);

    RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(lc);
    fileAppender.setFile(getLogFilePath());
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.setTriggeringPolicy(rollingPolicy);
    rollingPolicy.setParent(fileAppender);

    PatternLayoutEncoder pl = new PatternLayoutEncoder();
    pl.setContext(lc);
    pl.setCharset(Charset.defaultCharset());
    pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %class{0}.%method:%L > %msg%n");
    pl.setImmediateFlush(false);
    pl.start();

    fileAppender.setEncoder(pl);
    fileAppender.setName("file");

    rollingPolicy.start();
    fileAppender.start();

    if (Config.isDebug()) {
        final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
        logcatTagPattern.setContext(lc);
        logcatTagPattern.setPattern("%class{0}");
        logcatTagPattern.start();

        final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder();
        logcatPattern.setContext(lc);
        logcatPattern.setPattern("[%thread] %method:%L > %msg%n");
        logcatPattern.start();

        final LogcatAppender logcatAppender = new LogcatAppender();
        logcatAppender.setContext(lc);
        logcatAppender.setTagEncoder(logcatTagPattern);
        logcatAppender.setEncoder(logcatPattern);
        logcatAppender.start();

        rootLogger.addAppender(logcatAppender);
    }

    rootLogger.addAppender(fileAppender);

}
 
開發者ID:rafali,項目名稱:flickr-uploader,代碼行數:59,代碼來源:FlickrUploader.java


注:本文中的ch.qos.logback.classic.encoder.PatternLayoutEncoder.setCharset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。