Mercurial > public > ostc_companion
view Utils/LogConsole.cpp @ 4:e30f00f760d3 default tip
Cleanup OSTC label and removed url
The computer type will now show OSTC 4/5 instead of only 4. The url has
been removed because it is no longer maintained. The ui header have been
deleted because they are generated files shich should not be under
version controll. Delete locally if you want to force an update of the
dialog layout.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 30 Nov 2025 18:37:32 +0100 |
| parents | 0b3630a29ad8 |
| children |
line wrap: on
line source
////////////////////////////////////////////////////////////////////////////// /// \file LogConsole.cpp /// \brief Put Log message onto standard console. /// \author JD Gascuel. /// \copyright (c) 2011-2016 JD Gascuel. All rights reserved. /// $Id$ ////////////////////////////////////////////////////////////////////////////// // // BSD 2-Clause License: // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF // THE POSSIBILITY OF SUCH DAMAGE. // ////////////////////////////////////////////////////////////////////////////// #include "LogConsole.h" #include "Log.h" //#include <QRegExp> #include <QRegularExpression> #include <stdio.h> #ifdef Q_OS_WIN32 # include <windows.h> # include <io.h> # include <fcntl.h> # include <iostream> #endif ////////////////////////////////////////////////////////////////////////////// // Nothing to do ... LogConsole::LogConsole(int argc, char *argv[]) : LogAppender(argc, argv) { setMinLevel(defaultMinLevel()); for(int i=1; i<argc; ++i) { if( strcmp("-dd", argv[i]) == 0 ) setMinLevel(Log::LEVEL_DEBUG); else if( strcmp("-d", argv[i]) == 0 ) setMinLevel(Log::LEVEL_TRACE); } } LogConsole::~LogConsole() {} ////////////////////////////////////////////////////////////////////////////// const char *LogConsole::type() const { return "Console"; } Log::Level LogConsole::defaultMinLevel() const { #ifdef DEBUG return Log::LEVEL_TRACE; #else return Log::LEVEL_INFO; #endif } const char *LogConsole::defaultFormat() const { return "%t %m"; } void LogConsole::operator()(const Log& log) { QString msg = format(log); // 2016-04-19 jDG: // Remove bad tags from console output... but keep it nice: #if 0 msg.replace("<br>", "\n") .replace(QRegExp("</?table[^>]*>"), "--------------------------------") .replace(QRegExp("</tr>(?!\n)"), "\n") .replace("</td>", "\t"); QRegExp re("</?[a-zA-Z]+[^>]*/?>"); while( msg.contains(re) ) msg.replace(re, ""); #endif msg.replace("<br>", "\n") .replace(QRegularExpression("</?table[^>]*>", QRegularExpression::CaseInsensitiveOption), "--------------------------------") .replace(QRegularExpression("</tr>(?!\n)"), "\n") .replace("</td>", "\t"); // allgemeiner Tag-Entferner QRegularExpression re("</?[a-zA-Z]+[^>]*/?>"); while (re.match(msg).hasMatch()) { msg.replace(re, ""); } // 2014-03-21 jDG: // // In UNIX print everything in UTF-8, so that: // * junitWrapper get it. // * it is compatible with Linux console. // // In Windows, the console DOES NOT accept UTF_8, we just got giberrish... // So defaults to Windows UNICODE which is Qt3's ucs2() or Qt4 toWCharArray() // // Note: it is correct for most Europe chars, but in corean (TCT example), // the line is truncated. #ifdef WIN32 wchar_t buffer[LOG_MAX_MESSAGE_LENGTH]; int len = msg.left(LOG_MAX_MESSAGE_LENGTH-2).toWCharArray(buffer); buffer[len] = 0; fprintf(stderr, "%S\n", buffer); #else QByteArray utf8 = msg.toUtf8(); fprintf(stderr, "%s\n", utf8.constData()); #endif fflush(stderr); }
