Comments (5)
Hi Peter,
I have a few questions before being able to analyse your issue:
- Do you configure tinylog via
tinylog.properties
or do you set the configuration manually in your code? - Do you use tinylog with any third-party logging API? If yes, which do you use?
- Do you see any log output of you app before
Error initializing logging: java.lang.UnsupportedOperationException: Configuration cannot be changed after applying to tinylog
? - Do you try to double configure tinylog by yourself or is this a side effect of your third-party SDK?
from tinylog.
Hi Martin,
thanks for getting back to me, let me try and answer you queries to paint the full picture so to speak.
- Do you configure tinylog via
tinylog.properties
or do you set the configuration manually in your code?
I'm using a tinylog.properties file located in src/main/resources for the Android application.
- Do you use tinylog with any third-party logging API? If yes, which do you use?
No, no third-party loggin API is used, none such as described in the tinylog docs
- Do you see any log output of you app before
Error initializing logging: java.lang.UnsupportedOperationException: Configuration cannot be changed after applying to tinylog
?
Yes, I do. What I am seeing is and - besides of the very first log statement - I know for a fact this is right from the MainActivity's onCreate():'
2023-07-16 15:57:19.885 20405-20405/com.example W/System.err: LOGGER WARN: Cannot create link to latest log file on Android
2023-07-16 15:57:19.892 20405-20405/com.example I/MainActivity: App v1.9.5 MainActivity created. Hello!
2023-07-16 15:57:19.892 20405-20405/com.example I/MainActivity: App file logging with tinylog initialized.
2023-07-16 15:57:19.893 20405-20405/com.example I/MainActivity: Logs can be found in /storage/emulated/0/Android/data/com.example/files .
which then leads to the excpetion being logged - two times in fact:
2023-07-16 15:57:20.231 20405-20405/com.example E/AndroidPlatform: Error initializing logging java.lang.UnsupportedOperationException: Configuration cannot be changed after applying to tinylog at org.tinylog.configuration.Configuration.set(Configuration.java:288)
Where this class AndroidPlatform
is from the 3rd party sdk.
- Do you try to double configure tinylog by yourself or is this a side effect of your third-party SDK?
This must be a side effect of the mentioned third-party SDK when its being used as a gradle dependency in the Android application.
Here is more of the exception being output to the logcat - I redacted the package name as this 3rd party SDK is under NDA unfortunately:
2023-07-16 15:57:20.237 20405-20405/com.example E/AndroidPlatform: 16 Jul 2023 13:57:20 [AndroidPlatform]: Error initializing logging: java.lang.UnsupportedOperationException: Configuration cannot be changed after applying to tinylog
at org.tinylog.configuration.Configuration.set(Configuration.java:288)
at com.3rdPartySDK.core.android.platform.AndroidPlatform$Companion.initLogging(AndroidPlatform.kt:451)
at com.3rdPartySDK.core.android.platform.AndroidPlatform$Companion.init(AndroidPlatform.kt:431)
at com.3rdPartySDK.core.android.framework.3rdPartySDKServiceConnection$Companion.bindServiceToActivity(3rdPartySDKServiceConnection.kt:75)
...
As you can probably alread see the 3rd Party SDK is setting its configuration manually in the code using the Configration class of tinlyog inside an AndroidPlatform.kt file. There a method initLogging is being called from the method init in there.
Here is the code that is doing the configuration (AndroidPlatform.kt:451 onwards)
private fun initLogging(context: Context) {
try {
val logFileDir =
File(context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)?.toURI())
Configuration.set("writer", "rolling file")
Configuration.set("writer.format", "{level}: {message}")
Configuration.set("writer.file", "${logFileDir.absolutePath}/log.txt")
Configuration.set("writer.charset", "UTF-8")
Configuration.set("writer.policies", "size: 9mb")
Configuration.set("writer.backups", "0")
} catch (t: Throwable) {
Log.e("AndroidPlatform", "Error initializing logging", t)
errorHandler?.logException(t)
}
}
Let me know if this helps for further analysis.
Thank you and best regards,
Peter
from tinylog.
Hi Peter,
It looks like that some log method is called somewhere before initLogging(context: Context)
is initially called, or initLogging(context: Context)
is called twice.
We can investigate the call flow by setting break points and debugging the app:
- Set a break point to all public methods of
org.tinylog.Logger
- Set a break point to
set()
andreplace()
inorg.tinylog.configuration.Configuration
If a break point of org.tinylog.Logger
triggers before any of the break points in org.tinylog.configuration.Configuration
, we will know what logic has to be refactored to ensure that tinylog will be fully initialized before issuing any log entries.
If you see that initLogging(context: Context)
is called twice or there is some other code that tries to configure tinylog, you will have to refactor the initialization of tinylog to ensure that there is only one attempt.
from tinylog.
Hi Martin @pmwmedia ,
thanks for your pieces of advice and the patience waiting for my reply - I've managed to debug the application and call flow of the methods involved.
Short summary with a follow-up question
Disclaimer: in the initial issue opening message I wrote
[...] which renders file logging unusable as the logging stops after this exception during app startup. [...]
This turns out to be incorrect, logging of the tinylog logger configured in the main android application continues to log :)
However, everytime on app startup - because the mentioned 3rd party SDK is attempting to change the tinylog configuration - the mentioned exception above is being thrown, caught and logged, too!
Logging of the already configured tinylog logger then continues as needed.
The multiple log messages seen in logcat are due to the 3rd party sdk calling a logging method which in turn calls
android.util.Log.e(tag, message, throwable)
and (tinylog) Logger.error(throwable, "{} [{}]: {}", getTimeStamp(), tag, message)
which is still in the configuration of the logger of the main android application that is there from app start. This logger writes to a file with one writer and with another writer to the logcat as well.
So, thanks for the clear hint to debug it in detail, that was very helpful.
Would you be aware of how to remedy the situation?
e.g. ensure that the 3rd party SDK library cannot change the configuration of tinylog as defined in our main android application?
I saw that for tinylog v3 change of configuration during runtime shall be permitted and I'm afraid this would become an issue then.
Thank you in advance Martin if you could recommend an approach to have the 3rd party SDK not get in the way of things of the main android app.
I can provide further information and a long summary if required.
Do not hesitate to let me know if you have any queries.
Best regards
Peter
from tinylog.
Hi Peter,
I don't know why, but I have missed your response. I'm really sorry! Is this issue still relevant? If yes, a minimal reproduction project would really help to find the root issue.
from tinylog.
Related Issues (20)
- Add overloaded "isEnabled" method that takes loggerClassName instead of callerDepth HOT 1
- org.slf4j.LoggerFactory.getLogger fails with java.lang.NoClassDefFoundError: org/slf4j/spi/LoggingEventAware after upgrading to 2.6.0 HOT 3
- more verbose than necessary HOT 3
- Multiple Log Files created when rollover is initiated HOT 1
- Trying to use thread placeholder on Rolling File writer HOT 3
- tinylog not logging some messages when used via SLF4J 2.0 fluent API HOT 1
- Why Can't I find this package anywhere org.tinylog.rules HOT 1
- No clear way how to integrate with FastCSV HOT 1
- JSON Logging to the Console HOT 3
- Is there a way to tell if the logger is still active? HOT 2
- Format time in UTC timezone HOT 1
- tinylog.properties does not seem to be read in version 2.6.2, but works in 2.5.0. HOT 3
- Logger class is missing stack trace error HOT 3
- Date placeholder in file name does not get applied HOT 3
- When attempting to build latest, I can't transfer animal-sniffer HOT 1
- How to programmatically set the log file path๏ผ HOT 2
- How to skip the log output of third-party packages? HOT 2
- I am getting error while using tinylog in my Android Kotlin project HOT 8
- TinyLog doesn't honor default log level HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinylog.