Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Revert API-breaking change in name of LOG (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeike committed Mar 14, 2019
1 parent cf03f34 commit e044bd5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void setUp() throws Exception {
@Test
public void testCustomLoggingLevels() {
LogTestLogger customLogger = new LogTestLogger();
Database.LOG.setCustom(customLogger);
Database.log.setCustom(customLogger);

for(int i = 5; i >= 1; i--) {
customLogger.getLines().clear();
Expand All @@ -54,7 +54,7 @@ public void testCustomLoggingLevels() {
@Test
public void testEnableAndDisableCustomLogging() {
LogTestLogger customLogger = new LogTestLogger();
Database.LOG.setCustom(customLogger);
Database.log.setCustom(customLogger);

customLogger.setLevel(LogLevel.NONE);
Log.v(LogDomain.DATABASE, "TEST VERBOSE");
Expand Down Expand Up @@ -95,7 +95,7 @@ public void run() {
LogLevel.VERBOSE
};
for (LogLevel level : levels) {
Database.LOG.getFile().setLevel(level);
Database.log.getFile().setLevel(level);
Log.v(LogDomain.DATABASE, "TEST VERBOSE");
Log.i(LogDomain.DATABASE, "TEST INFO");
Log.w(LogDomain.DATABASE, "TEST WARNING");
Expand Down Expand Up @@ -320,7 +320,7 @@ public void run() {
assertFalse(contents.contains(uuidString));
}

Database.LOG.getFile().setLevel(LogLevel.VERBOSE);
Database.log.getFile().setLevel(LogLevel.VERBOSE);
writeAllLogs(uuidString);

File[] filesExceptDebug = path.listFiles(new FilenameFilter() {
Expand Down Expand Up @@ -493,16 +493,16 @@ public void testEditReadOnlyLogFileConfiguration() {
);
final String logDirectory = emptyDirectory(path.getAbsolutePath());
LogFileConfiguration config = new LogFileConfiguration(logDirectory);
Database.LOG.getFile().setConfig(config);
Database.log.getFile().setConfig(config);

thrown.expect(IllegalStateException.class);
Database.LOG.getFile().getConfig().setMaxSize(1024);
Database.log.getFile().getConfig().setMaxSize(1024);

thrown.expect(IllegalStateException.class);
Database.LOG.getFile().getConfig().setMaxRotateCount(3);
Database.log.getFile().getConfig().setMaxRotateCount(3);

thrown.expect(IllegalStateException.class);
Database.LOG.getFile().getConfig().setUsePlaintext(true);
Database.log.getFile().getConfig().setUsePlaintext(true);
}

//endregion
Expand All @@ -511,9 +511,9 @@ public void testEditReadOnlyLogFileConfiguration() {
public void testNonASCII() throws CouchbaseLiteException {
LogTestLogger customLogger = new LogTestLogger();
customLogger.setLevel(LogLevel.VERBOSE);
Database.LOG.setCustom(customLogger);
Database.LOG.getConsole().setDomains(EnumSet.of(LogDomain.ALL));
Database.LOG.getConsole().setLevel(LogLevel.VERBOSE);
Database.log.setCustom(customLogger);
Database.log.getConsole().setDomains(EnumSet.of(LogDomain.ALL));
Database.log.getConsole().setLevel(LogLevel.VERBOSE);

String hebrew = "מזג האוויר נחמד היום"; // The weather is nice today.
MutableDocument doc = new MutableDocument();
Expand All @@ -536,17 +536,17 @@ public void testNonASCII() throws CouchbaseLiteException {

//region Helper methods
private void testWithConfiguration(LogLevel level, LogFileConfiguration config, Runnable r) {
LogFileConfiguration old = Database.LOG.getFile().getConfig();
EnumSet<LogDomain> domains = Database.LOG.getConsole().getDomains();
Database.LOG.getFile().setConfig(config);
Database.LOG.getFile().setLevel(level);
LogFileConfiguration old = Database.log.getFile().getConfig();
EnumSet<LogDomain> domains = Database.log.getConsole().getDomains();
Database.log.getFile().setConfig(config);
Database.log.getFile().setLevel(level);
try {
r.run();
} finally {
Database.LOG.getFile().setLevel(LogLevel.INFO);
Database.LOG.getFile().setConfig(old);
Database.LOG.getConsole().setDomains(domains);
Database.LOG.getConsole().setLevel(LogLevel.WARNING);
Database.log.getFile().setLevel(LogLevel.INFO);
Database.log.getFile().setConfig(old);
Database.log.getConsole().setDomains(domains);
Database.log.getConsole().setLevel(LogLevel.WARNING);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void setCallbackLevel(@NonNull LogLevel level) {
if (level == null) { throw new IllegalArgumentException("level cannot be null."); }

LogLevel callbackLevel = level;
final Logger custom = Database.LOG.getCustom();
final Logger custom = Database.log.getCustom();
if ((custom != null) && (custom.getLevel().compareTo(callbackLevel) < 0)) {
callbackLevel = custom.getLevel();
}
Expand Down
11 changes: 7 additions & 4 deletions shared/src/main/java/com/couchbase/lite/AbstractDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ abstract class AbstractDatabase {
/**
* Gets the logging controller for the Couchbase Lite library to configure the
* logging settings and add custom logging.
*
* This is part of the Public API.
*/
@SuppressWarnings("ConstantName")
@NonNull
public static final com.couchbase.lite.Log LOG;
public static final com.couchbase.lite.Log log;

static {
NativeLibraryLoader.load();
LOG = new com.couchbase.lite.Log(); // Don't move this, the native library is needed
log = new com.couchbase.lite.Log(); // Don't move this, the native library is needed
Log.setLogLevel(LogDomain.ALL, LogLevel.WARNING);
}

Expand Down Expand Up @@ -181,7 +184,7 @@ public static void copy(
* @param level The log level
* @deprecated As of 2.5 because it is being replaced with the
* {@link com.couchbase.lite.Log#getConsole() getConsole} method
* from the {@link #LOG log} property. This method has
* from the {@link #log log} property. This method has
* been replaced with a no-op to preserve API compatibility.
*/
@Deprecated
Expand Down Expand Up @@ -245,7 +248,7 @@ public void run() {
Log.info(DOMAIN, CBLVersion.getUserAgent());

// Check file logging
if (Database.LOG.getFile().getConfig() == null) {
if (Database.log.getFile().getConfig() == null) {
Log.w(DOMAIN, "Database.log.getFile().getConfig() is null, meaning file " +
"logging is disabled. Log files required for product support are " +
"not being generated.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ static void logCallback(String domainName, int level, String message) {
domain = domainObjects.get(domainName);
}

Database.LOG.getConsole().log(LogLevel.values()[level], domain, message);
final Logger customLogger = Database.LOG.getCustom();
Database.log.getConsole().log(LogLevel.values()[level], domain, message);
final Logger customLogger = Database.log.getCustom();
if (customLogger != null) {
customLogger.log(LogLevel.values()[level], domain, message);
}
}

private static void recalculateLevels() {
LogLevel callbackLevel = Database.LOG.getConsole().getLevel();
final Logger customLogger = Database.LOG.getCustom();
LogLevel callbackLevel = Database.log.getConsole().getLevel();
final Logger customLogger = Database.log.getCustom();
if (customLogger != null && customLogger.getLevel().compareTo(callbackLevel) < 0) {
callbackLevel = customLogger.getLevel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,26 +397,26 @@ private static void sendToLoggers(LogLevel level, LogDomain domain, String msg)
boolean consoleSucceeded = false;
try {
// File logging:
Database.LOG.getFile().log(level, domain, msg);
Database.log.getFile().log(level, domain, msg);
fileSucceeded = true;

// Console logging:
Database.LOG.getConsole().log(level, domain, msg);
Database.log.getConsole().log(level, domain, msg);
consoleSucceeded = true;

// Custom logging:
final Logger custom = Database.LOG.getCustom();
final Logger custom = Database.log.getCustom();
if (custom != null) {
custom.log(level, domain, msg);
}
}
catch (Exception e) {
if (fileSucceeded) {
Database.LOG.getFile().log(LogLevel.ERROR, LogDomain.DATABASE, e.toString());
Database.log.getFile().log(LogLevel.ERROR, LogDomain.DATABASE, e.toString());
}

if (consoleSucceeded) {
Database.LOG.getConsole().log(LogLevel.ERROR, LogDomain.DATABASE, e.toString());
Database.log.getConsole().log(LogLevel.ERROR, LogDomain.DATABASE, e.toString());
}
}
}
Expand Down

0 comments on commit e044bd5

Please sign in to comment.