From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,86b57370403509bc,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!c13g2000vbr.googlegroups.com!not-for-mail From: dhenry Newsgroups: comp.lang.ada Subject: Disabling string evaluation in a logging system Date: Tue, 18 May 2010 00:48:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 80.156.46.53 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1274168919 16861 127.0.0.1 (18 May 2010 07:48:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 18 May 2010 07:48:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c13g2000vbr.googlegroups.com; posting-host=80.156.46.53; posting-account=EZVF2goAAABmd4nprEqIYBBoiiKbAL2e User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.0.19) Gecko/2010040116 Ubuntu/9.04 (jaunty) Firefox/3.0.19,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11701 Date: 2010-05-18T00:48:38-07:00 List-Id: 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.