@@ -318,37 +318,33 @@ DDNetworkBackend::fetchKey(std::vector<uint8_t> &result,
318318 return libcdoc::OK;
319319}
320320
321- DDCDocLogger::~DDCDocLogger ()
322- {
323- if (ofs.is_open ()) {
324- ofs.close ();
325- }
326- }
327-
328- static constexpr std::string_view
321+ static constexpr QLatin1String
329322level2Str (libcdoc::LogLevel level) noexcept
330323{
331324 switch (level) {
332325 using enum libcdoc::LogLevel;
333- case LEVEL_FATAL: return " FATAL" ;
334- case LEVEL_ERROR: return " ERROR" ;
335- case LEVEL_WARNING: return " WARNING" ;
336- case LEVEL_INFO: return " INFO" ;
337- case LEVEL_DEBUG: return " DEBUG" ;
338- case LEVEL_TRACE: return " TRACE" ;
339- default : return " UNKNWON" ;
326+ case LEVEL_FATAL: return QLatin1String ( " FATAL" ) ;
327+ case LEVEL_ERROR: return QLatin1String ( " ERROR" ) ;
328+ case LEVEL_WARNING: return QLatin1String ( " WARNING" ) ;
329+ case LEVEL_INFO: return QLatin1String ( " INFO" ) ;
330+ case LEVEL_DEBUG: return QLatin1String ( " DEBUG" ) ;
331+ case LEVEL_TRACE: return QLatin1String ( " TRACE" ) ;
332+ default : return QLatin1String ( " UNKNWON" ) ;
340333 }
341334}
342335
343336void DDCDocLogger::logMessage (libcdoc::LogLevel level, std::string_view file, int line, std::string_view message) {
344- if (!ofs.is_open ()) {
337+ if (!ofs.isOpen ()) {
345338 return ;
346339 }
347- auto time = QDateTime::currentDateTime ().toString (QStringLiteral (" [yyyy-MM-dd hh:mm:ss] " ));
340+ auto time = QDateTime::currentDateTime ().toString (QStringLiteral (" [yyyy-MM-dd hh:mm:ss]" ));
348341 if (auto pos = file.find_last_of (" \\ /" ); pos != std::string_view::npos)
349342 file = file.substr (pos);
350343
351- ofs << time.toStdString () << level2Str (level) << ' ' << file << ' :' << line << ' ' << message << std::endl;
344+ ofs.write (QStringLiteral (" %1 %2 %3:%4 %5\n " )
345+ .arg (time, level2Str (level), file)
346+ .arg (line)
347+ .arg (message).toUtf8 ());
352348}
353349
354350DDCDocLogger *
@@ -358,12 +354,13 @@ DDCDocLogger::getLogger()
358354 return &logger;
359355}
360356
361- void DDCDocLogger::setUpLogger (const std::string& path)
357+ void DDCDocLogger::setUpLogger (const QString & path)
362358{
363359 DDCDocLogger *logger = getLogger ();
364360 logger->setMinLogLevel (libcdoc::LEVEL_WARNING);
365- logger->ofs .open (path, std::ios_base::app);
366- libcdoc::setLogger (logger);
361+ logger->ofs .setFileName (path);
362+ if (logger->ofs .open (QFile::WriteOnly|QFile::Append))
363+ libcdoc::setLogger (logger);
367364}
368365
369366void DDCDocLogger::setLogLevel (libcdoc::LogLevel level)
0 commit comments