@Override public void onApplicationEvent(ApplicationEvent event) { final String settings = environment.getProperty("logging.config.src"); if (StringUtils.hasText(settings)) { try { final ContextBase context = (ContextBase) StaticLoggerBinder.getSingleton().getLoggerFactory(); final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); LOG.info("try to update logback configuration to {}", settings); context.reset(); configurator.doConfigure(new ByteArrayInputStream(settings.getBytes())); } catch (JoranException e) { LOG.error("can't load settings", e); } } }
@Test public void testTail2() throws Exception { SimpleRuleStore srs = new SimpleRuleStore(new ContextBase()); srs.addRule(new ElementSelector("*/c"), new XAction()); for (String s : cc.combinations("a/b/c")) { List<Action> r = srs.matchActions(new ElementPath(s)); assertNotNull(r); assertEquals(1, r.size()); if (!(r.get(0) instanceof XAction)) { fail("Wrong type"); } } }
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; }
@Override protected void setUp() throws Exception { context = new ContextBase(); appender = new JMSQueueAppender(); appender.setContext(context); appender.setName("jmsQueue"); appender.qcfBindingName = "queueCnxFactory"; appender.queueBindingName = "testQueue"; appender.setProviderURL("url"); appender.setInitialContextFactoryName(MockInitialContextFactory.class.getName()); MockInitialContext mic = MockInitialContextFactory.getContext(); mic.map.put(appender.qcfBindingName, new MockQueueConnectionFactory()); mic.map.put(appender.queueBindingName, new MockQueue(appender.queueBindingName)); super.setUp(); }
@Before public void setUp() throws Exception { context = new ContextBase(); appender = new JMSTopicAppender(); appender.setContext(context); appender.setName("jmsTopic"); appender.tcfBindingName = "topicCnxFactory"; appender.topicBindingName = "testTopic"; appender.setProviderURL("url"); appender.setInitialContextFactoryName(MockInitialContextFactory.class.getName()); MockInitialContext mic = MockInitialContextFactory.getContext(); mic.map.put(appender.tcfBindingName, new MockTopicConnectionFactory()); mic.map.put(appender.topicBindingName, new MockTopic(appender.topicBindingName)); }
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); }
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); }
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); } }
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); }
/** * Default method for stopping the Logback context */ protected void stop() { addInfo("Logback context being closed via shutdown hook"); Context hookContext = getContext(); if (hookContext instanceof ContextBase) { ContextBase context = (ContextBase) hookContext; context.stop(); } }
@Test public void testUnStarted() { PatternLayoutBase<E> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); String s = plb.doLayout(getEventObject()); assertEquals("", s); StatusManager sm = context.getStatusManager(); StatusPrinter.print(sm); }
@Test public void testStarted() { PatternLayoutBase<E> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); String s = plb.doLayout(getEventObject()); assertEquals("", s); StatusManager sm = context.getStatusManager(); StatusPrinter.print(sm); }
@Test public void testNullPattern() { //System.out.println("testNullPattern"); PatternLayoutBase<E> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern(null); plb.start(); String s = plb.doLayout(getEventObject()); assertEquals("", s); StatusChecker checker = new StatusChecker(context.getStatusManager()); //StatusPrinter.print(context); checker.assertContainsMatch("Empty or null pattern."); }
@Test public void testEmptyPattern() { //System.out.println("testNullPattern"); PatternLayoutBase<E> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern(""); plb.start(); String s = plb.doLayout(getEventObject()); assertEquals("", s); StatusChecker checker = new StatusChecker(context.getStatusManager()); //StatusPrinter.print(context); checker.assertContainsMatch("Empty or null pattern."); }
@Test public void testOK() { PatternLayoutBase<Object> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern("x%OTT"); plb.start(); String s = plb.doLayout(new Object()); //System.out.println(s); //StatusManager sm = context.getStatusManager(); //StatusPrinter.print(sm); assertEquals("x123", s); }
@Test public void testEscapeClosingParentheses() { PatternLayoutBase<Object> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern("x(%OTT\\)y"); plb.start(); String s = plb.doLayout(new Object()); assertEquals("x(123)y", s); }
@Test public void testEscapeBothParentheses() { PatternLayoutBase<Object> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern("x\\(%OTT\\)y"); plb.start(); String s = plb.doLayout(new Object()); assertEquals("x(123)y", s); }
@Test public void testPercentAsLiteral() { PatternLayoutBase<Object> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern("hello \\% world"); plb.start(); String s = plb.doLayout(new Object()); assertEquals("hello % world", s); }
public void testStringToLong() { Context context = new ContextBase(); SizeBasedTriggeringPolicy policy = new SizeBasedTriggeringPolicy(); policy.setContext(context); Long result; { result = policy.toFileSize("123"); assertEquals(new Long("123"), result); } { result = policy.toFileSize("123KB"); // = 123 * 1024 assertEquals(new Long("125952"), result); } { result = policy.toFileSize("123MB"); // = 123 * 1024 * 1024 assertEquals(new Long("128974848"), result); } { result = policy.toFileSize("123GB"); // = 123 * 1024 * 1024 * 1024 assertEquals(new Long("132070244352"), result); } { result = policy.toFileSize("123xxxx"); // = 123 * 1024 * 1024 * 1024 assertEquals(new Long(SizeBasedTriggeringPolicy.DEFAULT_MAX_FILE_SIZE), result); assertEquals(2, context.getStatusManager().getCount()); } }
public void setUp() throws Exception { context = new ContextBase(); matcher = new Matcher(); matcher.setContext(context); matcher.setName("testMatcher"); super.setUp(); }
@Before public void setUp() throws Exception { context = new ContextBase(); ec = new InterpretationContext(context, null); propertyAction = new PropertyAction(); propertyAction.setContext(context); }
@Test public void testBasic() { Context context = new ContextBase(); context.getStatusManager().add(new InfoStatus("test", this)); StatusPrinter.print(context); String result = outputStream.toString(); assertTrue(result.contains("|-INFO in "+this.getClass().getName())); }
@Test public void testNested() { Status s0 = new ErrorStatus("test0", this); Status s1 = new InfoStatus("test1", this); Status s11 = new InfoStatus("test11", this); Status s12 = new InfoStatus("test12", this); s1.add(s11); s1.add(s12); Status s2 = new InfoStatus("test2", this); Status s21 = new InfoStatus("test21", this); Status s211 = new WarnStatus("test211", this); Status s22 = new InfoStatus("test22", this); s2.add(s21); s2.add(s22); s21.add(s211); Context context = new ContextBase(); context.getStatusManager().add(s0); context.getStatusManager().add(s1); context.getStatusManager().add(s2); StatusPrinter.print(context); String result = outputStream.toString(); assertTrue(result.contains("+ INFO in "+this.getClass().getName())); assertTrue(result.contains("+ WARN in "+this.getClass().getName())); assertTrue(result.contains(" |-WARN in "+this.getClass().getName())); }
@Test public void testWithException() { Status s0 = new ErrorStatus("test0", this); Status s1 = new InfoStatus("test1", this, new Exception("testEx")); Status s11 = new InfoStatus("test11", this); Status s12 = new InfoStatus("test12", this); s1.add(s11); s1.add(s12); Status s2 = new InfoStatus("test2", this); Status s21 = new InfoStatus("test21", this); Status s211 = new WarnStatus("test211", this); Status s22 = new InfoStatus("test22", this); s2.add(s21); s2.add(s22); s21.add(s211); Context context = new ContextBase(); context.getStatusManager().add(s0); context.getStatusManager().add(s1); context.getStatusManager().add(s2); StatusPrinter.print(context); String result = outputStream.toString(); assertTrue(result.contains("|-ERROR in "+this.getClass().getName())); assertTrue(result.contains("+ INFO in "+this.getClass().getName())); assertTrue(result.contains("ch.qos.logback.core.util.StatusPrinterTest.testWithException")); }
public static void main(String[] args) { Context context = new ContextBase(); for(int i = 0; i < 3; i++) { SenderRunnable senderRunnable = new SenderRunnable(""+i); context.getExecutorService().execute(senderRunnable); } System.out.println("done"); //System.exit(0); }
public static void main(String[] args) throws Exception { Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>(); // Associate "hello-world" pattern with HelloWorldAction ruleMap.put(new ElementSelector("hello-world"), new HelloWorldAction()); // Joran needs to work within a context. Context context = new ContextBase(); SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap); // link the configurator with its context simpleConfigurator.setContext(context); simpleConfigurator.doConfigure(args[0]); StatusPrinter.print(context); }
@Before public void before() { layout.setContext(new ContextBase()); layout.setOriginHost("localhost"); }
@Before public void setUp() throws Exception { configuration.setContext(new ContextBase()); }