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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,400766bdbcd86f7c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Peter Amey Newsgroups: comp.lang.ada Subject: Re: This can't be done in Ada...or? Date: Mon, 14 Feb 2005 15:21:22 +0000 Message-ID: <37btvjF5b6imcU1@individual.net> References: <1108139611.709714.36170@o13g2000cwo.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net m2SrJ/eZR1MP+ZhHBPpI8wPsjkjw4/9FTVRkCRiVLI4+/1pHw= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en In-Reply-To: <1108139611.709714.36170@o13g2000cwo.googlegroups.com> Xref: g2news1.google.com comp.lang.ada:8312 Date: 2005-02-14T15:21:22+00:00 List-Id: Per Lindquist wrote: > Hi, this question has already sort of been discussed in topics about > multiple target platforms, conditional compilation, preprocessors and > build strategies. Before giving up I thought I'd give it a try one last > time... > > My impression from reading some threads is that Ada DOES NOT offer a > decent way to implement trace printouts (log messages), at least not > with the features stated below. > > The problem > ----------- > > We want to be able to output log messages, or traces as we call it, > from an Ada program. There will be a few trace categories like Error, > Warning, Note etc. The messages (strings) can be sent to a file or > stdout or whatever (not important). > > A call might look something like this: > > Trace.Error(Package_Name, Subprogram_Name, "Woops, V=" & > Some_Type'Image(V)); > > How do we write a tracing utility in Ada that: > 1. has different behaviour on different target platforms > 2. can disable some categories depending on target platform at > compile-time. > 3. does *not* cause any execution overhead if disabled. > 4. does not need yucky "if Trace_Wanted then ... end if;" around all > calls > 5. does not need preprocessing (some of you say it's never needed in > Ada...) > > I say it can't be done in Ada. Please prove me wrong! > One useful approach I have used is to make us of subunits. Each of the reporting routines in your package Trace can be made a subunit of Trace. The subunit itself, e.g. Error, can have two implementations, one that reports the error and one which is just a null body. The compiler "make" system and library manager can be used to build different variants with different levels of reporting. If the stub is marked as in_line then there is no overhead when the null version is called. Peter