mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-22 16:03:15 +00:00
Merge branch 'common/improve_logger' into source/add_files_refactor1
This commit is contained in:
commit
dccb3090e1
|
@ -1,5 +1,7 @@
|
|||
package one.nem.lacerta.utils;
|
||||
|
||||
import one.nem.lacerta.utils.model.KeyValueLog;
|
||||
|
||||
public interface LacertaLogger {
|
||||
|
||||
void info(String tag, String message);
|
||||
|
@ -9,4 +11,7 @@ public interface LacertaLogger {
|
|||
void trace(String tag, String message);
|
||||
void fatal(String tag, String message);
|
||||
|
||||
String buildKVMessage(KeyValueLog... logs);
|
||||
// With name
|
||||
String buildKVMessage(String name, KeyValueLog... logs);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.util.Log;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
import one.nem.lacerta.utils.model.KeyValueLog;
|
||||
|
||||
public class LacertaLoggerImpl implements LacertaLogger{
|
||||
|
||||
@Inject
|
||||
|
@ -40,4 +42,30 @@ public class LacertaLoggerImpl implements LacertaLogger{
|
|||
public void fatal(String tag, String message) {
|
||||
Log.wtf(tag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildKVMessage(KeyValueLog... logs) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (KeyValueLog log : logs) {
|
||||
builder.append(log.getKey());
|
||||
builder.append(": ");
|
||||
builder.append(log.getValue());
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildKVMessage(String name, KeyValueLog... logs) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(name);
|
||||
builder.append("\n");
|
||||
for (KeyValueLog log : logs) {
|
||||
builder.append(log.getKey());
|
||||
builder.append(": ");
|
||||
builder.append(log.getValue());
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package one.nem.lacerta.utils.model;
|
||||
|
||||
public class KeyValueLog {
|
||||
|
||||
String key;
|
||||
String value;
|
||||
|
||||
public KeyValueLog(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// Getter
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Setter
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user