Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

logger

> 编程语言
Open source

✔️ Simple, pretty and powerful logger for android

13.8K stars0 likes2 views
WebsiteGitHub

About

✔️ Simple, pretty and powerful logger for android

Logger

Simple, pretty and powerful logger for android

Setup

Download

groovy
implementation 'com.orhanobut:logger:2.2.0'

Initialize

java
Logger.addLogAdapter(new AndroidLogAdapter());

And use

java
Logger.d("hello");

Output

Options

java
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

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

Collections are supported (only available for debug logs)

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

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

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

Advanced

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

java
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

java
Logger.addLogAdapter(new DiskLogAdapter());

Add custom tag to Csv format strategy

java
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

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

Issues· 81 open

View all issuesOpen on GitHub
  • #267

    com.orhanobut.logger.LoggerPrinter.logAdapters isNotAThreadSafeCollection

    Updated Dec 31, 2024
  • #268

    When I copy, I always have extra border and tag. How do I remove the border and tag on the left side? I just want to copy pure print without tag and border

    Updated Mar 15, 2024
  • #255

    About some opened issues and niche needs (关于一些未关闭的问题、一些小众需求)

    Updated Jan 12, 2024
  • #269

    The design of the restriction position for "isLoggable" is unreasonable

    Updated Dec 26, 2023
  • #265

    sometimes i don‘t want many line, border, i just like the style like Log.d()..., can add some config ?

    Updated Nov 14, 2023
  • #260

    Androidx suport not completed

    Updated Jun 30, 2023
  • #261

    Is there any API to get the path of log files

    Updated Jun 1, 2023
  • #266

    Security breach

    Updated Dec 1, 2022
  • #262

    Remove legacy com.android.support:support-annotations and use jetpack version of it

    Updated Jun 1, 2022
  • #259

    why does it still run while I have already make isLoggable false??

    Updated Mar 2, 2022

> Tags

Javaandroidjavajson-logginglog

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 2, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言