Giter Site home page Giter Site logo

lumberjack's Introduction

About

Release License

This is a full logging library with a build in way to log to console, file or any custom place as well as optional extensions to send a log file via mail or show it on the device.

📷 Screenshots

Demo Demo Demo Demo

📖 Documentation

The readme for this library with code samples, screenshots and more can be found on following github page:

Static Badge

Additionally there is also a full working demo app inside the demo module.

lumberjack's People

Contributors

mflisar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lumberjack's Issues

Use Timber. and L. together

it would be nice if I can separate the use of L. to log to file, and Timber. as normal (not logging to file) (to prevent #1). Logging to file is why I tried Lumberjack.

Create different instance or store to a different file

Hello! First of all, thank you for this awesome library, it really helped me developing my VOIP app.

Currently I setup the library in the Application class, and use it throughout the app to store all logs in the log file.

`@HiltAndroidApp
class MyApp : Application() {

override fun onCreate() {
    super.onCreate()
    initLumberjackLogger()
}

private fun initLumberjackLogger() {
    // Install the implementation
    L.init(LumberjackLogger)
    L.enable(BuildConfig.DEBUG)

    // Install loggers
    val setup = FileLoggerSetup.Daily(this, fileExtension = FILE_LOGGER_EXTENSION).also {
        FILE_LOGGING_SETUP = it
    }
    L.plant(FileLogger(setup))
}

 companion object {
    const val FILE_LOGGER_EXTENSION = "txt"
    lateinit var FILE_LOGGING_SETUP: IFileLoggingSetup
   lateinit var FILE_LOGGING_SETUP_TEST: IFileLoggingSetup
}

`

What I want to achieve is when I open the CallingActivity class, to store all logs from that activity in the "main" log file but also in a separate file called: call1_2024_03_12.txt for example. I tried to create a new FileLoggerSetup, but from here I don't know how to make all logs to be stored in a different file.

`@AndroidEntryPoint
class CallingActivity : ProximitySensorActivity() {

private lateinit var binding: ActivityCallingBinding
private val viewModel by viewModels<CallingViewModel>()

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    initBinding()
    initLumberjackLogger()
}

private fun initLumberjackLogger() {
    val setup = FileLoggerSetup.Daily(
        context = this,
        fileExtension = MyApp.FILE_LOGGER_EXTENSION,
        fileBaseName = getDynamicCallIdentifier() // returns a dynamic name for each call
    ).also {
            MyApp.FILE_LOGGING_SETUP_TEST = it
    }
    L.plant(FileLogger(setup))
}

`

Can someone give me some suggestions on how I can achieve this?
Thank you!

General - improve filter

Currently you have to define groups and can filter them in the notification logger. This logger should be replaced with the overlay logger and I want to add another grouping feature for it without the need of custom classes (they were only for type safety and for extensibility, but I think there is nothing that can be added to a group than a name).

So what I want:

  • no need to define groups - user can decide to use dynamic strings or define static string constants and uses them
  • the filter function (in the future) should extract all the groups dynamically from the receiver log messages

Synthetic stacktrace didn't have enough elements: are you using proguard?

After adding your library, I am now getting these errors, causing crashes

02-06 13:03:55.226 22472-23118/za.co.demo.app 
E/AndroidRuntime: FATAL EXCEPTION: SyncAdapterThread-2
  Process: za.co.demo.app, PID: 22472
  java.lang.IllegalStateException: Synthetic stacktrace didn't have enough elements: are you using proguard?
      at timber.log.BaseTree.getTag(BaseTree.java:54)
      at timber.log.Timber$Tree.prepareLog(Timber.java:521)
      at timber.log.Timber$Tree.d(Timber.java:417)
      at timber.log.Timber$1.d(Timber.java:239)
      at timber.log.Timber.d(Timber.java:34)
      at za.co.demo.app.adaptors.SyncAdapter.onPerformSync(SyncAdapter.java:278)
      at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:272)

code line number is repeated

The logging output contains the Line number twice. It would be better if it were included once and also if it were clickable still.

Examples:

Existing log:
07-01 10:07:12.446 30867 30867 D [<MyTag@> LogExperiment:24 log]: My test log (LogExperiment.kt:24)

Desired log:
07-01 10:07:12.446 30867 30867 D [<MyTag@> LogExperiment:24 log]: My test log

here is some example code:

    private fun log() {
        log2()
    }

    private fun log2() {
        d { "test log2 "}
        log3()
    }

    private fun log3() {
        d { "test log3 "}
    }
/TestActivity:50 log3]: test log3  (TestActivity.kt:50)

there is no need to include TestActivity twice it could be just:

/TestActivity:50 log3]: test log3 

Could not find com.github.MFlisar:CacheFileProvider:0.2.

We were using Lumberjack in our android project since a long time. Recently, in one of our builds, we came across the following error :

Could not resolve all files for configuration ':fairmatic:debugRuntimeClasspath'.
Could not find com.github.MFlisar:CacheFileProvider:0.2.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/github/MFlisar/CacheFileProvider/0.2/CacheFileProvider-0.2.pom
- file:/home/runner/.m2/repository/com/github/MFlisar/CacheFileProvider/0.2/CacheFileProvider-0.2.pom
- https://jcenter.bintray.com/com/github/MFlisar/CacheFileProvider/0.2/CacheFileProvider-0.2.pom
- https://jitpack.io/com/github/MFlisar/CacheFileProvider/0.2/CacheFileProvider-0.2.pom
- https://s01.oss.sonatype.org/content/repositories/snapshots/com/github/MFlisar/CacheFileProvider/0.2/CacheFileProvider-0.2.pom
Required by:
project :fairmatic > com.github.MFlisar.Lumberjack:lumberjack-feedback:5.2.6 > com.github.MFlisar:FeedbackManager:2.0.3

Please advise on what should be done.
Thanks
PS: We are using Lumberjack 5.2.6 in our project.

Runtime crash

I recently upgraded to Gradle 8.0.1 in my Android project, and that version of Gradle enables R8 full mode by default. Now that that is enabled, I'm getting a crash in release builds:

 java.lang.RuntimeException: Unable to create application com.example.MyApp: java.lang.IllegalStateException: FileNamePattern [/data/user/0/com.example/files/ApplicationLog%i.txt] does not contain a valid IntegerToken
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6776)
	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2129)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7884)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.IllegalStateException: FileNamePattern [/data/user/0/com.example/files/ApplicationLog%i.txt] does not contain a valid IntegerToken
	at p6.b.start(Unknown Source:147)
	at gf.e.<init>(Unknown Source:257)
	at com.example.MyApp.onCreate(Unknown Source:78)
	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1277)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6771)
	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2129) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:201) 
	at android.os.Looper.loop(Looper.java:288) 
	at android.app.ActivityThread.main(ActivityThread.java:7884) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 

The crash occurs in this code in my app:

// We add the file logger to all build configurations
fileLoggingSetup = FileLoggingSetup.NumberedFiles(
    this,
    setup = FileLoggingSetup.Setup(
        fileName = "ApplicationLog",
        fileExtension = "txt",
        logsToKeep = 3
    ),
    sizeLimit = "2MB"
)
L.plant(FileLoggingTree(fileLoggingSetup))

I tracked down the error to the logback library used by Lumberjack:
https://github.com/qos-ch/logback/blob/97e517511e52e9c96357384e751d38050134dd8f/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java#L95

But I can't figure out why the error is occurring. Even in the error message above, there is the %i integer format argument, so I'm not sure what is going on. Has anyone seen this? Any idea how to fix it? Currently I can't release the app until this is resolved, or I will have to disable diagnostic logs in the app.

File Returned By getAllExistingLogFiles() Does Not Exist

We have a mechanism in our app to export all log files. To get the available log files we invoke FileLoggingSetup#getAllExistingLogFiles(). We then copy the files into a different directory that contains other diagnostic files and then zip this folder.

However, while copying the files we noticed that some files returned by getAllExistingLogFiles() do not exist and we get an error while copying.

I looked into the source of FileLoggingSetup but couldn't find anything suspicious that would explain this. It's just weird that a file contained in the returned list does not actually exist.

Lumberjack Version 5.0.3

config.getAllExistingLogFiles().forEach {
            try {
                it.copyTo(File(targetDirectory, it.name))
            } catch (error: Throwable) {
                // here we get the error: The source file doesn't exist.
            }
        }

Overlay logger - Advanced filter options

Instead of showing a toggle button for "errors only" / "all" use a filter option with following options:

  • Filter by log priority level
  • Show messages that are exactly the selected error level or at least
  • Search button

Sending log file by email crashes when FileProvider paths are used in application

We are using the version 6.0.2 of your library and we use the Viewer extension. We also use the lumberjack implementation, not Timber. I'm writing this issue to let you know that when FileProvider is used in the application, a crash occurs when sending a log file by email.

Portion of our build.gradle file:

    def lumberjack = "6.0.2"
    implementation("com.github.MFlisar.Lumberjack:core:$lumberjack")
    implementation("com.github.MFlisar.Lumberjack:implementation-lumberjack:$lumberjack")
    implementation("com.github.MFlisar.Lumberjack:logger-console:$lumberjack")
    implementation("com.github.MFlisar.Lumberjack:logger-file:$lumberjack")
    implementation("com.github.MFlisar.Lumberjack:extension-viewer:$lumberjack")

Simple init:

    L.init(LumberjackLogger)
    fileLoggingSetup = FileLoggerSetup.Daily(context)
    L.plant(FileLogger(fileLoggingSetup))

When we started to use the FileProvider in our application, we needed to add this code block in the AndroidManifest.xml file:

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.example.file-provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

And here is the content of the file_paths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-files-path
        name="pictures"
        path="Pictures" />
</paths>

As a result, when we try to share a log file by email, we get this exception:

FATAL EXCEPTION: main
Process: com.example.myapp, PID: 31371
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.myapp/files/shared-files/log_2024_01_15.log
at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:849)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:452)
at com.michaelflisar.cachefileprovider.CachedFileProvider$Companion.getCacheFileUri(CachedFileProvider.kt:21)
at com.michaelflisar.feedbackmanager.Feedback.buildIntent(Feedback.kt:36)
at com.michaelflisar.feedbackmanager.Feedback.startEmailChooser(Feedback.kt:59)
at com.michaelflisar.lumberjack.extensions.feedback.ExtensionFeedbackKt.sendFeedback(ExtensionFeedback.kt:34)
at com.michaelflisar.lumberjack.extensions.feedback.ExtensionFeedbackKt.sendFeedback$default(ExtensionFeedback.kt:22)
at com.michaelflisar.lumberjack.extensions.viewer.view.LumberjackViewerActivity.onOptionsItemSelected(LumberjackViewerActivity.kt:171)

Since your library creates a copy of the log file in a folder named "shared-files", I added this path in the file_paths.xml file, like below:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-files-path
        name="pictures"
        path="Pictures" />
    <files-path
        name="shared-files"
        path="shared-files/" />
</paths>

Adding the <files-path> tag did the trick. I'm sharing this just in case you would have a better solution to suggest. Adding this use-case to your documentation could also avoid some headaches to other users.

Good work BTW, we like your lib a lot!

Fails to show notification on api 31+

A required flag was added on api 31+ to the pending intent that the library is not adding:

2022-05-05 23:09:27.717 10486-10486/com.savvasdalkitsis.uhuruphotos.debug E/[PendingIntent:375 checkFlags]: java.lang.IllegalArgumentException: com.savvasdalkitsis.uhuruphotos.debug: Targeting S+ {version 31 and above} requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
    	at android.app.PendingIntent.checkFlags{PendingIntent.java:375}
    	at android.app.PendingIntent.getActivityAsUser{PendingIntent.java:458}
    	at android.app.PendingIntent.getActivity{PendingIntent.java:444}
    	at android.app.PendingIntent.getActivity{PendingIntent.java:408}
    	at com.michaelflisar.feedbackmanager.Feedback.startNotification{Feedback.kt:70}
    	at com.michaelflisar.lumberjack.ExtensionNotificationKt.showCrashNotification{ExtensionNotification.kt:41}
    	at com.michaelflisar.lumberjack.ExtensionNotificationKt.showCrashNotification$default{ExtensionNotification.kt:19}
    	at com.savvasdalkitsis.uhuruphotos.log.initializer.LogInitializer.onAppCreated$lambda-0{LogInitializer.kt:44}
   

Log messages do not contain full package name

Is it possible to make the log output contain the full package name instead of just the class name?

It could be as simple as disabling this:

    private fun getSimpleClassName(className: String): String {
        return className.substring(className.lastIndexOf('.') + 1)
    }

Getting parse error when using file logging.

I am using file logging library and everything is working good in debug build but when it comes to release build I am getting parse error for date and tag in console.

expected: Date [ClassName:LineNumber method]: Log
What I am getting is: %PARSER_ERROR[d] [p92:1 z]: log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.