Replaced Json parser with a custom one (optims+compact output)

This commit is contained in:
emeric
2023-10-20 15:22:00 +02:00
parent 4562e0368a
commit d86260ba2d
13 changed files with 316 additions and 181 deletions
+7 -6
View File
@@ -17,18 +17,19 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <thread>
#include "utils/StreamLogger.hpp"
StreamLogger::StreamLogger(std::ostream& os, EnumSet<Severity> severities)
: _os {os}
, _severities {severities}
: _os{ os }
, _severities{ severities }
{
}
void
StreamLogger::processLog(const Log& log)
void StreamLogger::processLog(const Log& log)
{
if (_severities.contains(log.getSeverity()))
_os << "[" << getSeverityName(log.getSeverity()) << "] [" << getModuleName(log.getModule()) << "] " << log.getMessage() << std::endl;
if (_severities.contains(log.getSeverity()))
_os << std::this_thread::get_id() << " [" << getSeverityName(log.getSeverity()) << "] [" << getModuleName(log.getModule()) << "] " << log.getMessage() << std::endl;
}
+23 -1
View File
@@ -219,7 +219,7 @@ namespace StringUtils
return res;
}
std::string jsEscape(const std::string& str)
std::string jsEscape(std::string_view str)
{
static const std::unordered_map<char, std::string_view> escapeMap
{
@@ -249,6 +249,28 @@ namespace StringUtils
return escaped;
}
void writeJSEscapedString(std::ostream& os, std::string_view str)
{
static constexpr std::pair<char, std::string_view> charsToEscape[]
{
{'\\', "\\\\" },
{ '\n', "\\n" },
{ '\r', "\\r" },
{ '\t', "\\t" },
{ '"', "\\\"" },
{ '\'', "\\\'" },
};
for (const char c : str)
{
auto itEntry{ std::find_if(std::cbegin(charsToEscape), std::cend(charsToEscape), [=](const auto& entry) { return entry.first == c;}) };
if (itEntry != std::cend(charsToEscape))
os << itEntry->second;
else
os << c;
}
}
std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar)
{
std::string res;
+14 -3
View File
@@ -19,14 +19,25 @@
#include "utils/WtLogger.hpp"
#include <thread>
#include <sstream>
#include <Wt/WApplication.h>
#include <Wt/WLogger.h>
#include "utils/Logger.hpp"
void
WtLogger::processLog(const Log& log)
namespace
{
Wt::log(getSeverityName(log.getSeverity())) << Wt::WLogger::sep << "[" << getModuleName(log.getModule()) << "]" << Wt::WLogger::sep << log.getMessage();
std::string to_string(std::thread::id id)
{
std::ostringstream oss;
oss << id;
return oss.str();
}
}
void WtLogger::processLog(const Log& log)
{
Wt::log(getSeverityName(log.getSeverity())) << Wt::WLogger::sep << to_string(std::this_thread::get_id()) << Wt::WLogger::sep << "[" << getModuleName(log.getModule()) << "]" << Wt::WLogger::sep << log.getMessage();
}