本文整理汇总了Java中ch.qos.logback.classic.LoggerContext类的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext类的具体用法?Java LoggerContext怎么用?Java LoggerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoggerContext类属于ch.qos.logback.classic包,在下文中一共展示了LoggerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUdpSender
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@Test
public void testUdpSender() throws JoranException, InterruptedException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(this.getClass().getClassLoader().getResourceAsStream("logback-syslog-udp.xml"));
Logger logger = context.getLogger("test-udp");
logger.info("test message over udp");
context.stop();
Thread.sleep(100);
final String serverData = serverStream.toString();
assertTrue("Server received: " + serverData, serverData.contains("test message over udp"));
}
示例2: initializeLogback
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@PostConstruct
public void initializeLogback() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
InputStream is = InitLogback.class.getClassLoader().getResourceAsStream("tasfe-logback.xml");
if (is == null)
return;
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
try {
configurator.doConfigure(is);
} catch (JoranException e) {
e.printStackTrace();
}
}
示例3: getEncoder
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
/**
* Get a {@link LoggingEventCompositeJsonEncoder}. The returned appender
* adds a timestamp field and sets the type to "servicelog" if serviceLog is
* true. If set to false, we return a request log appender which sets the
* timestamp field internally to guarantee that timestamp of the request log
* event and the resultant json structure stay in sync.
* @param loggerContext to use for setup
* @param serviceLog return appender for service logs if true, else return one for request logs
* @return corresponding {@link LoggingEventCompositeJsonEncoder}
*/
static LoggingEventCompositeJsonEncoder getEncoder(
final LoggerContext loggerContext, final boolean serviceLog) {
final LoggingEventCompositeJsonEncoder jsonEncoder = new LoggingEventCompositeJsonEncoder();
jsonEncoder.setContext(loggerContext);
final LoggingEventJsonProviders jsonProviders = getCommonJsonProviders(loggerContext);
final GlobalCustomFieldsJsonProvider<ILoggingEvent> customFieldsJsonProvider
= new GlobalCustomFieldsJsonProvider<>();
if (serviceLog) {
final LoggingEventFormattedTimestampJsonProvider timeStampProvider
= new LoggingEventFormattedTimestampJsonProvider();
timeStampProvider.setTimeZone(DateTimeZone.UTC.getID());
timeStampProvider.setFieldName("timestamp");
jsonProviders.addTimestamp(timeStampProvider);
customFieldsJsonProvider.setCustomFields("{\"type\":\"servicelog\"}");
} else {
customFieldsJsonProvider.setCustomFields("{\"type\":\"requestlog\"}");
}
jsonProviders.addGlobalCustomFields(customFieldsJsonProvider);
jsonProviders.addStackTrace(new StackTraceJsonProvider());
jsonProviders.addLogLevel(new LogLevelJsonProvider());
jsonEncoder.setProviders(jsonProviders);
jsonEncoder.start();
return jsonEncoder;
}
示例4: execute
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
static int execute(JetGatlingOptions options) {
String workingDir = System.getProperty("user.dir");
GatlingPropertiesBuilder builder = new GatlingPropertiesBuilder();
builder.simulationClass(SIMULATION);
builder.dataDirectory(workingDir);
builder.bodiesDirectory(workingDir);
builder.mute();
if (options.getTimeout() > -1) {
System.setProperty("gatling.http.ahc.readTimeout", String.valueOf(options.getTimeout()));
}
if (options.isDebug() || options.isTrace()) {
Level logLevel = options.isTrace() ? Level.TRACE : Level.DEBUG;
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.getLogger("io.gatling.http.ahc").setLevel(logLevel);
loggerContext.getLogger("io.gatling.http.response").setLevel(logLevel);
loggerContext.getLogger("io.gatling.app").setLevel(logLevel);
loggerContext.getLogger("com.github.scw1109.jetgatling").setLevel(logLevel);
}
return Gatling.fromMap(builder.build());
}
示例5: setUp
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
registry = RegistryService.getMetricRegistry();
TagEncodedMetricName rootName = APPENDS_BASE_NAME;
TagEncodedMetricName throwablesBaseName = THROWABLES_BASE_NAME;
meters = new HashMap<>();
meters.put("total", getMeter(rootName.submetric("total")));
meters.put("trace", getMeter(rootName.withTags("level", "trace")));
meters.put("debug", getMeter(rootName.withTags("level", "debug")));
meters.put("info", getMeter(rootName.withTags("level", "info")));
meters.put("warn", getMeter(rootName.withTags("level", "warn")));
meters.put("error", getMeter(rootName.withTags("level", "error")));
meters.put("throwCount", getMeter(throwablesBaseName.submetric("total")));
meters.put("throw[RuntimeException]",
getMeter(throwablesBaseName.withTags("class", RuntimeException.class.getName())
));
LoggerContext context = new LoggerContext();
logger = context.getLogger(LogbackInstrumentationTest.class);
origLevel = logger.getLevel();
logger.setLevel(Level.ALL);
}
示例6: WebSocketLogAppender
import ch.qos.logback.classic.LoggerContext; //导入依赖的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);
}
示例7: init
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@Before
public void init()
{
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
ctx.reset();
this.layoutProducer = new LayoutProducer();
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setLayout(layoutProducer);
appender.setContext(ctx);
appender.start();
Logger basicLogger = ctx.getLogger(LogFmtTest.class);
basicLogger.addAppender(appender);
this.logger = LogFmt.from(basicLogger);
ctx.start();
}
示例8: addLogstashAppender
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
public void addLogstashAppender(LoggerContext context) {
log.info("Initializing Logstash logging");
LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
logstashAppender.setName("LOGSTASH");
logstashAppender.setContext(context);
String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
"\"instance_id\":\"" + instanceId + "\"}";
// Set the Logstash appender config from JHipster properties
logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
logstashAppender.setCustomFields(customFields);
// Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
throwableConverter.setMaxLength(7500);
throwableConverter.setRootCauseFirst(true);
logstashAppender.setThrowableConverter(throwableConverter);
logstashAppender.start();
// Wrap the appender in an Async appender for performance
AsyncAppender asyncLogstashAppender = new AsyncAppender();
asyncLogstashAppender.setContext(context);
asyncLogstashAppender.setName("ASYNC_LOGSTASH");
asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
asyncLogstashAppender.addAppender(logstashAppender);
asyncLogstashAppender.start();
context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
示例9: getList
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@GetMapping("/logs")
@Timed
public List<LoggerVM> getList() {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
return context.getLoggerList()
.stream()
.map(LoggerVM::new)
.collect(Collectors.toList());
}
示例10: setupLoggingStdoutOnly
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
/**
* Set up logback logging for service and request logs. We use only ONE appender here to write
* normal log lines to stdout for both types. Logging context is set from the keys and values
* parameters. They must be corresponding in length and all elements must be non-null and
* non-empty. However, the request logger is set up slightly differently. To guarantee that
* everything works as expected this method must be called with the fully qualified class name
* of the request logger that will be used in jetty.
* @param keys to add to all log lines
* @param values to add to all log lines
* @param requestLoggerName the request logger class name
* @param json true for json output, false for plain test
*/
public static void setupLoggingStdoutOnly(
final String[] keys,
final String[] values,
final String requestLoggerName,
final boolean json) {
if(!parametersOk(keys, values)) {
throw new IllegalArgumentException(
"Context keys and/or values are not properly formatted.");
}
final LoggerContext loggerContext = getLoggerContext(keys, values);
final Appender<ILoggingEvent> consoleAppender = json
? createJsonConsoleAppender(SERVICE_CONSOLE_APPENDER, loggerContext, true)
: createPatternLayoutConsoleAppender(SERVICE_CONSOLE_APPENDER, loggerContext, true);
// specifically cast to logback version so we set it up
final Logger rootLogger = (Logger) LoggerFactory.getLogger(
org.slf4j.Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(consoleAppender);
rootLogger.setLevel(LOG_LEVEL);
if (!Strings.isNullOrEmpty(requestLoggerName)) {
final Logger requestLogger = (Logger) LoggerFactory.getLogger(requestLoggerName);
requestLogger
.addAppender(json
? createJsonConsoleAppender(
REQUESTLOG_CONSOLE_APPENDER, loggerContext, false)
: createPatternLayoutConsoleAppender(
REQUESTLOG_CONSOLE_APPENDER, loggerContext, false));
requestLogger.setAdditive(false);
requestLogger.setLevel(LOG_LEVEL);
}
}
示例11: getCommonJsonProviders
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
private static LoggingEventJsonProviders getCommonJsonProviders(
final LoggerContext loggerContext) {
final LoggingEventJsonProviders jsonProviders = new LoggingEventJsonProviders();
jsonProviders.addPattern(new LoggingEventPatternJsonProvider());
jsonProviders.addArguments(new ArgumentsJsonProvider());
jsonProviders.addMessage(new MessageJsonProvider());
jsonProviders.addContext(new ContextJsonProvider<ILoggingEvent>());
jsonProviders.addMdc(new MdcJsonProvider());
jsonProviders.setContext(loggerContext);
return jsonProviders;
}
示例12: changeLevel
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@RequestMapping(value = "/logs",
method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
@Timed
public void changeLevel(@RequestBody LoggerDTO jsonLogger) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.getLogger(jsonLogger.getName()).setLevel(Level.valueOf(jsonLogger.getLevel()));
}
示例13: figureOutLogBackConfig
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
/**
* figure out the logback's configuration: for example, appenders' file path, buff io, etc...
*
* @param context
* @param webapploader
*/
private void figureOutLogBackConfig(HookContext context, ClassLoader webapploader) {
Logger logback = (Logger) LoggerFactory.getLogger(LogBackHookProxy.class);
InterceptContext interceptContext = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
if (interceptContext == null) {
logback.warn("No InterceptContext available, can't figure out LogBack configuration.");
return;
}
@SuppressWarnings("unchecked")
LinkedList<LogProfileInfo> list = (LinkedList<LogProfileInfo>) interceptContext
.get(HookConstants.LOG_PROFILE_LIST);
if (null == list) {
list = new LinkedList<LogProfileInfo>();
interceptContext.put(HookConstants.LOG_PROFILE_LIST, list);
}
String appid = (String) (interceptContext.get(InterceptConstants.CONTEXTPATH));
// figureour all loggers
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
List<ch.qos.logback.classic.Logger> loggers = loggerContext.getLoggerList();
for (Logger logger : loggers) {
figureoutLogConfiguration(logger, list, appid);
}
}
示例14: changeLevel
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@PutMapping("/logs")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Timed
public void changeLevel(@RequestBody LoggerVM jsonLogger) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.getLogger(jsonLogger.getName()).setLevel(Level.valueOf(jsonLogger.getLevel()));
}
示例15: configure
import ch.qos.logback.classic.LoggerContext; //导入依赖的package包/类
@Override
public void configure(LoggerContext loggerContext) {
addInfo("Setting up default configuration.");
DefaultConsoleAppender consoleAppender = new DefaultConsoleAppender();
consoleAppender.setContext(loggerContext);
consoleAppender.setName("CONSOLE");
consoleAppender.start();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(consoleAppender);
}