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.
I think it's worth to say that logMessage("") only works directly in the Tasklet class. If you want to log outside of that class you can use ServerTaskManager.getInstance().logMessageText("").
ReplyDeleteIn addition I highly recommend to look at log4j2 (http://logging.apache.org/log4j/2.x/). It works like a charm in combination with DOTS and you'll see big performance gains against NSF based logging.
Hi Rene,
Deletethanks for your feedback. I was going to update the post to include some info about logging outside the ServerTask today. I was not aware of the ServerTaskManager.getInstance().logMessageText() which is really straightforward to use. And logging into my own log file is another thing worth looking into. Thanks for letting me know, I will definately add this to the post!
I have developed a very simple class using ServerConsole in CollaborationToday - FeedMonster.
ReplyDeletehttps://github.com/OpenNTF/collaborationtoday/blob/master/DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/shared/TaskletLogger.java
It extends the Logger class:
https://github.com/OpenNTF/collaborationtoday/blob/master/DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/shared/Logger.java
You can see how I used it here:
https://github.com/OpenNTF/collaborationtoday/blob/master/DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/QueueManager.java
Cool stuff. Thanks, Serdar. I will be looking into this, too :)
Delete