mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-16 10:08:36 +03:00
0031206: Foundation Classes, Message_PrinterSystemLog - log messages to Browser console within Emscripten
Message_PrinterOStream::SetConsoleTextColor() skips color tags in case of Emscripten. Message_PrinterSystemLog now implements log via emscripten_log().
This commit is contained in:
parent
c64efd9e30
commit
b380b06c5d
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <Message.hxx>
|
#include <Message.hxx>
|
||||||
#include <Message_Messenger.hxx>
|
#include <Message_Messenger.hxx>
|
||||||
|
#include <Message_PrinterSystemLog.hxx>
|
||||||
#include <OSD_MemInfo.hxx>
|
#include <OSD_MemInfo.hxx>
|
||||||
#include <OSD_Parallel.hxx>
|
#include <OSD_Parallel.hxx>
|
||||||
|
|
||||||
@ -56,6 +57,8 @@ static void onFileReadFailed (void* theOpaque)
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Message::DefaultMessenger()->Printers().First()->SetTraceLevel (Message_Trace);
|
Message::DefaultMessenger()->Printers().First()->SetTraceLevel (Message_Trace);
|
||||||
|
Handle(Message_PrinterSystemLog) aJSConsolePrinter = new Message_PrinterSystemLog ("webgl-sample", Message_Trace);
|
||||||
|
Message::DefaultMessenger()->AddPrinter (aJSConsolePrinter); // open JavaScript console within the Browser to see this output
|
||||||
Message::DefaultMessenger()->Send (TCollection_AsciiString("NbLogicalProcessors: ") + OSD_Parallel::NbLogicalProcessors(), Message_Trace);
|
Message::DefaultMessenger()->Send (TCollection_AsciiString("NbLogicalProcessors: ") + OSD_Parallel::NbLogicalProcessors(), Message_Trace);
|
||||||
aViewer.run();
|
aViewer.run();
|
||||||
Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
|
Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
|
||||||
|
@ -243,6 +243,12 @@ void Message_PrinterOStream::SetConsoleTextColor (Standard_OStream* theOStream,
|
|||||||
}
|
}
|
||||||
SetConsoleTextAttribute (anStdOut, aFlags);
|
SetConsoleTextAttribute (anStdOut, aFlags);
|
||||||
}
|
}
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
// Terminal capabilities are undefined on this platform.
|
||||||
|
// std::cout could be redirected to HTML page, into terminal or somewhere else.
|
||||||
|
(void )theOStream;
|
||||||
|
(void )theTextColor;
|
||||||
|
(void )theIsIntenseText;
|
||||||
#else
|
#else
|
||||||
if (theOStream == NULL)
|
if (theOStream == NULL)
|
||||||
{
|
{
|
||||||
|
@ -54,6 +54,35 @@
|
|||||||
}
|
}
|
||||||
return ANDROID_LOG_DEBUG;
|
return ANDROID_LOG_DEBUG;
|
||||||
}
|
}
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
#include <emscripten/emscripten.h>
|
||||||
|
|
||||||
|
// actual version of Emscripten does not define these yet
|
||||||
|
#ifndef EM_LOG_INFO
|
||||||
|
#define EM_LOG_INFO 0
|
||||||
|
#endif
|
||||||
|
#ifndef EM_LOG_DEBUG
|
||||||
|
#define EM_LOG_DEBUG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//! Convert message gravity into emscripten_log() flags.
|
||||||
|
static int getEmscriptenPriority (const Message_Gravity theGravity)
|
||||||
|
{
|
||||||
|
switch (theGravity)
|
||||||
|
{
|
||||||
|
case Message_Trace: return EM_LOG_CONSOLE | EM_LOG_DEBUG;
|
||||||
|
case Message_Info: return EM_LOG_CONSOLE | EM_LOG_INFO;
|
||||||
|
case Message_Warning: return EM_LOG_CONSOLE | EM_LOG_WARN;
|
||||||
|
case Message_Alarm: return EM_LOG_CONSOLE | EM_LOG_ERROR;
|
||||||
|
case Message_Fail: return EM_LOG_CONSOLE | EM_LOG_ERROR;
|
||||||
|
}
|
||||||
|
return EM_LOG_CONSOLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Print message to console.debug().
|
||||||
|
EM_JS(void, debugMsgToConsole, (const char* theStr), {
|
||||||
|
console.debug(UTF8ToString(theStr));
|
||||||
|
});
|
||||||
#else
|
#else
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
@ -90,6 +119,8 @@ Message_PrinterSystemLog::Message_PrinterSystemLog (const TCollection_AsciiStrin
|
|||||||
myEventSource = (Standard_Address )RegisterEventSourceW (NULL, aWideSrcName.ToWideString());
|
myEventSource = (Standard_Address )RegisterEventSourceW (NULL, aWideSrcName.ToWideString());
|
||||||
#elif defined(__ANDROID__)
|
#elif defined(__ANDROID__)
|
||||||
//
|
//
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
//
|
||||||
#else
|
#else
|
||||||
openlog (myEventSourceName.ToCString(), LOG_PID | LOG_NDELAY, LOG_USER);
|
openlog (myEventSourceName.ToCString(), LOG_PID | LOG_NDELAY, LOG_USER);
|
||||||
#endif
|
#endif
|
||||||
@ -110,6 +141,8 @@ Message_PrinterSystemLog::~Message_PrinterSystemLog()
|
|||||||
}
|
}
|
||||||
#elif defined(__ANDROID__)
|
#elif defined(__ANDROID__)
|
||||||
//
|
//
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
//
|
||||||
#else
|
#else
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
@ -132,6 +165,15 @@ void Message_PrinterSystemLog::Send (const Standard_CString theString,
|
|||||||
Send (TCollection_ExtendedString (theString), theGravity, true);
|
Send (TCollection_ExtendedString (theString), theGravity, true);
|
||||||
#elif defined(__ANDROID__)
|
#elif defined(__ANDROID__)
|
||||||
__android_log_write (getAndroidLogPriority (theGravity), myEventSourceName.ToCString(), theString);
|
__android_log_write (getAndroidLogPriority (theGravity), myEventSourceName.ToCString(), theString);
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
if (theGravity == Message_Trace)
|
||||||
|
{
|
||||||
|
debugMsgToConsole (theString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emscripten_log (getEmscriptenPriority (theGravity), "%s", theString);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
syslog (getSysLogPriority (theGravity), "%s", theString);
|
syslog (getSysLogPriority (theGravity), "%s", theString);
|
||||||
#endif
|
#endif
|
||||||
@ -154,6 +196,15 @@ void Message_PrinterSystemLog::Send (const TCollection_AsciiString& theString,
|
|||||||
Send (TCollection_ExtendedString (theString), theGravity, true);
|
Send (TCollection_ExtendedString (theString), theGravity, true);
|
||||||
#elif defined(__ANDROID__)
|
#elif defined(__ANDROID__)
|
||||||
__android_log_write (getAndroidLogPriority (theGravity), myEventSourceName.ToCString(), theString.ToCString());
|
__android_log_write (getAndroidLogPriority (theGravity), myEventSourceName.ToCString(), theString.ToCString());
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
if (theGravity == Message_Trace)
|
||||||
|
{
|
||||||
|
debugMsgToConsole (theString.ToCString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emscripten_log (getEmscriptenPriority (theGravity), "%s", theString.ToCString());
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
syslog (getSysLogPriority (theGravity), "%s", theString.ToCString());
|
syslog (getSysLogPriority (theGravity), "%s", theString.ToCString());
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user