Skip to content

Commit ebf2d96

Browse files
committed
Fix file encoding handlin on windows
Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 4d089ed commit ebf2d96

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

client/Application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ Application::Application( int &argc, char **argv )
452452
d->helpAction = d->bar->helpMenu()->addAction(tr("DigiDoc4 Client Help"), this, &Application::openHelp);
453453
#endif
454454

455-
DDCDocLogger::setUpLogger(QStringLiteral("%1/libcdoc.log").arg(QDir::tempPath()).toStdString());
455+
DDCDocLogger::setUpLogger(QStringLiteral("%1/libcdoc.log").arg(QDir::tempPath()));
456456
try
457457
{
458458
digidoc::Conf::init( new DigidocConf );

client/CDocSupport.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
329322
level2Str(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

343336
void 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

354350
DDCDocLogger *
@@ -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

369366
void DDCDocLogger::setLogLevel(libcdoc::LogLevel level)

client/CDocSupport.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ struct DDNetworkBackend final : public libcdoc::NetworkBackend, private QObject
123123

124124
class DDCDocLogger final : private libcdoc::Logger {
125125
public:
126-
static void setUpLogger(const std::string& path);
126+
static void setUpLogger(const QString &path);
127127
static void setLogLevel(libcdoc::LogLevel level);
128128

129129
private:
130130
DDCDocLogger() = default;
131-
~DDCDocLogger();
132131
static DDCDocLogger *getLogger();
133132
void logMessage(libcdoc::LogLevel level, std::string_view file, int line, std::string_view message) final;
134-
std::ofstream ofs;
133+
QFile ofs;
135134
};
136135

137136
class CDocSupport {

0 commit comments

Comments
 (0)