forked from segmentio/analytics-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggingPlugin.java
More file actions
44 lines (39 loc) · 1.3 KB
/
Copy pathLoggingPlugin.java
File metadata and controls
44 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package sample;
import com.segment.analytics.Analytics;
import com.segment.analytics.Callback;
import com.segment.analytics.Log;
import com.segment.analytics.Plugin;
import com.segment.analytics.messages.Message;
/**
* A {@link Plugin} implementation that redirects client logs to standard output and logs callback
* events.
*/
public class LoggingPlugin implements Plugin {
@Override
public void configure(Analytics.Builder builder) {
builder.log(
new Log() {
@Override
public void print(Level level, String format, Object... args) {
System.out.println(level + ":\t" + String.format(format, args));
}
@Override
public void print(Level level, Throwable error, String format, Object... args) {
System.out.println(level + ":\t" + String.format(format, args));
System.out.println(error);
}
});
builder.callback(
new Callback() {
@Override
public void success(Message message) {
System.out.println("Uploaded " + message);
}
@Override
public void failure(Message message, Throwable throwable) {
System.out.println("Could not upload " + message);
System.out.println(throwable);
}
});
}
}