{"id":16838509,"url":"https://github.com/zserge/log","last_synced_at":"2025-03-17T04:33:26.913Z","repository":{"id":33434853,"uuid":"37080170","full_name":"zserge/log","owner":"zserge","description":"Ultimately minimal (yet very convenient) logger for Android and Java","archived":false,"fork":false,"pushed_at":"2016-06-21T06:50:34.000Z","size":36,"stargazers_count":156,"open_issues_count":5,"forks_count":17,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-10-14T12:23:37.213Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zserge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-08T16:55:29.000Z","updated_at":"2024-07-20T14:32:02.000Z","dependencies_parsed_at":"2022-09-12T19:31:48.733Z","dependency_job_id":null,"html_url":"https://github.com/zserge/log","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Flog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Flog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Flog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Flog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zserge","download_url":"https://codeload.github.com/zserge/log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221672133,"owners_count":16861383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T12:24:01.455Z","updated_at":"2024-10-27T11:59:19.562Z","avatar_url":"https://github.com/zserge.png","language":"Java","funding_links":[],"categories":["日志库"],"sub_categories":["Spring Cloud框架"],"readme":"# Ultimately minimal (yet very convenient) logger for Android and Java.\n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-log-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1958)\n[![Build Status](https://travis-ci.org/zserge/log.svg?branch=master)](https://travis-ci.org/zserge/log)\n\nLog is a super-simple drop-in replacement for `android.util.Log` that can also\nbe used in normal Java projects.\n\n## Features\n\n```java\n\n// API is backwards-compatible with android.util.Log, so you already know it.\nLog.d(tag, \"X equals \" + x);\n\n// Safe logging for multiple comma-separated values\nLog.d(tag, \"X\", x)\n\n// Tag is optional, by default it equals to the class name \nclass Foo {\n\tpublic void foo() {\n\t\tLog.d(\"Hello\"); // prints 'D/Foo: Hello'\n\t}\n}\n\n// If tag or TAG field is found - it overrides the class name\nclass Foo {\n\tprivate final static String tag = \"Bar\";\n\tpublic void foo() {\n\t\tLog.d(\"Hello\"); // prints 'D/Bar: Hello'\n\t}\n}\n\n// And it's still compatible with your old code\nclass Foo {\n\tprivate final static String TAG = \"Bar\";\n\tpublic void foo() {\n\t\tLog.d(TAG, \"Hello\"); // prints 'D/Bar: Hello', not 'D/Bar: Bar Hello'\n\t}\n}\n\n// Even if you used different tag field names\nclass Foo {\n\tstatic {\n\t\tLog.useTags(new String[]{\"tag\", \"TAG\", \"MYTAG\", \"_TAG\", \"iLoveLongFieldName\"});\n\t}\n\tprivate final static String _TAG = \"Bar\";\n\t...\n}\n\n// Support for Throwables\nException e = new Exception(\"foo\");\nLog.d(\"Something bad happened\", someObject, \"error:\", e); // A log message and a stack trace will be printed\n\n// Chainable API\nLog\n\t.d(\"First\")\n\t.d(\"Second\")\n\t.d(\"Third line\")\n\n// Filters by log level\nLog.level(Log.I);\nLog.d(\"foo\"); // will be ignored\n\n// Format strings are suported, too\nLog.useFormat(true);\nLog.d(\"X equals %d\", x); // prints 'X equals 42'\n// But if no format is provided - log will be printed as multiple values\nLog.d(\"Value of X\", x); // prints 'Value of X 42'\n\n// Long messages are wrapped on newlines\n// If the message doesn't contain newlines and is longer than 4000 symbols\n// (like compact JSONs or HTML) - it will be wrapped on whitespace or punctuation\nLog.d(\"Hello\\nworld\"); // prints 'D/SomeTag: Hello' and 'D/SomeTag: world'\n\n// On Android logs are printed via android.util.Log by default.\n// On other JVMs logs are printed via System.out.println by default.\n// Unless specified otherwise\nLog.usePrinter(Log.SYSTEM, true).usePrinter(Log.ANDROID, false).d(\"hello\"); // will be printed via System.out on Android as well\nLog.usePrinter(mMyPrinter, true); // or you can use your own custom printers\n\n// If you want to disable debug printing for Release build\nif (!BuildConfig.DEBUG) {\n  Log.usePrinter(Log.ANDROID, false); // from now on Log.d etc do nothing and is likely to be optimized with JIT\n}\n\n// And it's only a single class of 200 LOC, so don't be afraid that it will\n// bloat your APK or slow down your builds.\n```\n\n## Installation\n\nbuild.gradle:\n\n``` gradle\nrepositories {\n\tjcenter() // mavenCentral() would work, too\n}\ndependencies {\n\tcompile 'co.trikita:log:1.1.5'\n}\n```\n## Migration from android.util.Log\n\nIf you already have a big project and want to use this logger right now - you\ncan just change imports using 'sed' (Linux/Mac/Cygwin):\n\n``` bash\n$ find -name \"*.java\" -type f -exec sed -i 's/import android.util.Log/import trikita.log.Log/g' {} \\;\n```\n\nIf you're using Android Studio: in the project pane right-click on the `app/java`\ndirectory (or any other directory containing your java classes). In the popup\nmenu select \"Replace in Path...\" option.\n\n'Text to find' should be \"android.util.Log\".\n'Replace with' should be \"trikita.log.Log\".\nClick Find, click All files.\n\nIf you know an easier way (or for different IDE) - let me know.\n\n## How is it different from...\n\nHere is a list of other popular loggers for Android: https://android-arsenal.com/tag/57\n\nMost of them are too specific (logging to file or socket, or printing logs on screen).\nSome of them are too complicated (Twig, SLF4J and every other logger that has factories).\nBut some of them are really nice, so that my logger was inspired by them.\n\nThese loggers are simple and put class and method names into the log message automatically.\nHowever they only support a single string parameter so you will end up with \n`\"X = \"+x+\", y=\"+y` in most of your logs.\n\n* https://gist.github.com/shkschneider/4a9849468b80deb172a9 \n* https://github.com/MustafaFerhan/DebugLog\n\nThis two are very similar to my logger, but the first one is a bit bloated and\nthe both don't support comma-separated values, only format-like strings:\n\n* https://github.com/noties/Debug\n* https://github.com/liaohuqiu/android-CLog\n\nAnd of course there are Jake Wharton's hugo and timber. Hugo is nice, but I\ndidn't need to log/profile my methods, I only need to print log messages from time to\ntime.\n\nTimber was my favourite choice, but I don't use it because of the name. I\nunderstand that it's really clever, but my hands are too much used to start log\nlines with the letter \"L\", not \"T\". And timber also doesn't support\ncomma-separated values, only format strings.\n\n## License\n\nCode is distributed under MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Flog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzserge%2Flog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Flog/lists"}