3535 * @author Eric Martin
3636 */
3737public class LogAppender <T > implements Closeable {
38-
38+
3939 /**
4040 * Logger project name
4141 */
4242 private final String logger ;
43-
43+
4444 /**
4545 * Maps from specific log implementation events to our API
4646 */
4747 private final EventAdapter <T > eventAdapter ;
48-
48+
4949 /**
5050 * Collector for LogMsg objects that need to be sent to Stackify
5151 */
5252 private LogCollector collector = null ;
53-
53+
5454 /**
5555 * Background thread for sending log events to Stackify
5656 */
5757 private LogBackgroundService backgroundService = null ;
58-
58+
5959 /**
6060 * Client side error governor to suppress duplicate errors
6161 */
@@ -72,7 +72,7 @@ public LogAppender(final String logger, final EventAdapter<T> eventAdapter) {
7272 this .logger = logger ;
7373 this .eventAdapter = eventAdapter ;
7474 }
75-
75+
7676 /**
7777 * Activates the appender
7878 * @param apiConfig API configuration
@@ -83,33 +83,33 @@ public void activate(final ApiConfiguration apiConfig) {
8383 Preconditions .checkArgument (!apiConfig .getApiUrl ().isEmpty ());
8484 Preconditions .checkNotNull (apiConfig .getApiKey ());
8585 Preconditions .checkArgument (!apiConfig .getApiKey ().isEmpty ());
86-
86+
8787 // Single JSON object mapper for all services
8888
8989 ObjectMapper objectMapper = new ObjectMapper ();
9090
9191 // build the app identity service
9292
9393 AppIdentityService appIdentityService = new AppIdentityService (apiConfig , objectMapper );
94-
94+
9595 // build the services for collecting and sending log messages
9696
9797 this .collector = new LogCollector (logger , apiConfig .getEnvDetail (), appIdentityService );
98-
98+
9999 LogSender sender = new LogSender (apiConfig , objectMapper );
100-
100+
101101 // build the background service to asynchronously post errors to Stackify
102102 // startup the background service
103-
103+
104104 this .backgroundService = new LogBackgroundService (collector , sender );
105-
105+
106106 try {
107107 backgroundService .startAsync ().awaitRunning (5 , TimeUnit .SECONDS );
108108 } catch (TimeoutException e ) {
109109 Throwables .propagate (e );
110110 }
111111 }
112-
112+
113113 /**
114114 * @see java.io.Closeable#close()
115115 */
@@ -123,39 +123,39 @@ public void close() throws IOException {
123123 }
124124 }
125125 }
126-
126+
127127 /**
128128 * Adds the log message to the collector
129- * @param logMsg
129+ * @param event
130130 */
131131 public void append (final T event ) {
132132
133133 // make sure we can append the log message
134-
134+
135135 if (backgroundService == null ) {
136136 return ;
137137 }
138-
138+
139139 if (!backgroundService .isRunning ()) {
140140 return ;
141141 }
142-
142+
143143 // build the log message and queue it to be sent to Stackify
144-
144+
145145 Optional <Throwable > exception = eventAdapter .getThrowable (event );
146-
146+
147147 Optional <StackifyError > error = Optional .absent ();
148-
148+
149149 if ((exception .isPresent ()) || (eventAdapter .isErrorLevel (event ))) {
150150 StackifyError e = eventAdapter .getStackifyError (event , exception .orNull ());
151-
151+
152152 if (errorGovernor .errorShouldBeSent (e )) {
153153 error = Optional .of (e );
154154 }
155155 }
156-
156+
157157 LogMsg logMsg = eventAdapter .getLogMsg (event , error );
158-
158+
159159 collector .addLogMsg (logMsg );
160160 }
161161}
0 commit comments