Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
2.5.0
-
Security Level: Public
-
None
-
CBL Sprint 3, CBL Sprint 4
-
2
Description
If specifying a custom logger, it looks like most messages get passed through at LogLevel.Verbose even if they should be higher.
Basic repro:
public class MainActivity extends AppCompatActivity {
|
|
Database db;
|
Replicator r;
|
URI u;
|
|
@Override
|
protected void onCreate (Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_main);
|
|
Database.log.setCustom(new LogTestLogger(LogLevel.DEBUG));
|
Database.log.getConsole().setLevel(LogLevel.DEBUG);
|
final DatabaseConfiguration dbc = new DatabaseConfiguration(this);
|
|
setUp(dbc);
|
|
}
|
|
private void setUp (DatabaseConfiguration dbc) {
|
try {
|
db = new Database("test", dbc);
|
} catch (CouchbaseLiteException e) {
|
e.printStackTrace();
|
}
|
|
// Create replicators to push and pull changes to and from the cloud.
|
Endpoint targetEndpoint = null;
|
try {
|
targetEndpoint = new URLEndpoint(new URI("ws://NONE_OF_YOUR_BUSINESS:80/db"));
|
} catch (URISyntaxException e) {
|
e.printStackTrace();
|
}
|
ReplicatorConfiguration replConfig = new ReplicatorConfiguration(db, targetEndpoint);
|
replConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PUSH_AND_PULL);
|
|
|
r = new Replicator(replConfig);
|
|
// Start replication.
|
r.start();
|
}
|
|
|
class LogTestLogger implements Logger {
|
@NonNull
|
private final LogLevel level;
|
|
public LogTestLogger(@NonNull LogLevel level) { this.level = level; }
|
|
@NonNull
|
@Override
|
public LogLevel getLevel() { return level; }
|
|
@Override
|
public void log(@NonNull LogLevel level, @NonNull LogDomain domain, @NonNull String message) {
|
// Avoid flooding of CBL-143 messages
|
if (!message.contains("C4Socket.write") && !message.contains("completedWrite(long) handle")) {
|
Log.println(level.getValue(), "CUSTOM_LOGGER", String.format("Level:%s - Message:%s", level.getValue(), message));
|
}
|
}
|
}
|
}
|
I/CouchbaseLite/DATABASE: {DB#3} Closing database
|
V/CUSTOM_LOGGER: Level:2 - Message:{DB#3} Closing database
|
I/CouchbaseLite/REPLICATOR: C4ReplicatorListener.statusChanged() status -> C4ReplicatorStatus{activityLevel=0, progressUnitsCompleted=0, progressUnitsTotal=0, progressDocumentCount=0, errorDomain=0, errorCode=0, errorInternalInfo=0}
|
V/CUSTOM_LOGGER: Level:2 - Message:C4ReplicatorListener.statusChanged() status -> C4ReplicatorStatus{activityLevel=0, progressUnitsCompleted=0, progressUnitsTotal=0, progressDocumentCount=0, errorDomain=0, errorCode=0, errorInternalInfo=0}
|
OH! Digging into this a bit more, I see the issue - our log levels are out of step with Android's:
CouchbaseLite
public enum LogLevel {
/**
* Debug log messages. Only present in debug builds of CouchbaseLite.
*/
DEBUG(Log.C4LOG_DEBUG),
/**
* Verbose log messages.
*/
VERBOSE(Log.C4LOG_VERBOSE),
/**
* Informational log messages.
*/
INFO(Log.C4LOG_INFO),
/**
* Warning log messages.
*/
WARNING(Log.C4LOG_WARN),
/**
* Error log messages. These indicate immediate errors that need to be addressed.
*/
ERROR(Log.C4LOG_ERROR),
/**
* Disabling log messages of a given log domain.
*/
NONE(Log.C4LOG_NONE);
// ... VVVV ...
public final class Log {
public static final int C4LOG_DEBUG = kC4LogDebug;
public static final int C4LOG_VERBOSE = kC4LogVerbose;
public static final int C4LOG_INFO = kC4LogInfo;
public static final int C4LOG_WARN = kC4LogWarning;
public static final int C4LOG_ERROR = kC4LogError;
public static final int C4LOG_NONE = kC4LogNone;
// ... VVVV ...
interface C4LogLevel {
int kC4LogDebug = 0;
int kC4LogVerbose = 1;
int kC4LogInfo = 2;
int kC4LogWarning = 3;
int kC4LogError = 4;
int kC4LogNone = 5;
}
Android
public final class Log {
/**
* Priority constant for the println method; use Log.v.
*/
public static final int VERBOSE = 2;
/**
* Priority constant for the println method; use Log.d.
*/
public static final int DEBUG = 3;
/**
* Priority constant for the println method; use Log.i.
*/
public static final int INFO = 4;
/**
* Priority constant for the println method; use Log.w.
*/
public static final int WARN = 5;
/**
* Priority constant for the println method; use Log.e.
*/
public static final int ERROR = 6;
/**
* Priority constant for the println method.
*/
public static final int ASSERT = 7;
So, not only are we not aligned, but we've actually reversed the levels Verbose and Debug.