Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Add capability to Log into Windows console
Add capability to Log into Windows console [message #10981] |
Thu, 09 August 2007 11:11  |
benoitc
Messages: 17 Registered: July 2007 Location: Nice (France)
|
Promising Member |
|
|
Hi,
Windows has a hidden "console" that allow to output debug information in real time using the Win32 API "OutputDebugString".
The messages can then be viewed using DebugView tool from Sysinternals (see picture attached) (" http://www.microsoft.com/technet/sysinternals/utilities/debu gview.mspx" )
The code to activate that is quite simple (99% are from the LogStream code) and can be easily extended to Linux with a printf instead of OutputDebugString.
class ConsoleStream : public Stream {
CriticalSection cs;
byte buffer[512];
byte *p;
void Flush();
void Put0(int w);
protected:
virtual void _Put(int w);
virtual void _Put(const void *data, dword size);
public:
virtual bool IsOpen() const {return true;};
ConsoleStream() {p = buffer;}
~ConsoleStream(){}
};
void ConsoleStream::Flush()
{
int count = (int)(p - buffer);
if(count == 0) return;
*p=0;
::OutputDebugString((LPCSTR)buffer);
p = buffer;
}
void ConsoleStream::Put0(int w)
{
*p++ = w;
if(w == '\n' || p == buffer + 511)
Flush();
}
void ConsoleStream::_Put(int w)
{
CriticalSection::Lock __(cs);
Put0(w);
}
void ConsoleStream::_Put(const void *data, dword size)
{
CriticalSection::Lock __(cs);
const byte *q = (byte *)data;
while(size--)
Put0(*q++);
}
Stream& GetConsoleStream()
{
static ConsoleStream s;
return s;
}
GUI_APP_MAIN
{
SetVppLog(GetConsoleStream());
LOG(123);
}
It will be useful (at least for me) to have that in Upp.
Regards,
Benoit
[Updated on: Thu, 09 August 2007 11:15] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Apr 28 01:09:53 CEST 2025
Total time taken to generate the page: 0.01039 seconds
|