comp.lang.ada
 help / color / mirror / Atom feed
* Disabling string evaluation in a logging system
@ 2010-05-18  7:48 dhenry
  2010-05-18  8:15 ` Dmitry A. Kazakov
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: dhenry @ 2010-05-18  7:48 UTC (permalink / raw)


Hello,

I have a logging system controlled by a log level (let's say 0 =
disabled, 1 = errors, 2 = error + warnings, ..., 5 = all previous ones
+ debug messages).

A Logging line may look like that:

Log.Write (Text => "Blabla...", Level => 5);

Often, I'll have some formatted text, requiring string conversions and
concatenations. Example:

Log.Write ("Parameter " & To_String (Param_Name) & " Value = " &
Integer'Image (X), Log_Level);

If the Log_Level variable is set to 0 (logging disabled), the
application will still evaluate the Text parameter, before testing the
Level parameter to know if we finally must write it into the file or
not.

I'd like to avoid the string evaluation if the logging is disabled
(because it consumes CPU resources).

A possible solution would be to test the log level before the
procedure call:

if Log_Level > 0 then
  Log.Write ("Parameter " & To_String (Param_Name) & " Value = " &
Integer'Image (X), Log_Level);
end if;

But with thousands of logging lines everywhere in my application, it
will make the code quite unreadable and introduces a lot of if-test
pollution (and it's really boring to write).

In a language like C or C++, I would use the preprocessor:
#define LOG(text, level) if (level > 0) { log.write (text, level) }

I'm wondering how in Ada 95 and/or Ada 2005 I could write such a
logging system (if it's possible). The goal is that logging should not
be too intrusive in my code.

Yours,
David.



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-05-19 19:08 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-18  7:48 Disabling string evaluation in a logging system dhenry
2010-05-18  8:15 ` Dmitry A. Kazakov
2010-05-18  8:45   ` Dmitry A. Kazakov
2010-05-18  9:45   ` Cyrille
2010-05-18 10:26     ` Dmitry A. Kazakov
2010-05-18 12:10       ` Georg Bauhaus
2010-05-18 12:15         ` Georg Bauhaus
2010-05-18 12:54         ` Dmitry A. Kazakov
2010-05-18  9:32 ` Gautier write-only
2010-05-18  9:37   ` Gautier write-only
2010-05-18 11:27   ` Gautier write-only
2010-05-18 12:18     ` dhenry
2010-05-19  9:04       ` Stephen Leake
2010-05-19 12:38         ` Dmitry A. Kazakov
2010-05-19 18:02           ` (see below)
2010-05-19 19:08             ` Adam Beneschan
2010-05-18 10:13 ` stefan-lucks
2010-05-18 18:17   ` Jeffrey R. Carter
2010-05-18 18:40 ` tmoran
2010-05-19  7:47   ` dhenry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox