REST easy with kbmMW #10 – Logging to a database

auntjojo - Flckr

In the upcoming release, the logging feature will have been improved in various ways. One of the new inclusions is the TkbmMWVirtualLogManager and its interface IkbmMWVirtualLogManager.

The virtual log manager can for example be used for logging select logs to a database, which this short blog will focus on.

I will in this sample, use kbmMW’s ORM to handle the database access, however any traditional database access method could have been used instead.

Since I want to use the ORM for log storage handling, I need to define a class describing the storage.

The TSystemLog class needs to be registered:

We add a method that we can call to persist the log entry. Notice that if the method is unable to persist the log due to some database issue, an error will be logged on the SystemLog, which is a standard, always existing, alternative logger in kbmMW. It will default output to debug view on Windows, or LogCat on Android.

And at some point before the first time the database log will be used, the database tables needs to be prepared:

And finally I define the TkbmMWVirtualLogManager which in turn calls the MyLog method whenever there is something for this logmanager to handle.

Because I want to put timestamp in a separate field in the database, I redefine the logformatter of this logmanager to only include a few select type of information.

Now every time you use Log.Info/Log.Error/Log.Warning/Log.Fatal or any of the other log methods, the log will be appended to the myLog table in the database.

Remember… if you like the blogs, kbmMW or any of our other products, share the word and your feelings about the products!

 527 total views,  1 views today

Author: kimbomadsen

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.