标签: timber-android

Android/Kotlin:未解决的参考:木材

我正在尝试为 Android 编写 kotlin 库,但不能包含木材。我总是收到以下错误:

Error:error: unresolved reference: timber
Run Code Online (Sandbox Code Playgroud)

我的 build.gradle 中有这个:

apply plugin: 'java-library'
apply plugin: 'kotlin'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        maven {url "https://maven.google.com"}
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    compile 'com.jakewharton.timber:timber:4.5.1'
    testCompile 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)

我的源文件目前非常简单:

package net.mbonnin.test

import timber.log.Timber

class Main() {

    fun main() {
        Timber.d("hello world")
    }
} …
Run Code Online (Sandbox Code Playgroud)

android kotlin timber-android

4
推荐指数
1
解决办法
1966
查看次数

将所有异常写入文件

我正在使用 Timber 将一些日志写入位于设备上的文件。现在,我正在使用 HTTP 拦截器编写我选择的日志和来自服务器的一些响应。但我想在文件中写入所有异常(例如致命的)。木材或其他图书馆可以吗?

现在我正在使用 Fabric,但我的应用程序并不总是与外部世界有互联网连接

PS我想在没有try/catch的情况下编写所有致命异常

TimberLooger.class

public class FileLoggingTree
{
    /**
     * Sends an error message to LogCat and to a log file.
     * @param context The context of the application.
     * @param logMessageTag A tag identifying a group of log messages. Should be a constant in the
     *                      class calling the logger.
     * @param logMessage The message to add to the log.
     */
    public static void e(Context context, String logMessageTag, String logMessage)
    {
        if (!Log.isLoggable(logMessageTag, Log.ERROR)) …
Run Code Online (Sandbox Code Playgroud)

android timber-android

3
推荐指数
1
解决办法
1200
查看次数

由于棉绒和木材,Gradle 清洁失败

在 Windows 7 上使用 Android Studio 1.5.1 和 gradle 2.8 或 2.10,尝试运行 gradle clean 时出现以下错误(仅在使用 Timber 时):

gradle clean
Incremental java compilation is an incubating feature.                           
WARNING [Project: :app] To shrink resources you must also enable ProGuard         
:clean                                                                               
:app:clean FAILED          

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:clean'.
> Unable to delete file: C:\blabla\app\build\intermediates\exploded-aar\com.jakewharton.timber\timber\4.1.0\jars\lint.jar

* Try:         
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get …
Run Code Online (Sandbox Code Playgroud)

android lint gradle android-lint timber-android

2
推荐指数
1
解决办法
1169
查看次数

在具有自动标记功能的单独模块中使用木材

我想在单独的模块中使用 wood 来处理我的 Android 应用程序中的日志记录,以便可以从任何模块调用它并记录到内部文件。

问题是,当在单独的类中使用自动标记而不是直接调用木材日志方法时,自动标记不起作用。

例如,我有一个日志记录类,其方法为Logger.kt

fun d(message: String)
{
    Timber.d(message)
}
Run Code Online (Sandbox Code Playgroud)

但是当我从任何地方调用它时,它显然使用日志类作为标记,而不是调用该方法的类。

所以我的问题是,如何通过此方法自动传递调用类?我不想添加像“TAG = classname”这样的附加变量,因为在这种情况下我也可以使用正常的日志记录。

是否可以检索方法的调用类?或者有更好的方法来进行集中日志记录吗?主要目的是不必定义 TAG 变量,同时还能够稍后添加文件日志记录。

logging android kotlin timber-android

1
推荐指数
1
解决办法
962
查看次数

标签 统计

android ×4

timber-android ×4

kotlin ×2

android-lint ×1

gradle ×1

lint ×1

logging ×1