本文整理汇总了Java中net.logstash.logback.composite.loggingevent.LogLevelJsonProvider类的典型用法代码示例。如果您正苦于以下问题:Java LogLevelJsonProvider类的具体用法?Java LogLevelJsonProvider怎么用?Java LogLevelJsonProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogLevelJsonProvider类属于net.logstash.logback.composite.loggingevent包,在下文中一共展示了LogLevelJsonProvider类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEncoder
import net.logstash.logback.composite.loggingevent.LogLevelJsonProvider; //导入依赖的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;
}
示例2: overrideLogLevelProvider
import net.logstash.logback.composite.loggingevent.LogLevelJsonProvider; //导入依赖的package包/类
@Test
public void overrideLogLevelProvider() {
SixtJsonEncoder encoder = new SixtJsonEncoder();
JsonProviders<ILoggingEvent> providers = encoder.getProviders();
int defaultCount = 0;
int overrideCount = 0;
for (JsonProvider<ILoggingEvent> provider : providers.getProviders()) {
if (provider instanceof LogLevelJsonProvider &&
!(provider instanceof CustomLogLevelJsonProvider)) {
defaultCount++;
} else if (provider instanceof CustomLogLevelJsonProvider) {
overrideCount++;
}
}
assertThat(defaultCount).isEqualTo(0);
assertThat(overrideCount).isEqualTo(1);
}
示例3: build
import net.logstash.logback.composite.loggingevent.LogLevelJsonProvider; //导入依赖的package包/类
public Appender<ILoggingEvent> build(
LoggerContext context,
String applicationName,
LayoutFactory<ILoggingEvent> layoutFactory,
LevelFilterFactory<ILoggingEvent> levelFilterFactory,
AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory
) {
final LoggingEventCompositeJsonEncoder encoder = new LoggingEventCompositeJsonEncoder();
encoder.setContext(context);
encoder.getProviders().addProvider(withPattern("{ \"type\": \"system\" }", new LoggingEventPatternJsonProvider(), context));
encoder.getProviders().addProvider(withName("timestamp", new LoggingEventFormattedTimestampJsonProvider(), context));
encoder.getProviders().addProvider(new LogLevelJsonProvider() );
encoder.getProviders().addProvider(new MessageJsonProvider() );
encoder.getProviders().addProvider(new StackTraceJsonProvider() );
encoder.start();
final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setContext(context);
appender.setEncoder(encoder);
appender.start();
return wrapAsync(appender, asyncAppenderFactory);
}
示例4: removeDefaultProvider
import net.logstash.logback.composite.loggingevent.LogLevelJsonProvider; //导入依赖的package包/类
private void removeDefaultProvider(LoggingEventJsonProviders providers) {
JsonProvider<ILoggingEvent> providerToDelete = null;
for (JsonProvider<ILoggingEvent> provider : providers.getProviders()) {
if (provider instanceof LogLevelJsonProvider) {
providerToDelete = provider;
break;
}
}
providers.removeProvider(providerToDelete);
}