Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/logPublic

This is a simple log print utils, like android.util.Log.

License

NotificationsYou must be signed in to change notification settings

ohmae/log

Repository files navigation

licenseGitHub releaseGitHub issuesGitHub closed issuesMaven Central

This is a simple log print utils, likeandroid.util.Log.

log

The "log" module is written in kotlin and can be used anywhere in Java / Kotlin projects.

log-android

The "log-android" module is a utility for using the "log" module on Android.

Requirements

  • log

    • Java SE 7 or later
  • log-android

    • Android API Level 14 (Android 4.0.0) or later

And I strongly recommend to use with Lambda. (Kotlin, Java8, desugar, retrolambda, etc.)

Example of use

Initialize

This library needs to set Log Level. Default is never output log.And needs to specify a Sender. Default does nothing.

If you use the default implementation, write as follows.

privatevalDEBUG=trueprivatevalVERBOSE=true...if (DEBUG) {Logger.setLogLevel(Logger.VERBOSE)Logger.setSender(Senders.create())Senders.appendCaller(VERBOSE)Senders.appendThread(VERBOSE)}

for Android

If you write it like this, you can output log to Logcat. (default is System.out)

privatevalVERBOSE=true...if (BuildConfig.DEBUG) {Logger.setLogLevel(Logger.VERBOSE)Logger.setSender(AndroidSenders.create())AndroidSenders.appendCaller(VERBOSE)AndroidSenders.appendThread(VERBOSE)}

Custom sender

Of course you can implement Sender any way.e.g. write to a file or send it to the network, etc.

Logger.setSender {level, message, throwable->...}

If you want to use same format as the default, please try the following:

Logger.setSender(DefaultSender.create { level, tag, message->...})

Log Level

If you set the log level, logs that are equal to or higher than the set value are output.

ASSERT > ERROR > WARN > INFO > DEBUG > VERBOSE

eg. If you set Log.ERROR

Logger.setLogLevel(Log.ERROR)

Only ASSERT or ERROR level logs are output.

logging

Logger.v("verbose")Logger.d("debug")Logger.i("info")Logger.w("warning")Logger.e("error")

Output

Logger.setLogLevel(Logger.VERBOSE)Logger.setSender(Senders.create())
2018-02-24 05:02:05.510 V [MainWindow] verbose2018-02-24 05:02:05.510 D [MainWindow] debug2018-02-24 05:02:05.510 I [MainWindow] info2018-02-24 05:02:05.510 W [MainWindow] warning2018-02-24 05:02:05.510 E [MainWindow] error
Logger.setLogLevel(Logger.VERBOSE)Logger.setSender(Senders.create())Senders.appendCaller(true)Senders.appendThread(true)
2018-02-24 05:02:46.541 V [MainWindow] [main,5,main] net.mm2d.upnp.sample.MainWindow.main(MainWindow.java:57) : verbose2018-02-24 05:02:46.542 D [MainWindow] [main,5,main] net.mm2d.upnp.sample.MainWindow.main(MainWindow.java:58) : debug2018-02-24 05:02:46.542 I [MainWindow] [main,5,main] net.mm2d.upnp.sample.MainWindow.main(MainWindow.java:59) : info2018-02-24 05:02:46.542 W [MainWindow] [main,5,main] net.mm2d.upnp.sample.MainWindow.main(MainWindow.java:60) : warning2018-02-24 05:02:46.542 E [MainWindow] [main,5,main] net.mm2d.upnp.sample.MainWindow.main(MainWindow.java:61) : error

How to use

jCenter will close in May. In 0.9.4 moved to mavenCentral from jcenter.
Please note that thegroupID has changed

Download from mavenCentral.Maven Central

Add dependencies, as following.

dependencies {    implementation("net.mm2d.log:log:0.9.4")}

If use with Android utils, as following.

dependencies {    implementation("net.mm2d.log:log:0.9.4")    implementation("net.mm2d.log:log-android:0.9.4")}

Versions below 0.9.4 were distributed with jCenter.However, jCenter will close and old versions are not migrated to mavenCentral.If you need an older version, please use the Github Pages repository.

repositories {    maven { url=URI("https://ohmae.github.com/maven") }}
dependencies {    implementation("net.mm2d:log:0.9.3")    implementation("net.mm2d:log-android:0.9.3")}

Dependent OSS

  • Kotlin
    • org.jetbrains.kotlin:kotlin-stdlib

Author

大前 良介 (OHMAE Ryosuke)http://www.mm2d.net/

License

MIT License

About

This is a simple log print utils, like android.util.Log.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp