Uploaded image for project: 'Couchbase Lite'
  1. Couchbase Lite
  2. CBL-144

Incorrect log level passed to custom logger

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Major
    • 2.7.0
    • 2.5.0
    • Java-Android
    • 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}
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            blake.meike Blake Meike
            James Flather James Flather (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty