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


Java PatternLayoutEncoder.setContext方法代码示例

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


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

示例1: WebSocketLogAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
public WebSocketLogAppender(String sessionId) {
    // deliberately NOT the com.intuit form else will pick up all those
    // this is supposed to isolate user-session s
    this.sessionId = sessionId;
    logger = (Logger) LoggerFactory.getLogger(sessionId);
    sb = new StringBuilder();
    setName("karate-web");
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    setContext(lc);
    encoder = new PatternLayoutEncoder();
    encoder.setPattern("%d{HH:mm:ss.SSS} %-5level - %msg%n");
    encoder.setContext(context);
    encoder.start();
    start();
    logger.addAppender(this);
    logger.setLevel(Level.DEBUG);
}
 
开发者ID:intuit,项目名称:karate,代码行数:18,代码来源:WebSocketLogAppender.java

示例2: configureInMemoryLogging

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
private static void configureInMemoryLogging() {
    org.slf4j.Logger rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    Logger logbackRootLogger = (Logger) rootLogger;
    logbackRootLogger.setLevel(Level.INFO);

    OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<>();
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern("[%date] [%level] [%logger{10}] %msg%n");
    ple.setContext(lc);
    ple.start();
    try {
        ple.init(bos);
    } catch (IOException e) {
    }
    appender.setContext(lc);
    appender.setOutputStream(bos);
    appender.setName("buffered");
    appender.setEncoder(ple);
    appender.start();

    logbackRootLogger.detachAppender("console");
    logbackRootLogger.addAppender(appender);
    logbackRootLogger.setAdditive(true);
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:26,代码来源:Cli.java

示例3: log

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
@Test
public void log() throws Exception {
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext context = logger.getLoggerContext();
    context.reset();

    Map<String, String> ruleRegistry = (Map) context.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
    if (ruleRegistry == null) {
        ruleRegistry = new HashMap<String, String>();
        context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, ruleRegistry);
    }
    ruleRegistry.put("ex1L", OnelineThrowableProxyConverter.class.getCanonicalName());

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%d{yyyy/MM/dd HH:mm:ss:SSS}\\t%-5level\\t%msg\\t%ex1L");
    encoder.start();

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(context);
    appender.setEncoder(encoder);
    appender.start();
    logger.addAppender(appender);

    logger.error("error", new RuntimeException("foo"));
}
 
开发者ID:roundrop,项目名称:logback-oneline-converter,代码行数:27,代码来源:OnelineThrowableProxyConverterTest.java

示例4: addAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
/**
 * Start a specific file logging, typically for the processing of a given book.
 *
 * @param name      appender name (typically the book radix)
 * @param logFolder target folder where the log file is to be written
 */
public static void addAppender (String name,
                                Path logFolder)
{
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
            Logger.ROOT_LOGGER_NAME);
    FileAppender fileAppender = new FileAppender();
    PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
    fileAppender.setName(name);
    fileAppender.setContext(loggerContext);
    fileAppender.setAppend(false);

    String now = new SimpleDateFormat("yyyyMMdd'T'HHmm").format(new Date());
    Path logFile = logFolder.resolve(name + "-" + now + ".log");
    fileAppender.setFile(logFile.toAbsolutePath().toString());
    fileEncoder.setContext(loggerContext);
    fileEncoder.setPattern("%date %level [%X{BOOK}%X{SHEET}] %25file:%-4line | %msg%n%ex");
    fileEncoder.start();
    fileAppender.setEncoder(fileEncoder);
    fileAppender.start();
    root.addAppender(fileAppender);
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:29,代码来源:LogUtil.java

示例5: addFileAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
/**
 * Add a specific appender meant for FILE.
 */
public static void addFileAppender ()
{
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
            Logger.ROOT_LOGGER_NAME);
    FileAppender fileAppender = new FileAppender();
    PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
    fileAppender.setName("FILE");
    fileAppender.setContext(loggerContext);
    fileAppender.setAppend(false);

    String now = new SimpleDateFormat("yyyyMMdd'T'HHmmss").format(new Date());
    Path logPath = WellKnowns.LOG_FOLDER.resolve(now + ".log").toAbsolutePath();
    fileAppender.setFile(logPath.toString());
    fileEncoder.setContext(loggerContext);
    fileEncoder.setPattern("%date %-5level [%X{BOOK}%X{SHEET}] %25replace(%file){'\\.java$',''} %-4line | %msg%n%ex");
    fileEncoder.start();
    fileAppender.setEncoder(fileEncoder);
    fileAppender.start();
    root.addAppender(fileAppender);

    System.out.println("LogUtil. Logging to " + logPath);
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:27,代码来源:LogUtil.java

示例6: buildFileAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
public FileAppender<ILoggingEvent> buildFileAppender(LoggerContext context, String file) {
  FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
  fileAppender.setFile(file);
  fileAppender.setContext(context);
  fileAppender.setPrudent(true);

  PatternLayoutEncoder encoder = new PatternLayoutEncoder();
  encoder.setContext(context);
  encoder.setPattern(primaryConfiguration.getLoggingPattern().or(baseConfiguration.getLoggingPattern()).or(JavaUtils.LOGBACK_LOGGING_PATTERN));
  encoder.start();

  fileAppender.setEncoder(encoder);
  fileAppender.start();

  return fileAppender;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:17,代码来源:SingularityRunnerBaseLogging.java

示例7: logToFile

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
static void logToFile(Parameters parameters) {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();

    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
    fileAppender.setFile(parameters.getWorkingDirectory() + "/jlineup.log");
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();

    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    logger.addAppender(fileAppender);
    logger.setLevel(Level.DEBUG);
}
 
开发者ID:otto-de,项目名称:jlineup,代码行数:18,代码来源:Util.java

示例8: configure

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
public static void configure(KonkerLoggerContext lc) {
    StatusManager sm = lc.getStatusManager();
    if(sm != null) {
        sm.add(new InfoStatus("Setting up default configuration.", lc));
    }

    ConsoleAppender ca = new ConsoleAppender();
    ca.setContext(lc);
    ca.setName("console");
    PatternLayoutEncoder pl = new PatternLayoutEncoder();
    pl.setContext(lc);
    pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
    pl.start();
    ca.setEncoder(pl);
    ca.start();
    KonkerLogger rootLogger = lc.getLogger("ROOT");
    rootLogger.addAppender(ca);
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:19,代码来源:KonkerLoggerBasicConfigurator.java

示例9: build

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
@Override
public Appender<ILoggingEvent> build(LoggerContext context, String s, Layout<ILoggingEvent> layout) {
    Preconditions.checkNotNull(context);
    WiretapAppender appender = new WiretapAppender();

    final PatternLayoutEncoder patternEncoder = new PatternLayoutEncoder();
    patternEncoder.setContext(context);
    patternEncoder.setPattern("%-5p [%thread] [%d] %c: %m%n%rEx");
    patternEncoder.start();

    appender.setContext(context);
    appender.setName("wiretap-appender");
    appender.setEncoder(patternEncoder);

    addThresholdFilter(appender, threshold);
    appender.start();

    return wrapAsync(appender);
}
 
开发者ID:Quiq,项目名称:dropwizard-wiretap,代码行数:20,代码来源:WiretapAppenderFactory.java

示例10: buildAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
@Override
public Appender<ILoggingEvent> buildAppender(Context logcingContext, String fileName) throws JoranException {
    // first sets up the paterns for log layout
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setPattern(logTemplate);
    encoder.setContext(logcingContext);
    encoder.start();
    // then create a file appender for the given filename
    FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
    appender.setContext(logcingContext);
    appender.setAppend(false);
    appender.setFile(logFolderName + "/" + fileName + ".log");
    appender.setEncoder(encoder);
    appender.start();

    return appender;
}
 
开发者ID:IRIT-SMAC,项目名称:agent-tooling,代码行数:18,代码来源:AgentLog.java

示例11: createLogger

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
/**
 * Creates a new logger.
 *
 * @param name a name for the logger
 * @param level the logging level for the logger
 * @param file the file to output all logging to
 * @return the created logger
 */
public static Logger createLogger(String name, Level level, String file) {
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
  PatternLayoutEncoder ple = new PatternLayoutEncoder();
  ple.setPattern("%date %level [%thread] %logger{10} [%file:%line]%n%msg%n%n");
  ple.setContext(lc);
  ple.start();
  FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
  fileAppender.setFile(file);
  fileAppender.setEncoder(ple);
  fileAppender.setAppend(false);
  fileAppender.setContext(lc);
  fileAppender.start();
  logger = (Logger) LoggerFactory.getLogger(name);
  logger.detachAndStopAllAppenders(); // detach console (doesn't seem to work)
  logger.addAppender(fileAppender); // attach file appender
  logger.setLevel(level);
  logger.setAdditive(true); // set to true if root should log too

  return logger;
}
 
开发者ID:agentsoz,项目名称:jill,代码行数:29,代码来源:Log.java

示例12: buildLoggerContext

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
static LoggerContext buildLoggerContext(String stamp, String filename,
    boolean safetyMode) {
  LoggerContext loggerContext = new LoggerContext();

  FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();

  PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
  patternLayout.setPattern(stamp + " %5p - %m%n");
  patternLayout.setContext(loggerContext);
  patternLayout.start();

  fa.setEncoder(patternLayout);
  fa.setFile(filename);
  fa.setAppend(true);
  fa.setPrudent(safetyMode);
  fa.setContext(loggerContext);
  fa.start();

  ch.qos.logback.classic.Logger root = loggerContext
      .getLogger(Logger.ROOT_LOGGER_NAME);
  root.addAppender(fa);

  return loggerContext;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:25,代码来源:SafeModeFileAppender.java

示例13: configureLogbackDirectly

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
private static void configureLogbackDirectly() {
    // reset the default context (which may already have been initialized)
    // since we want to reconfigure it
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();

    // setup LogcatAppender
    PatternLayoutEncoder encoder2 = new PatternLayoutEncoder();
    encoder2.setContext(lc);
    encoder2.setPattern("[%thread] %msg%n");
    encoder2.start();

    LogcatAppender logcatAppender = new LogcatAppender();
    logcatAppender.setContext(lc);
    logcatAppender.setEncoder(encoder2);
    logcatAppender.start();

    // backup the newly created appenders to the root logger;
    // qualify Logger to disambiguate from org.slf4j.Logger
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.addAppender(logcatAppender);

    root.setLevel(Level.ALL);
}
 
开发者ID:kejunxia,项目名称:AndroidMvc,代码行数:25,代码来源:BaseTestCase.java

示例14: getLogger

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
public Logger getLogger() {
    LoggerContext  context = (LoggerContext)LoggerFactory.getILoggerFactory();
    Logger rootLogger = context.getLogger("ROOT");
    rootLogger.detachAppender("console");

    // Just a simple pattern for outputting the messages, includes the ISO8601 formatted timestamp and marker.
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%msg");
    encoder.start();

    RollingFileAppender appender = new RollingFileAppender<>();
    appender.setContext(context);
    appender.setRollingPolicy(new ExternalRotateRollingPolicy());
    appender.getRollingPolicy().setParent(appender);
    appender.setFile(new File(folder.getRoot(), "log").getAbsolutePath());

    appender.setEncoder(encoder);
    appender.start();
    rootLogger.addAppender(appender);
    context.start();
    return rootLogger;

}
 
开发者ID:ezbake,项目名称:ezbake-common-java,代码行数:25,代码来源:TestExternalRotateRollingPolicy.java

示例15: main

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //导入方法依赖的package包/类
static public void main(String[] args) throws Exception {
  Logger rootLogger = (Logger) LoggerFactory.getLogger("root");
  LoggerContext loggerContext = rootLogger.getLoggerContext();
  loggerContext.reset();
  
  PatternLayoutEncoder encoder = new PatternLayoutEncoder();
  encoder.setContext(loggerContext);
  encoder.setPattern("%-5level [%thread]: %message%n");
  encoder.start();
  
  ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
  appender.setContext(loggerContext);
  appender.setEncoder(encoder);
  appender.start();
  
  rootLogger.addAppender(appender);

  rootLogger.debug("Message 1");
  rootLogger.warn("Message 2");
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:21,代码来源:PatternSample.java


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