logger README

The project's README from github.com/orhanobut/logger. As one markdown file: README.md.

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

// 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.

logger (orhanobut/logger)

Searching Database…

13.8K ·GitHub
这是什么?Logger 是一个简单、美观且功能强大的 Android 日志库,能让 Logcat 的输出更易读。
这是独立应用,还是需要添加到 Android 项目中的库?它是一个 Android/Java/Kotlin 库,你需要将其作为依赖引入,并在应用代码中初始化。它本身没有界面,也不是独立应用。
我该如何把它添加到我的 Android 项目中?下载该库(将其添加为依赖),在应用中初始化一次 Logger,然后在需要格式化输出的地方调用其日志方法。
Logger 的输出与普通的 Android Log 调用有何不同?根据其 GitHub 主题('pretty-printer'、'json-logging'),Logger 会用带结构的边框格式化输出,还能美化打印 JSON,使日志在 Logcat 中比原始的 Log.d 输出更易浏览。
它和 Jake Wharton 的 Timber 库类似吗?该仓库将 'timber' 列为相关主题,这表明 Logger 扮演着类似的角色,即对 Android 的 Log 类进行即插即用的封装,但更侧重于美化输出和 JSON 格式化输出。
它同时适用于 Java 和 Kotlin 的 Android 项目吗?适用。该库本身使用 Kotlin 编写,其主题同时包含 'java' 和 'kotlin',因此用这两种语言编写的 Android 应用都可以使用它。
Creator
orhanobut
Size
1.9 MB
Stars
13.8K
Age
11y
Commits · 90 Days