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!feeder.news-service.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news-1.dfn.de!news.dfn.de!news.uni-weimar.de!not-for-mail From: stefan-lucks@see-the.signature Newsgroups: comp.lang.ada Subject: Re: Disabling string evaluation in a logging system Date: Tue, 18 May 2010 12:13:01 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: Reply-To: stefan-lucks@see-the.signature NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: tigger.scc.uni-weimar.de 1274174462 9650 141.54.178.228 (18 May 2010 09:21:02 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Tue, 18 May 2010 09:21:02 +0000 (UTC) X-X-Sender: lucks@medsec1.medien.uni-weimar.de In-Reply-To: Xref: g2news2.google.com comp.lang.ada:11707 Date: 2010-05-18T12:13:01+02:00 List-Id: On Tue, 18 May 2010, dhenry wrote: [...] > 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. [...] > 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). How about the following? package Log is type Level_Type is range 0 .. 5; procedure Write(Message: String; Log_Level: Level_Type); -- The above is, what you have, so far. -- The stuff below is new: procedure Write(Message_1: String; Message_2: String; Log_Level: Level_Type); -- if Log_Level>0 then -- Write(Message_1 & Message_2, Log_Level); -- end if procedure Write(Message_1: String; Message_2: String; Message_3: String Log_Level: Level_Type); -- if Log_Level>0 then ... ... end Log; If you are willing to change the order of your parameters, one flexible Write-procedure would suffice: with Log; package Flexi_Log is procedure Write(Log_Level: Log.Level_Type; Message_1: String := ""; Message_2: String := ""; Message_3: String := ""; ... Message_9: String := ""); -- if Log_Level>0 then -- Log.Write(Message_1 & Message_2 & ... , Log_Level); -- end if; end Flexi_Log; In any case, the number of different strings to make one message is constant. The constant is under your control, but it is constant. If your support goes for up to, say, Message_9, a message for the log which consists of 10 or more parts may still trouble you. So change the constant sufficiently large that it doesn't trouble you too often ... I hope that helps! Stefan -- ------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------ Stefan dot Lucks at uni minus weimar dot de ------ I love the taste of Cryptanalysis in the morning! ------