ch.qos.logback.classic.Logger类的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(456)

本文整理了Java中ch.qos.logback.classic.Logger类的一些代码示例,展示了Logger类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger类的具体详情如下:
包路径:ch.qos.logback.classic.Logger
类名称:Logger

Logger介绍

暂无

代码示例

代码示例来源:origin: jamesdbloom/mockserver

public static void setRootLogLevel(String name) {
  Logger logger = LoggerFactory.getLogger(name);
  try {
    Class.forName("ch.qos.logback.classic.Logger");
    if (logger instanceof ch.qos.logback.classic.Logger) {
      ((ch.qos.logback.classic.Logger) logger).setLevel(
        ch.qos.logback.classic.Level.valueOf(System.getProperty("root.logLevel", "WARN"))
      );
    }
  } catch (ClassNotFoundException ignore) {
  }
}

代码示例来源:origin: springside/springside4

/**
 * 将此appender添加到logger中.
 */
public void addToLogger(Class<?> loggerClass) {
  Logger logger = (Logger) LoggerFactory.getLogger(loggerClass);
  logger.addAppender(this);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
protected LoggerLevel getLevel() {
 ch.qos.logback.classic.Logger logback = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
 switch (logback.getLevel().levelInt) {
  case Level.TRACE_INT:
   return LoggerLevel.TRACE;
  case Level.DEBUG_INT:
   return LoggerLevel.DEBUG;
  default:
   return LoggerLevel.INFO;
 }
}

代码示例来源:origin: ch.qos.logback/logback-classic

void recursiveReset() {
  detachAndStopAllAppenders();
  localLevelReset();
  additive = true;
  if (childrenList == null) {
    return;
  }
  for (Logger childLogger : childrenList) {
    childLogger.recursiveReset();
  }
}

代码示例来源:origin: org.springframework.boot/spring-boot

public void logger(String name, Level level, boolean additive,
    Appender<ILoggingEvent> appender) {
  Logger logger = this.context.getLogger(name);
  if (level != null) {
    logger.setLevel(level);
  }
  logger.setAdditive(additive);
  if (appender != null) {
    logger.addAppender(appender);
  }
}

代码示例来源:origin: ch.qos.logback/logback-classic

public LoggerContext() {
  super();
  this.loggerCache = new ConcurrentHashMap<String, Logger>();
  this.loggerContextRemoteView = new LoggerContextVO(this);
  this.root = new Logger(Logger.ROOT_LOGGER_NAME, null, this);
  this.root.setLevel(Level.DEBUG);
  loggerCache.put(Logger.ROOT_LOGGER_NAME, root);
  initEvaluatorMap();
  size = 1;
  this.frameworkPackages = new ArrayList<String>();
}

代码示例来源:origin: ch.qos.logback/logback-examples

static void programmaticConfiguration() {
  // Configure logback
  LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
  loggerContext.reset();
  PatternLayoutEncoder layout = new PatternLayoutEncoder();
  layout.setContext(loggerContext);
  layout.setPattern("%X{first} %X{last} - %m%n");
  layout.start();
  ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
  appender.setContext(loggerContext);
  appender.setEncoder(layout);
  appender.start();
  // cast root logger to c.q.logback.classic.Logger so that we can attach
  // an appender to it
  ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("root");
  root.addAppender(appender);
}

代码示例来源:origin: SonarSource/sonarqube

private void verifyJmxLogLevel(LoggerContext ctx, Level expected) {
 assertThat(ctx.getLogger("javax.management.remote.timeout").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("javax.management.remote.misc").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("javax.management.remote.rmi").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("javax.management.mbeanserver").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("sun.rmi.loader").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("sun.rmi.transport.tcp").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("sun.rmi.transport.misc").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("sun.rmi.server.call").getLevel()).isEqualTo(expected);
 assertThat(ctx.getLogger("sun.rmi.dgc").getLevel()).isEqualTo(expected);
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

/**
   * Programmatically (i.e. not in XML) create a Logback logger for requests happening on this router.
   * http://stackoverflow.com/a/17215011/778449
   */
  private static Logger createLogger(String file) {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern("%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
    fileAppender.setFile(file);
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();
    Logger logger = (Logger) LoggerFactory.getLogger("REQ_LOG");
    logger.addAppender(fileAppender);
    logger.setLevel(Level.INFO);
    logger.setAdditive(false);
    return logger;
  }
}

代码示例来源:origin: dropwizard/dropwizard

@Override
  public RequestLog build(String name) {
    final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
    logger.setAdditive(false);

    final LoggerContext context = logger.getLoggerContext();

    final LogbackAccessRequestLog requestLog = new LogbackAccessRequestLog();

    final LevelFilterFactory<IAccessEvent> levelFilterFactory = new NullLevelFilterFactory<>();
    final AsyncAppenderFactory<IAccessEvent> asyncAppenderFactory = new AsyncAccessEventAppenderFactory();
    final LayoutFactory<IAccessEvent> layoutFactory = new LogbackAccessRequestLayoutFactory();

    for (AppenderFactory<IAccessEvent> output : appenders) {
      requestLog.addAppender(output.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }

    return requestLog;
  }
}

代码示例来源:origin: spotify/helios

(ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
final LoggerContext context = rootLogger.getLoggerContext();
context.reset();
final PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setContext(context);
ple.setPattern("%d{HH:mm:ss.SSS} %-5level %logger{1} %F:%L - %msg%n");
ple.start();
fileAppender.start();
rootLogger.setLevel(Level.DEBUG);
rootLogger.addAppender(fileAppender);

代码示例来源:origin: SonarSource/sonarqube

private static void setCustomRootAppender(LoggingConfiguration conf) {
 Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
 String level = StringUtils.defaultIfBlank(conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), LoggingConfiguration.LEVEL_ROOT_DEFAULT);
 if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) {
  logger.detachAndStopAllAppenders();
  logger.addAppender(createAppender(conf.getLogOutput()));
 }
 logger.setLevel(Level.toLevel(level));
}

代码示例来源:origin: ch.qos.logback/logback-classic

/**
   * After serialization, the logger instance does not know its LoggerContext.
   * The best we can do here, is to return a logger with the same name
   * returned by org.slf4j.LoggerFactory.
   * 
   * @return Logger instance with the same name
   * @throws ObjectStreamException
   */
  protected Object readResolve() throws ObjectStreamException {
    return LoggerFactory.getLogger(getName());
  }
}

代码示例来源:origin: ctripcorp/apollo

private void tryConfigCLogging() throws Exception {
 String appId = Foundation.app().getAppId();
 if (Strings.isNullOrEmpty(appId)) {
  logger.warn("App id is null or empty!");
  return;
 }
 LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
 Class clazz = Class.forName(cLoggingAppenderClass);
 Appender cLoggingAppender = (Appender) clazz.newInstance();
 ReflectionUtils.findMethod(clazz, "setAppId", String.class).invoke(cLoggingAppender, appId);
 ReflectionUtils.findMethod(clazz, "setServerIp", String.class)
   .invoke(cLoggingAppender, cloggingUrl());
 ReflectionUtils.findMethod(clazz, "setServerPort", int.class)
   .invoke(cLoggingAppender, Integer.parseInt(cloggingPort()));
 cLoggingAppender.setName("CentralLogging");
 cLoggingAppender.setContext(loggerContext);
 cLoggingAppender.start();
 ch.qos.logback.classic.Logger logger =
   (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("root");
 logger.addAppender(cLoggingAppender);
}

代码示例来源:origin: gocd/gocd

private void initializeLoggerForPluginId(String pluginId) {
  if (alreadyInitialized(pluginId)) {
    return;
  }
  synchronized (pluginId.intern()) {
    if (alreadyInitialized(pluginId)) {
      return;
    }
    synchronized (appenderCreationLock) {
      FileAppender<ILoggingEvent> pluginAppender = getAppender(pluginId);
      ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(PLUGIN_LOGGER_PREFIX + "." + pluginId);
      logger.setAdditive(false);
      logger.setLevel(systemEnvironment.pluginLoggingLevel(pluginId));
      logger.addAppender(pluginAppender);
      if (systemEnvironment.consoleOutToStdout()) {
        ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
        consoleAppender.setEncoder(LogHelper.encoder("%d{ISO8601} %5p [%t] %c{1}:%L [plugin-" + pluginId + "] - %m%n"));
        logger.setAdditive(false);
        logger.setLevel(systemEnvironment.pluginLoggingLevel(pluginId));
        consoleAppender.start();
        logger.addAppender(consoleAppender);
      }
      loggingServiceLogger.debug("Plugin with ID: " + pluginId + " will log to: " + pluginAppender.rawFileProperty());
    }
  }
}

代码示例来源:origin: ch.qos.logback/logback-examples

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

代码示例来源:origin: skylot/jadx

public static void register() {
  Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
  LoggerContext loggerContext = rootLogger.getLoggerContext();
  PatternLayout layout = new PatternLayout();
  layout.setContext(loggerContext);
  layout.setPattern("%-5level: %msg%n");
  layout.start();
  INSTANCE.setContext(loggerContext);
  INSTANCE.setLayout(layout);
  INSTANCE.start();
  rootLogger.addAppender(INSTANCE);
}

代码示例来源:origin: SonarSource/sonarqube

public LoggerContext getRootContext() {
 org.slf4j.Logger logger;
 while (!((logger = LoggerFactory.getLogger(ROOT_LOGGER_NAME)) instanceof Logger)) {
  // It occurs when the initialization step is still not finished because of a race condition
  // on ILoggerFactory.getILoggerFactory
  // http://jira.qos.ch/browse/SLF4J-167
  // Substitute loggers are used.
  // http://www.slf4j.org/codes.html#substituteLogger
  // Bug is not fixed in SLF4J 1.7.14.
  try {
   Thread.sleep(10);
  } catch (InterruptedException e) {
   Thread.currentThread().interrupt();
  }
 }
 return ((Logger) logger).getLoggerContext();
}

代码示例来源:origin: tinyMediaManager/tinyMediaManager

private TmmUILogCollector() {
 Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
 // create a new TmmUILogAppender - so we need not to put it in the logback.xml:
 PatternLayoutEncoder encoder = new PatternLayoutEncoder();
 encoder.setContext(rootLogger.getLoggerContext());
 encoder.setPattern("%d{HH:mm:ss.SSS} %-5level %logger{60} - %msg%n");
 encoder.start();
 logAppender = new TmmUILogAppender();
 logAppender.setContext(rootLogger.getLoggerContext());
 logAppender.setEncoder(encoder);
 logAppender.start();
 rootLogger.addAppender(logAppender);
}

代码示例来源:origin: line/armeria

@Before
public void setUp() {
  rootLogger.getLoggerContext().getStatusManager().clear();
  MDC.clear();
  testLogger = (Logger) LoggerFactory.getLogger("loggerTest." + testName.getMethodName());
  testLogger.setLevel(Level.ALL);
}

相关文章