static public ILoggingEvent[] make(CorpusModel corpusModel, int n, boolean withCallerData) { LoggerContextVO lcVO = corpusModel.getRandomlyNamedLoggerContextVO(); PubLoggingEventVO[] plevoArray = new PubLoggingEventVO[n]; for (int i = 0; i < n; i++) { PubLoggingEventVO e = new PubLoggingEventVO(); plevoArray[i] = e; e.loggerContextVO = lcVO; e.timeStamp = corpusModel.getRandomTimeStamp(); LogStatement logStatement = corpusModel.getRandomLogStatementFromPool(); e.loggerName = logStatement.loggerName; e.level = logStatement.level; e.message = logStatement.mat.message; e.argumentArray = corpusModel .getRandomArgumentArray(logStatement.mat.numberOfArguments); if (withCallerData) { e.callerDataArray = corpusModel.getRandomCallerData( ClassicConstants.DEFAULT_MAX_CALLEDER_DATA_DEPTH, e.loggerName); } e.throwableProxy = logStatement.throwableProxy; e.threadName = corpusModel.getRandomThreadNameFromPool(); } return plevoArray; }
public boolean equals(Object o) { if(this == o) { return true; } else if(!(o instanceof LoggerContextVO)) { return false; } else { KonkerLoggerContextVO that = (KonkerLoggerContextVO) o; if(this.birthTime != that.birthTime) { return false; } else { if(this.name != null) { if(!this.name.equals(that.name)) { return false; } } else if(that.name != null) { return false; } if(this.propertyMap != null) { if(!this.propertyMap.equals(that.propertyMap)) { return false; } } else if(that.propertyMap != null) { return false; } return true; } } }
public String convert(ILoggingEvent event) { if (key == null) { return "Property_HAS_NO_KEY"; } else { LoggerContextVO lcvo = event.getLoggerContextVO(); Map<String, String> map = lcvo.getPropertyMap(); String val = map.get(key); if (val != null) { return val; } else { return System.getProperty(key); } } }
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>(); }
LoggingEventWrapper(ILoggingEvent event, Map<String, String> mdcPropertyMap) { this.event = event; this.mdcPropertyMap = mdcPropertyMap; final LoggerContextVO oldVo = event.getLoggerContextVO(); if (oldVo != null) { vo = new LoggerContextVO(oldVo.getName(), mdcPropertyMap, oldVo.getBirthTime()); } else { vo = null; } }
private void setLogbackProperty( final ILoggingEvent mockEvent, final String propertyKey, final String propertyValue) { LoggerContextVO mockContext = mock(LoggerContextVO.class); Map<String, String> mockPropertiesMap = new HashMap<String, String>(); mockPropertiesMap.put(propertyKey, propertyValue); when(mockEvent.getLoggerContextVO()).thenReturn(mockContext); when(mockContext.getPropertyMap()).thenReturn(mockPropertiesMap); }
@Override public LoggerContextVO getLoggerContextVO() { return event.getLoggerContextVO(); }
@Override public LoggerContextVO getLoggerContextVO() { return this.event.getLoggerContextVO(); }
@Override public LoggerContextVO getLoggerContextVO() { return loggingEvent.getLoggerContextVO(); }
public LoggerContextVO getLoggerContextRemoteView() { return loggerContextRemoteView; }
LoggerContextVO getRandomlyNamedLoggerContextVO() { LoggerContext lc = new LoggerContext(); lc.setName(getRandomJavaIdentifier()); return new LoggerContextVO(lc); }
private ILoggingEvent createEvent(String message) { return new ILoggingEvent() { @Override public void prepareForDeferredProcessing() { // Do nothing } @Override public boolean hasCallerData() { return false; } @Override public long getTimeStamp() { return 0; } @Override public IThrowableProxy getThrowableProxy() { return null; } @Override public String getThreadName() { return "test"; } @Override public String getMessage() { return message; } @Override public Map<String, String> getMdc() { return Collections.emptyMap(); } @Override public Marker getMarker() { return null; } @Override public Map<String, String> getMDCPropertyMap() { return Collections.emptyMap(); } @Override public String getLoggerName() { return "fake"; } @Override public LoggerContextVO getLoggerContextVO() { return null; } @Override public Level getLevel() { return Level.INFO; } @Override public String getFormattedMessage() { return message; } @Override public StackTraceElement[] getCallerData() { return new StackTraceElement[0]; } @Override public Object[] getArgumentArray() { return new Object[0]; } }; }
@Override public LoggerContextVO getLoggerContextVO() { return null; }
@Override public LoggerContextVO getLoggerContextVO() { return vo; }
public MockLoggingEvent with(final LoggerContextVO loggerContextVO) { this.loggerContextVO = loggerContextVO; return this; }
@Override public LoggerContextVO getLoggerContextVO() { return loggerContextVO; }
public LoggerContextVO getLoggerContextVO() { return event.getLoggerContextVO(); }
@Override public LoggerContextVO getLoggerContextVO() { return _wrappedEvent.getLoggerContextVO(); }
/** * @deprecated Invokes deprecated methods on Logback classes. */ @Deprecated @Test public void test() { final ILoggingEvent wrapped = Mockito.mock(ILoggingEvent.class); final LoggerContextVO loggerContext = Mockito.mock(LoggerContextVO.class); final IThrowableProxy throwableProxy = Mockito.mock(IThrowableProxy.class); final StackTraceElement[] callerData = new StackTraceElement[]{}; final Marker marker = Mockito.mock(Marker.class); // CHECKSTYLE.OFF: IllegalInstantiation - No Guava dependency here. final Map<String, String> mdcPropertyMap = new HashMap<>(); final Map<String, String> mdc = new HashMap<>(); // CHECKSTYLE.ON: IllegalInstantiation mdcPropertyMap.put("foo1", "bar1"); mdc.put("foo2", "bar2"); final String message = "The message"; final Object[] arguments = new Object[] {}; Mockito.doReturn("threadName").when(wrapped).getThreadName(); Mockito.doReturn(Level.WARN).when(wrapped).getLevel(); Mockito.doReturn("loggerName").when(wrapped).getLoggerName(); Mockito.doReturn(loggerContext).when(wrapped).getLoggerContextVO(); Mockito.doReturn(throwableProxy).when(wrapped).getThrowableProxy(); Mockito.doReturn(callerData).when(wrapped).getCallerData(); Mockito.doReturn(Boolean.TRUE).when(wrapped).hasCallerData(); Mockito.doReturn(marker).when(wrapped).getMarker(); Mockito.doReturn(mdcPropertyMap).when(wrapped).getMDCPropertyMap(); Mockito.doReturn(mdc).when(wrapped).getMdc(); Mockito.doReturn(1L).when(wrapped).getTimeStamp(); final LoggingEventWrapper wrapper = new LoggingEventWrapper(wrapped, message, arguments); Assert.assertEquals("threadName", wrapper.getThreadName()); Assert.assertEquals(Level.WARN, wrapper.getLevel()); Assert.assertEquals("loggerName", wrapper.getLoggerName()); Assert.assertSame(loggerContext, wrapper.getLoggerContextVO()); Assert.assertSame(throwableProxy, wrapper.getThrowableProxy()); Assert.assertSame(callerData, wrapper.getCallerData()); Assert.assertTrue(wrapper.hasCallerData()); Assert.assertSame(marker, wrapper.getMarker()); Assert.assertEquals(mdcPropertyMap, wrapper.getMDCPropertyMap()); Assert.assertEquals(mdc, wrapper.getMdc()); Assert.assertEquals(1L, wrapped.getTimeStamp()); Assert.assertEquals(message, wrapper.getMessage()); Assert.assertTrue(Arrays.equals(arguments, wrapper.getArgumentArray())); }
@Override public LoggerContextVO getLoggerContextVO() { return baseEvent.getLoggerContextVO(); }
/** * A new instance of LoggerContextRemoteView needs to be created each time the * name or propertyMap (including keys or values) changes. */ private void updateLoggerContextVO() { loggerContextRemoteView = new LoggerContextVO(this); }