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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,86b57370403509bc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!bnewspeer01.bru.ops.eu.uu.net!bnewspeer00.bru.ops.eu.uu.net!emea.uu.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Disabling string evaluation in a logging system Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Tue, 18 May 2010 10:15:48 +0200 Message-ID: <15grablk8asle$.z2pjxbkmcyhz.dlg@40tude.net> NNTP-Posting-Date: 18 May 2010 10:15:48 CEST NNTP-Posting-Host: 51101df1.newsspool4.arcor-online.net X-Trace: DXC=37enW;^6ZC`4\`mfM[68DC3OM=WXiAk@U1 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:11704 Date: 2010-05-18T10:15:48+02:00 List-Id: On Tue, 18 May 2010 00:48:38 -0700 (PDT), dhenry wrote: > 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; I am using this way, but rather as: if Log.Level in Warning..Severe then Log.Write (...); 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). I don't see much more pollution than a call to Log.Write has already inflicted. > 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. AFAIK, there is no way. But if I were to make a proposal, then I would do the useless pargma Assert useful. E.g. pragma Assert (Condition, Message); [Change] Dynamic semantics: Message is evaluated only if Condition is evaluated to true. Then a user-defined assertion handler is called, if any (to be set by Assertion_Policy). Otherwise Assertion_Error is propagated. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de