forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemOutLogger.java
More file actions
79 lines (72 loc) · 2.41 KB
/
SystemOutLogger.java
File metadata and controls
79 lines (72 loc) · 2.41 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package io.sentry;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** ILogger implementation to System.out. */
public final class SystemOutLogger implements ILogger {
/**
* Logs to console a message with the specified level, message and optional arguments.
*
* @param level The SentryLevel.
* @param message The message.
* @param args The optional arguments to format the message.
*/
@SuppressWarnings("AnnotateFormatMethod")
@Override
public void log(SentryLevel level, String message, Object... args) {
System.out.println(String.format("%s: %s", level, String.format(message, args)));
}
/**
* Logs to console a message with the specified level, message and throwable.
*
* @param level The SentryLevel.
* @param message The message.
* @param throwable The throwable to log.
*/
@SuppressWarnings("AnnotateFormatMethod")
@Override
public void log(SentryLevel level, String message, Throwable throwable) {
if (throwable == null) {
this.log(level, message);
} else {
System.out.println(
String.format(
"%s: %s\n%s",
level, String.format(message, throwable.toString()), captureStackTrace(throwable)));
}
}
/**
* Logs to console a message with the specified level, throwable, message and optional arguments.
*
* @param level The SentryLevel.
* @param throwable The throwable to log.
* @param message The message.
* @param args The optional arguments to format the message.
*/
@SuppressWarnings("AnnotateFormatMethod")
@Override
public void log(SentryLevel level, Throwable throwable, String message, Object... args) {
if (throwable == null) {
this.log(level, message, args);
} else {
System.out.println(
String.format(
"%s: %s \n %s\n%s",
level,
String.format(message, args),
throwable.toString(),
captureStackTrace(throwable)));
}
}
@Override
public boolean isEnabled(final @Nullable SentryLevel level) {
return true;
}
private @NotNull String captureStackTrace(final @NotNull Throwable throwable) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
throwable.printStackTrace(printWriter);
return stringWriter.toString();
}
}