In my previous blog post I showed how I implemented console logging in my DOTS projects. As I mentioned already yesterday, I prefer using logMessage respectively logException which are both implemented in the ServerConsole class of DOTS.
Both methods can easily be used directly inside your tasklet. When my first tasklet was growing, I started implmenting my own classes. Thereby I realised that logMessage and logException both are not available outside the tasklet class.
As these methods are implemented inside an own class "ServerConsole" I need an object of this class to use these methods. First I declare an object of type ServerConsole. In my case this object is in my class header and initialized in the class constructor. Thus I can use this object anywhere in my class - and even outside my class as it is declared as a public object.
In my DOTS projects I usually declare one ServerConsole object in one of my classes and use this object anywhere possible.
Beyond this approach I was pointed into two different directions today:
Rene Winkelmeyer mentioned another useful approach in a comment here. If you want to log outside of the tasklet class you can easily use ServerTaskManager.getInstance().logMessageText("").
So if you only want to log messages, this might be the easiest solution for you. However, if you want to log messages and/or exceptions, the ServerConsole class is your friend...
OR you go down the road that Serdar suggested in his comment here. and use his Logger class.
He created an own TaskletLogger class which extends another Logger class. I haven't tried it out yet, but I am pretty sure it works great :)
Speaking of logger classes, I think I have to mention the XPages OpenLog Logger OpenNTF project by Paul Withers which can be used from OSGi extensions too.
To make a long story short: there are many options available - and while writing this update post I am realizing that this "blogging thing" revealed a lot of good new stuff to explore ;-)
Showing posts with label Tasklets. Show all posts
Showing posts with label Tasklets. Show all posts
Tuesday, 19 November 2013
Monday, 18 November 2013
DOTS: Logging to server console and log.nsf
In one of my current development projects I am developing a DOTS server task(let). One thing that I found very annoying is the logging part of DOTS. With logging, I essentially mean - at least in this post - an output to the server console and / or log.nsf. To achieve this, there are basically two different possibilities for logging in your DOTS projects.
Option 1: System.out.println
As in other Java projects you can use System.out.println("your message") to print out message to the server console.
Running this little tasklet results in the following output on the server's console:
As you can see, the message is printed to the console. What you cannot see from here is that these messages are not save to log.nsf.
Option 2: logMessage
A way better logging is provided by a specific method logMessage("your message") which is part of the class com.ibm.dots.task.ServerConsole.
While your cord resides inside the tasklet you can easily use this method instantly without any further declarations:
The output looks like that:
Using this method has several benefits:
Moreover, the ServerConsole class provides another very useful method "logException" which accepts a throwable Java Exception which then will be printed to the console. In other words: you can use this method in any catch statemen to handle error logging to the server console / log.nsf.
Option 1: System.out.println
As in other Java projects you can use System.out.println("your message") to print out message to the server console.
Running this little tasklet results in the following output on the server's console:
Option 2: logMessage
A way better logging is provided by a specific method logMessage("your message") which is part of the class com.ibm.dots.task.ServerConsole.
While your cord resides inside the tasklet you can easily use this method instantly without any further declarations:
The output looks like that:
Using this method has several benefits:
- Messages logged using the logMessage method are saved to log.nsf.
- You can see the date and time of the message.
- In addition, the message indicates that it comes from the DOTS Tasklet "Helloworld".
Moreover, the ServerConsole class provides another very useful method "logException" which accepts a throwable Java Exception which then will be printed to the console. In other words: you can use this method in any catch statemen to handle error logging to the server console / log.nsf.
Saturday, 14 September 2013
Domino OSGi Tasklet Services - some useful links
I am currently working on a DOTS project. Since I have started this project I benefited a lot from various community resources out there. First of all, thank you very much to the originating authors for sharing these resources with all of us! I was thinking that starting a link collection for DOTS might be a good idea for others who want dive deeper in this topic...
So this is a list of some valuable resources I used :
Feel free to add more links in the comments section :)
So this is a list of some valuable resources I used :
- Presentation from BLUG by Frank van der Linden:
The power of DOTS
This presentation is very useful if you want to get a comprehensive overview of DOTS and details on how to setup a development environment to get started! - Various DOTS-related Blog Posts by Serdar Basegmez
- IBM Connect 2013 Session Slide by Bruce Elgort and Serdar Basegmez:
BP207 - Meet the Java Application Server you already own - IBM Domino - OpenNTF video by Niklas Heidloff:
Extend Domino Servers via OSGi/Java
This video also shows how to setup Eclipse as well as Domino and some samples. - OpenNTF DOTS project page
- ICONUK presentation by Serdar Basegmez and Frank van der Linden:
Background Tasks: An XPager's Guide to Process Server-Side Jobs on Domino - NotesIn9 093: Introduction to DOTS by Serdar Basegmez
- Another helpful Blog Post by Rene Winkelmeyer with some interesting details you should not miss:
DOTS - considerations about a real cool gem for IBM Domino
Feel free to add more links in the comments section :)
Subscribe to:
Posts (Atom)