I have been playing somewhat with Microlog, but I have been experiencing some problems in a multithreaded application... I have several classes but they all use one single Logger object (within the main MIDlet), to begin with is this common practice or should every class have its own Logger method ? And if so how do I place all data into a single RMS ?
Mostly the problem is that my application will delete the log at some point (after a check with a server) whilst the other threads/classes might still try to log something so at some point I get :
Failed to log to RecordStore javax.microedition.rms.InvalidRecordIDException
errors, this following the deletion of the log through the loader.clearLog() method...
any ideas and/or considerations ?
I have tried to make the RecordStore thread-safe, but this scenario is not something that I have considered. But I think that it would be possible to solve your issue by making Microlog a little bit "smarter". However I will have to take a deeper look into the code to come up with a solution. Thus I will have to get back with you on that.
I think that it is appropriate to use one RMS/MIDlet. Even if you use one or several Logger instances, there are only a limited number of RMSs available. It is therefore vital that the RecordStoreAppender is thread-safe.
The reason for using several (named) Loggers could be that you wish to separate the logging statements. For example, you could use the Log4j standard that each class have a logger with the class-name as its name. To do this you use:
Logger.getLogger(YourClass.class) to create your logger object.
That last one your mentioning (logger with class name) will that result in several RMS's (one for each class name) or in one single RMS ?
But I did solve the problem by using the Logger.clear() method instead of the Appender one.
Or at least I aint getting the same errors anymore ;)
even if you use several logger instances, they should log to the same record store. But this is not tested very much...
Nice that you got it to work with Logger.clear() method.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.