MCPcopy
hub / github.com/orhanobut/logger

github.com/orhanobut/logger @2.2.0 sqlite

repository ↗ · DeepWiki ↗ · release 2.2.0 ↗
212 symbols 788 edges 24 files 28 documented · 13%
README

Android Arsenal Join the chat at https://gitter.im/orhanobut/logger Build Status

Logger

Simple, pretty and powerful logger for android

Setup

Download

implementation 'com.orhanobut:logger:2.2.0'

Initialize

Logger.addLogAdapter(new AndroidLogAdapter());

And use

Logger.d("hello");

Output

Options

Logger.d("debug");
Logger.e("error");
Logger.w("warning");
Logger.v("verbose");
Logger.i("information");
Logger.wtf("What a Terrible Failure");

String format arguments are supported

Logger.d("hello %s", "world");

Collections are supported (only available for debug logs)

Logger.d(MAP);
Logger.d(SET);
Logger.d(LIST);
Logger.d(ARRAY);

Json and Xml support (output will be in debug level)

Logger.json(JSON_CONTENT);
Logger.xml(XML_CONTENT);

Advanced

FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
  .showThreadInfo(false)  // (Optional) Whether to show thread info or not. Default true
  .methodCount(0)         // (Optional) How many method line to show. Default 2
  .methodOffset(7)        // (Optional) Hides internal method calls up to offset. Default 5
  .logStrategy(customLog) // (Optional) Changes the log strategy to print out. Default LogCat
  .tag("My custom tag")   // (Optional) Global tag for every log. Default PRETTY_LOGGER
  .build();

Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));

Loggable

Log adapter checks whether the log should be printed or not by checking this function. If you want to disable/hide logs for output, override isLoggable method. true will print the log message, false will ignore it.

Logger.addLogAdapter(new AndroidLogAdapter() {
  @Override public boolean isLoggable(int priority, String tag) {
    return BuildConfig.DEBUG;
  }
});

Save logs to the file

//TODO: More information will be added later

Logger.addLogAdapter(new DiskLogAdapter());

Add custom tag to Csv format strategy

FormatStrategy formatStrategy = CsvFormatStrategy.newBuilder()
  .tag("custom")
  .build();

Logger.addLogAdapter(new DiskLogAdapter(formatStrategy));

How it works

More

  • Use filter for a better result. PRETTY_LOGGER or your custom tag
  • Make sure that wrap option is disabled
  • You can also simplify output by changing settings.

  • Timber Integration
// Set methodOffset to 5 in order to hide internal method calls
Timber.plant(new Timber.DebugTree() {
  @Override protected void log(int priority, String tag, String message, Throwable t) {
    Logger.log(priority, tag, message, t);
  }
});

License

Copyright 2018 Orhan Obut

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Extension points exported contracts — how you extend this code

LogAdapter (Interface)
Provides a common interface to emits logs through. This is a required contract for Logger. @see AndroidLogAdapter @see [6 …
logger/src/main/java/com/orhanobut/logger/LogAdapter.java
FormatStrategy (Interface)
Used to determine how messages should be printed or saved. @see PrettyFormatStrategy @see CsvFormatStrategy [17 implementers]
logger/src/main/java/com/orhanobut/logger/FormatStrategy.java
LogStrategy (Interface)
Determines destination target for the logs such as Disk, Logcat etc. @see LogcatLogStrategy @see DiskLogStrategy [18 implementers]
logger/src/main/java/com/orhanobut/logger/LogStrategy.java
Printer (Interface)
A proxy interface to enable additional operations. Contains all possible Log message usages. [2 implementers]
logger/src/main/java/com/orhanobut/logger/Printer.java

Core symbols most depended-on inside this repo

log
called by 37
logger/src/main/java/com/orhanobut/logger/Printer.java
toString
called by 26
logger/src/main/java/com/orhanobut/logger/Utils.java
checkNotNull
called by 23
logger/src/main/java/com/orhanobut/logger/Utils.java
d
called by 21
logger/src/main/java/com/orhanobut/logger/Printer.java
build
called by 17
logger/src/main/java/com/orhanobut/logger/CsvFormatStrategy.java
log
called by 12
logger/src/main/java/com/orhanobut/logger/FormatStrategy.java
equals
called by 8
logger/src/main/java/com/orhanobut/logger/Utils.java
logLevel
called by 8
logger/src/main/java/com/orhanobut/logger/Utils.java

Shape

Method 183
Class 25
Interface 4

Languages

Java100%

Modules by API surface

logger/src/test/java/com.orhanobut.logger/LoggerPrinterTest.java29 symbols
logger/src/main/java/com/orhanobut/logger/PrettyFormatStrategy.java21 symbols
logger/src/test/java/com.orhanobut.logger/LoggerTest.java16 symbols
logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java15 symbols
logger/src/main/java/com/orhanobut/logger/Logger.java15 symbols
logger/src/test/java/com.orhanobut.logger/PrettyFormatStrategyTest.java13 symbols
logger/src/test/java/com.orhanobut.logger/LogAssert.java13 symbols
logger/src/main/java/com/orhanobut/logger/Printer.java13 symbols
logger/src/main/java/com/orhanobut/logger/CsvFormatStrategy.java12 symbols
logger/src/test/java/com.orhanobut.logger/UtilsTest.java11 symbols
logger/src/main/java/com/orhanobut/logger/Utils.java8 symbols
logger/src/main/java/com/orhanobut/logger/DiskLogStrategy.java8 symbols

For agents

$ claude mcp add logger \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact