File tree Expand file tree Collapse file tree
main/java/com/stackify/api/common/log
test/java/com/stackify/api/common/log Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,4 +53,11 @@ public interface EventAdapter<T> {
5353 * @return True if the event was logged at error level
5454 */
5555 boolean isErrorLevel (final T event );
56+
57+ /**
58+ * Returns the class name from the log event
59+ * @param event The logging event
60+ * @return The class name from the log event
61+ */
62+ String getClassName (final T event );
5663}
Original file line number Diff line number Diff line change @@ -127,6 +127,16 @@ public void append(final T event) {
127127 return ;
128128 }
129129
130+ // skip internal logging
131+
132+ String className = eventAdapter .getClassName (event );
133+
134+ if (className != null ) {
135+ if (className .startsWith ("com.stackify.api." )) {
136+ return ;
137+ }
138+ }
139+
130140 // build the log message and queue it to be sent to Stackify
131141
132142 Throwable exception = eventAdapter .getThrowable (event );
Original file line number Diff line number Diff line change @@ -121,4 +121,12 @@ public boolean isErrorLevel(final LogEvent event) {
121121
122122 return false ;
123123 }
124+
125+ /**
126+ * @see com.stackify.api.common.log.EventAdapter#getClassName(java.lang.Object)
127+ */
128+ @ Override
129+ public String getClassName (final LogEvent event ) {
130+ return event .getClassName ();
131+ }
124132}
Original file line number Diff line number Diff line change @@ -141,4 +141,40 @@ public void testAppendWithoutActivate() throws Exception {
141141
142142 Mockito .verifyZeroInteractions (collector );
143143 }
144+
145+ /**
146+ * testAppendInternalEvent
147+ * @throws Exception
148+ */
149+ @ Test
150+ public void testAppendInternalEvent () throws Exception {
151+ String event = "log event" ;
152+
153+ EventAdapter <String > adapter = Mockito .mock (EventAdapter .class );
154+ Mockito .when (adapter .getClassName (event )).thenReturn ("com.stackify.api.common.log.LogBackgroundService" );
155+
156+ ErrorGovernor governor = Mockito .mock (ErrorGovernor .class );
157+ Mockito .when (governor .errorShouldBeSent (Mockito .any (StackifyError .class ))).thenReturn (true );
158+ PowerMockito .whenNew (ErrorGovernor .class ).withAnyArguments ().thenReturn (governor );
159+
160+ LogAppender <String > appender = new LogAppender <String >("logger" , adapter );
161+
162+ LogCollector collector = Mockito .mock (LogCollector .class );
163+ PowerMockito .whenNew (LogCollector .class ).withAnyArguments ().thenReturn (collector );
164+
165+ LogBackgroundService background = PowerMockito .mock (LogBackgroundService .class );
166+ PowerMockito .whenNew (LogBackgroundService .class ).withAnyArguments ().thenReturn (background );
167+
168+ ApiConfiguration config = ApiConfiguration .newBuilder ().apiUrl ("url" ).apiKey ("key" ).envDetail (Mockito .mock (EnvironmentDetail .class )).build ();
169+
170+ appender .activate (config );
171+
172+ Mockito .when (background .isRunning ()).thenReturn (true );
173+
174+ appender .append (event );
175+
176+ appender .close ();
177+
178+ Mockito .verifyZeroInteractions (collector );
179+ }
144180}
Original file line number Diff line number Diff line change @@ -130,4 +130,16 @@ public void testIsErrorLevel() {
130130 LogEvent noLevel = LogEvent .newBuilder ().message ("Message" ).build ();
131131 Assert .assertFalse (adapter .isErrorLevel (noLevel ));
132132 }
133+
134+ /**
135+ * testGetClassName
136+ */
137+ @ Test
138+ public void testGetClassName () {
139+ EnvironmentDetail envDetail = Mockito .mock (EnvironmentDetail .class );
140+ LogEventAdapter adapter = new LogEventAdapter (envDetail );
141+
142+ LogEvent isStackify = LogEvent .newBuilder ().className ("com.stackify.api.common.log.LogBackgroundService" ).build ();
143+ Assert .assertEquals ("com.stackify.api.common.log.LogBackgroundService" , adapter .getClassName (isStackify ));
144+ }
133145}
You can’t perform that action at this time.
0 commit comments