[Mono-list] Diagnostic Messages
Jonathan Pryor
jonpryor@vt.edu
26 May 2002 09:17:00 -0400
Apparently some clarification is in order.
On Windows, the `DefaultTraceListener' uses `OutputDebugString' to print
messages. This ensures that no messages will be displayed on the
console unless an additional `TraceListener' is added that sends output
to the console. This is a rather nice feature, in that I can leave
trace messages in the program without having them be seen by the user.
Linux/Unix, as far as I can tell, has no equivalent to
`OutputDebugString'. The console must be used instead (until someone
tells me a better way to do it).
So I have a problem: I want to leave trace code in the program, but I
don't want the user to see it by default.
A concrete example is in order. Suppose we have the following program:
#define TRACE
#define DEBUG
using System;
using System.Diagnostics;
public class test {
public static void Main ()
{
Trace.WriteLine ("Trace Message");
Debug.WriteLine ("Debug Message");
Console.WriteLine ("Console Message");
}
}
Notice that I have `#define' statements to enable both debug and trace
messages to remain in the code.
Now, when I run it with mono, I want to see:
$ mono test.exe
Console Message
Notice that I don't want any trace or debug messages to be shown.
If I want to see trace messages, I use the appropriate argument:
$ mono --diagnostics=trace
** Mono-Trace: Trace Message
Console Message
If I want to see debug messages:
$ mono --diagnostics=debug
** Mono-Debug: Debug Message
Console Message
If I want to see everything:
$ mono --diagnostics=all
** Mono-Trace: Trace Message
** Mono-Debug: Debug Message
Console Message
(Message prefixes are for example only, and may not be the ones actually
used.)
The point I'm attempting to demonstrate is that this isn't a compiler
issue, this is a runtime issue. Trace and debug messages need to be
sent somewhere in order to be seen (and thus useful), but we don't want
them to be seen all the time, as it isn't appropriate.
Hence why I would like to add a `--diagnostics' flag to mint/mono.
Thanks
- Jon
On Sun, 2002-05-26 at 03:03, Lawrence Pit wrote:
Hi Jonathan,
> My current idea for "more functional" is that we add a new argument to
> mono/mint:
>
> --diagnostics=[trace | debug | all]
The debug switch shouldn't be on mono/mint, but on mcs instead.
A tracing switch should be on both mono/mint and mcs.
By default mcs shouldn't emit code for calls to methods Assert, Fail,
Indent, Unindent and the various Write methods on both the Debug and Trace
classes. The Debug methods should only be emitted into IL code when you add
#define DEBUG to your sourcecode or provide the --define DEBUG switch to
mcs. Similarly, the Trace methods should only be emitted into IL code when
you add #define TRACE to your sourcecode or provide the --define TRACE
switch to mcs. When tracing methods are called from the IL code, by default
they'll show their output. Via the application configuration file you can
set the trace level or disable tracing completely.
Greets,
Lawrence