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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
//
// Logger.java
// Adjust
//
// Created by Christian Wellenbrock on 2013-04-18.
// Copyright (c) 2013 adjust GmbH. All rights reserved.
// See the file MIT-LICENSE for copying permission.
//
package com.adjust.sdk;
import android.util.Log;
import java.util.Arrays;
import java.util.Locale;
import static com.adjust.sdk.Constants.LOGTAG;
public class Logger implements ILogger {
private LogLevel logLevel;
private static String formatErrorMessage = "Error formating log message: %s, with params: %s";
public Logger() {
setLogLevel(LogLevel.INFO);
}
@Override
public void setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
}
@Override
public void setLogLevelString(String logLevelString) {
if (null != logLevelString) {
try {
setLogLevel(LogLevel.valueOf(logLevelString.toUpperCase(Locale.US)));
} catch (IllegalArgumentException iae) {
error("Malformed logLevel '%s', falling back to 'info'", logLevelString);
}
}
}
@Override
public void verbose(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.VERBOSE) {
try {
Log.v(LOGTAG, String.format(message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void debug(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.DEBUG) {
try {
Log.d(LOGTAG, String.format(message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void info(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.INFO) {
try {
Log.i(LOGTAG, String.format(message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void warn(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.WARN) {
try {
Log.w(LOGTAG, String.format(message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void error(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.ERROR) {
try {
Log.e(LOGTAG, String.format(message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void Assert(String message, Object... parameters) {
try {
Log.println(Log.ASSERT, LOGTAG, String.format(message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
|