Logger

I want to develop an application which will perform Logging. I have read about slogger but i have few things to confirm:

1: I will use slogf() to wrote log messages in my .cpp file say clog.cpp. so where should the log messages get stored?

2: How the user can see the log messages like they can view opening file but at screen when any error occure therr would be some dialog appears to indicate that error has occured…Can it be possible with slogger???

more serious question:
1: I want to know about the logging level means messages to be conditionally logged like only those messages should be logged foe example if I use only debug messages should be logged then release mode messages should be skipped off so that compilation time can be saved

Please answer the questions soon.

  1. The messages are in a circular buffer controlled by QNX. For your purposes, you can assume their stored in a ‘file’ at /dev/slog
  2. You can view the messages either with sloginfo or by opening /dev/slog and calling read(). As for displaying a dialog box, there is no built-in mechanism for displaying a dialog box when an error occurs (where would the dialog box go on an embedded system?). If you’re using photon you can use something like PtAlert() or ApError() to display the error message easily. Hope that helps.

1 (serious). When you start slogger you can specify a minimum severity for logging (slogger -f severity). Using this, you can write your debug messages to the lowest level (7) and if you no longer wanted those messages logged, simply start slogger at a higher level for example slogger -f 5. However this has nothing to do with saving compile time, it simply setups up the logger to ignore lower priority messages. If you want your developer debug messages to be completely out of the released code you’ll have to use a compile flag. (i.e. #ifdef)

Soniavts,

The system logger (slogger) rewrites over the old log file every time QNX boots. If you need your log files to be persistant between reboots then slogger isn’t going to work for you.

  1. The log messages can be stored where ever you want by using the -l option to slogger.

  2. The user can view the log file with the sloginfo command. There is no automatic way to inform users/another process that a log message was written to the log file. You would have to write all that logic yourself by continually monitoring the log file. Plus the system logger is a general logging area for any process under QNX so there would be log messages there other than ones your apps log. Is this what you want?

Conditional logging levels have nothing to do with release/debug mode compilation. The decision to log is determined at run time but the code is always present unless you #ifdef it out in some way.

If you are looking for persistent logs (between reboots) and looking to pop up an error message (graphically in Photon I assume) whenever an error is logged you are WAY better off writing your own logger solution (esp if you aren’t interested in log messages other than those your app creates). You can start by getting the source to slogger on Foundry27 and then modifying that for your own use (adding persistant log files and a method to inform another process that a log message was received).

Tim

but simple logging is possible in this way na:
1: I create a method in my cpp file names as errorMessage() and call slof() in this method to log the messages?
this is the proper way of logging in QNX for embedded systems?

I want a simple application to log the messages in the log file in QNX…Is there any application present on Foundry27 where logging has been used???

Soniavts,

Definitely you can do simple logging using the method you describe. If that’s all you require then it will be fine. The hard part will be trying to pop up an error message to a user as there is no built-in facility to do so.

Tim

Is there any Trace*() method available with QNX? If yes , I need the example how to implement that…Can i use this method in debug mode?

How to check from code whether the slogger utility is running or not? if running do this else print error(slogger not working)?

Sorry for so many questions at one time…but i need answers urgently.
If i set the severity level while starting slogger using -f option…

Can i check which severity level has been set through the code?
for ex I pass severity level in mymethod(severitylevel = 3)
now I want to execute the method only if this matches with the severity level passed in slogger -f

Soniavts,

There are only 2 ways to determine the severity level:

  1. Your program spawns slogger itself in which case you know the severity level you spawned slogger at.
  2. Using the system() command you issue a ‘pidin A’ command and parse the results looking for slogger and the severity level it was started at.

To check whether slogger is running you can try to open /dev/slog as read-only. If that fails the logger is not running.

Tim