Home > Articles > Software Development & Management

  • Print
  • + Share This
This chapter is from the book

Thus far, all our decisions about what to log and where to send the output have been determined at compile time. In many cases, it is unreasonable to require a recompile to change the logging options. We could, of course, provide parameters or a configuration file to our application, but we would have to spend valuable time writing and debugging that code. Fortunately, ACE has already provided us with a convenient solution in the form of the ACE_Logging_Strategy object.

Consider the following file:

dynamic Logger Service_Object * ACE:_make_ACE_Logging_Strategy()
"-s log.out -f STDERR|OSTREAM -p INFO"

We've seen this kind of thing before when we were talking about the distributed logging service. In this case, we're instructing the ACE Service Configurator to create and configure a logging strategy instance just like the distributed logging server. Again, the Service Configurator is an advanced topic with many exciting features2 and is covered in Chapter 19.

The following sample application uses the preceding file:

int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
  if (ACE_Service_Config::open (argc,
                                1) < 0)
                       ACE_TEXT ("Service Config open")),
    ACE_TRACE (ACE_TEXT ("main"));
    ACE_DEBUG ((LM_NOTICE, ACE_TEXT ("%t%IHowdy Pardner\n")));
    ACE_DEBUG ((LM_INFO, ACE_TEXT ("%t%IGoodnight\n")));

    return 0;

The key is the call to ACE_Service_Config::open(), which is given our command line parameters. By default it will open a file named svc.conf, but we can specify an alternative by specifying -f someFile. In either case, the file's content would be something like the preceding, which tells the logging service to direct the output to both STDERR and the file log.out.

Be careful that you call ACE_Service_Config::open() as shown rather than with the default parameters. If the final parameter is not 1, the open() method will restore the logging flags to their preopen values. Because the logging service loads its configuration and sets the logging flags from within the service configuration's open(), you will be unpleasantly surprised to find that the logging strategy had no effect on the priority mask once open() completes.

Recall that, by default, all logging severity levels are enabled at a processwide level. If you specify -p INFO in your config file, you will probably be surprised when you get other logging levels also; they were already enabled by default. To get what you want, be sure to use the disable flags, such as ~INFO, as well; these are listed in Table 3.8.

One of the most powerful features of the logging strategy is the ability to rotate the application's log files when they reach a specified size. Use the -m parameter to set the size and the -N parameter to set the maximum number of files to keep. Authors of long-running applications will appreciate this, as it will go a long way toward preventing rampant disk space consumption.

Table 3.8 lists all the ACE Logging Strategy options that can be specified and their values. The possible values for -p and -t are the same as those listed in Table 3.1, but without the LM_ prefix. Any value can be prefixed with ~ to omit that log level from the output. Multiple flags can be OR'd (|) together as needed.

Table 3.8. ACE Logging Strategy Configuration Options


Arguments and Meaning


Specify ACE_Log_Msg flags (OSTREAM, STDERR, LOGGER, VERBOSE, SILENT, VERBOSE_LITE) used to control logging.


The interval, in seconds, at which the log file size is sampled (default is 0; do not sample by default).


Specify the rendezvous point for the client logger.


The maximum log file size in Kbytes.


Set the program name for the %n format specifier.


The maximum number of log files to create.


Request the standard log file ordering (keeps multiple log files in numbered order). Default is not to order log files.


Pass in the processwide priorities to either enable (DEBUG, INFO, WARNING, NOTICE, ERROR, CRITICAL, ALERT, EMERGENCY) or to disable (~DEBUG, ~INFO, ~WARNING, ~NOTICE, ~ERROR, ~CRITICAL, ~ALERT, ~EMERGENCY).


Specify the file name used when OSTREAM is specified as an output target.


Pass in the per instance priorities to either enable (DEBUG, INFO, WARNING, NOTICE, ERROR, CRITICAL, ALERT, EMERGENCY) or to disable (~DEBUG, ~INFO, ~WARNING, ~NOTICE, ~ERROR, ~CRITICAL, ~ALERT, ~EMERGENCY).


Cause the log file to be wiped out on both start-up and reconfiguration.

  • + Share This
  • 🔖 Save To Your Account