本文整理汇总了Java中ch.qos.logback.core.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于ch.qos.logback.core包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDefaultValues
import ch.qos.logback.core.Context; //导入依赖的package包/类
@Test
public void testDefaultValues() {
final Context mockContext = mock(Context.class);
final PutLogEventsResult mockResult = mock(PutLogEventsResult.class);
when(mockResult.getNextSequenceToken()).thenReturn("2");
final AWSLogs mockAwsLogs = mock(AWSLogs.class);
when(mockAwsLogs.putLogEvents(any())).thenReturn(mockResult);
final CloudWatchAppender appender = new CloudWatchAppender();
appender.setContext(mockContext);
appender.setAwsLogs(mockAwsLogs);
appender.start();
appender.doAppend(new LoggingEvent());
appender.stop();
}
示例2: testAlreadyExists
import ch.qos.logback.core.Context; //导入依赖的package包/类
@Test
public void testAlreadyExists() {
final Context mockContext = mock(Context.class);
final PutLogEventsResult mockResult = mock(PutLogEventsResult.class);
when(mockResult.getNextSequenceToken()).thenReturn("2");
final AWSLogs mockAwsLogs = mock(AWSLogs.class);
when(mockAwsLogs.createLogGroup(any())).thenThrow(ResourceAlreadyExistsException.class);
when(mockAwsLogs.createLogStream(any())).thenThrow(ResourceAlreadyExistsException.class);
when(mockAwsLogs.putLogEvents(any())).thenReturn(mockResult);
final CloudWatchAppender appender = new CloudWatchAppender();
appender.setContext(mockContext);
appender.setAwsLogs(mockAwsLogs);
appender.start();
appender.doAppend(new LoggingEvent());
appender.stop();
}
示例3: getEffectiveConverterMap
import ch.qos.logback.core.Context; //导入依赖的package包/类
/**
* Returns a map where the default converter map is merged with the map
* contained in the context.
*/
public Map<String, String> getEffectiveConverterMap() {
Map<String, String> effectiveMap = new HashMap<String, String>();
// add the least specific map fist
Map<String, String> defaultMap = getDefaultConverterMap();
if (defaultMap != null) {
effectiveMap.putAll(defaultMap);
}
// contextMap is more specific than the default map
Context context = getContext();
if (context != null) {
@SuppressWarnings("unchecked")
Map<String, String> contextMap = (Map<String, String>) context
.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
if (contextMap != null) {
effectiveMap.putAll(contextMap);
}
}
// set the most specific map last
effectiveMap.putAll(instanceConverterMap);
return effectiveMap;
}
示例4: printInCaseOfErrorsOrWarnings
import ch.qos.logback.core.Context; //导入依赖的package包/类
/**
* Print the contents of the context status, but only if they contain
* warnings or errors occurring later then the threshold.
*
* @param context
*/
public static void printInCaseOfErrorsOrWarnings(Context context, long threshold) {
if (context == null) {
throw new IllegalArgumentException("Context argument cannot be null");
}
StatusManager sm = context.getStatusManager();
if (sm == null) {
ps.println("WARN: Context named \"" + context.getName()
+ "\" has no status manager");
} else {
StatusUtil statusUtil = new StatusUtil(context);
if (statusUtil.getHighestLevel(threshold) >= ErrorStatus.WARN) {
print(sm, threshold);
}
}
}
示例5: printIfErrorsOccured
import ch.qos.logback.core.Context; //导入依赖的package包/类
/**
* Print the contents of the context statuses, but only if they contain
* errors.
*
* @param context
*/
public static void printIfErrorsOccured(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context argument cannot be null");
}
StatusManager sm = context.getStatusManager();
if (sm == null) {
ps.println("WARN: Context named \"" + context.getName()
+ "\" has no status manager");
} else {
StatusUtil statusUtil = new StatusUtil(context);
if (statusUtil.getHighestLevel(0) == ErrorStatus.ERROR) {
print(sm);
}
}
}
示例6: getEffectiveConverterMap
import ch.qos.logback.core.Context; //导入依赖的package包/类
/**
* Returns a map where the default converter map is merged with the map
* contained in the context.
*/
public Map<String, String> getEffectiveConverterMap() {
Map<String, String> effectiveMap = new HashMap<String, String>();
// add the least specific map fist
Map<String, String> defaultMap = getDefaultConverterMap();
if (defaultMap != null) {
effectiveMap.putAll(defaultMap);
}
// contextMap is more specific than the default map
Context context = getContext();
if (context != null) {
@SuppressWarnings("unchecked")
Map<String, String> contextMap = (Map<String, String>) context
.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
if (contextMap != null) {
effectiveMap.putAll(contextMap);
}
}
return effectiveMap;
}
示例7: buildFruit
import ch.qos.logback.core.Context; //导入依赖的package包/类
public Fruit buildFruit() {
Context context = new ContextBase();
this.fruit = null;
context.putProperty("fruitKey", "orange-"+count);
// for next round
count++;
FruitConfigurator fruitConfigurator = new FruitConfigurator(this);
fruitConfigurator.setContext(context);
try {
fruitConfigurator.doConfigure(eventList);
} catch(JoranException je) {
je.printStackTrace();
}
return fruit;
}
示例8: main
import ch.qos.logback.core.Context; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Context context = new ContextBase();
Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();
// we start with the rule for the top-most (root) element
ruleMap.put(new ElementSelector("*/foo"), new NOPAction());
// Add an implicit action.
List<ImplicitAction> iaList = new ArrayList<ImplicitAction>();
iaList.add(new PrintMeImplicitAction());
SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap,
iaList);
// link the configurator with its context
simpleConfigurator.setContext(context);
simpleConfigurator.doConfigure(args[0]);
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
示例9: main
import ch.qos.logback.core.Context; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Context context = new ContextBase();
Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();
// we start with the rule for the top-most (root) element
ruleMap.put(new ElementSelector("*/computation"), new ComputationAction1());
// Associate "/new-rule" pattern with NewRuleAction from the
// org.apache.joran.action package.
//
// We will let the XML file to teach the Joran interpreter about new rules
ruleMap.put(new ElementSelector("/computation/newRule"), new NewRuleAction());
SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
// link the configurator with its context
simpleConfigurator.setContext(context);
simpleConfigurator.doConfigure(args[0]);
// Print any errors that might have occured.
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
示例10: main
import ch.qos.logback.core.Context; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();
// Note the wild card character '*', in the paterns, signifying any level
// of nesting.
ruleMap.put(new ElementSelector("*/computation"), new ComputationAction2());
ruleMap.put(new ElementSelector("*/computation/literal"), new LiteralAction());
ruleMap.put(new ElementSelector("*/computation/add"), new AddAction());
ruleMap.put(new ElementSelector("*/computation/multiply"), new MultiplyAction());
Context context = new ContextBase();
SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
// link the configurator with its context
simpleConfigurator.setContext(context);
try {
simpleConfigurator.doConfigure(args[0]);
} catch (JoranException e) {
// Print any errors that might have occured.
StatusPrinter.print(context);
}
}
示例11: main
import ch.qos.logback.core.Context; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Context context = new ContextBase();
Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();
// Associate "/computation" pattern with ComputationAction1
ruleMap.put(new ElementSelector("/computation"), new ComputationAction1());
// Other associations
ruleMap.put(new ElementSelector("/computation/literal"), new LiteralAction());
ruleMap.put(new ElementSelector("/computation/add"), new AddAction());
ruleMap.put(new ElementSelector("/computation/multiply"), new MultiplyAction());
SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
// link the configurator with its context
simpleConfigurator.setContext(context);
simpleConfigurator.doConfigure(args[0]);
// Print any errors that might have occured.
StatusPrinter.print(context);
}
示例12: buildAppender
import ch.qos.logback.core.Context; //导入依赖的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;
}
示例13: setContext
import ch.qos.logback.core.Context; //导入依赖的package包/类
@Override
public void setContext(Context context) {
super.setContext(context);
final String hostname = context.getProperty(CoreConstants.HOSTNAME_KEY);
if (hostname == null) {
addError("Hostname could not be found in context. HostNamePartitioningStrategy will not work.");
} else {
hostnameHash = ByteBuffer.allocate(4).putInt(hostname.hashCode()).array();
}
}
示例14: setContext
import ch.qos.logback.core.Context; //导入依赖的package包/类
@Override
public void setContext(Context context) {
super.setContext(context);
final String hostname = context.getProperty(CoreConstants.CONTEXT_NAME_KEY);
if (hostname == null) {
addError("Hostname could not be found in context. HostNamePartitioningStrategy will not work.");
} else {
contextNameHash = ByteBuffer.allocate(4).putInt(hostname.hashCode()).array();
}
}
示例15: setContext
import ch.qos.logback.core.Context; //导入依赖的package包/类
@Override
public void setContext(Context context) {
super.setContext(context);
this.host = SysUtil.host;
this.app = context.getName();
}