File indexing completed on 2024-06-23 05:14:17

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     utils/log.h
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <utils/pimpl_ptr.h>
0013 
0014 #include <memory>
0015 
0016 #include <cstdio>
0017 
0018 class QIODevice;
0019 class QString;
0020 
0021 namespace Kleo
0022 {
0023 
0024 class Log
0025 {
0026 public:
0027     enum OpenMode {
0028         Read = 0x1,
0029         Write = 0x2,
0030     };
0031 
0032     static void messageHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &msg);
0033 
0034     static std::shared_ptr<const Log> instance();
0035     static std::shared_ptr<Log> mutableInstance();
0036 
0037     ~Log();
0038 
0039     bool ioLoggingEnabled() const;
0040     void setIOLoggingEnabled(bool enabled);
0041 
0042     QString outputDirectory() const;
0043     void setOutputDirectory(const QString &path);
0044 
0045     std::shared_ptr<QIODevice> createIOLogger(const std::shared_ptr<QIODevice> &wrapped, const QString &prefix, OpenMode mode) const;
0046 
0047     FILE *logFile() const;
0048 
0049 private:
0050     Log();
0051 
0052 private:
0053     class Private;
0054     kdtools::pimpl_ptr<Private> d;
0055 
0056     Q_DISABLE_COPY(Log)
0057 };
0058 
0059 }