2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-02-24 19:21:32 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "base/ILogOutputter.h"
|
2025-03-19 22:11:47 +00:00
|
|
|
#include "common/Common.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "mt/Thread.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
//! Stop traversing log chain outputter
|
|
|
|
|
/*!
|
|
|
|
|
This outputter performs no output and returns false from \c write(),
|
|
|
|
|
causing the logger to stop traversing the outputter chain. Insert
|
|
|
|
|
this to prevent already inserted outputters from writing.
|
|
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class StopLogOutputter : public ILogOutputter
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2025-05-01 02:04:58 +00:00
|
|
|
StopLogOutputter() = default;
|
|
|
|
|
~StopLogOutputter() override = default;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// ILogOutputter overrides
|
2025-04-28 01:27:48 +00:00
|
|
|
void open(const char *title) override;
|
|
|
|
|
void close() override;
|
|
|
|
|
void show(bool showIfEmpty) override;
|
2025-07-07 21:44:21 +00:00
|
|
|
bool write(LogLevel level, const char *message) override;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! Write log to console
|
|
|
|
|
/*!
|
|
|
|
|
This outputter writes output to the console. The level for each
|
|
|
|
|
message is ignored.
|
|
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class ConsoleLogOutputter : public ILogOutputter
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2025-05-01 02:04:58 +00:00
|
|
|
ConsoleLogOutputter() = default;
|
|
|
|
|
~ConsoleLogOutputter() override = default;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// ILogOutputter overrides
|
2025-04-28 01:27:48 +00:00
|
|
|
void open(const char *title) override;
|
|
|
|
|
void close() override;
|
|
|
|
|
void show(bool showIfEmpty) override;
|
2025-07-07 21:44:21 +00:00
|
|
|
bool write(LogLevel level, const char *message) override;
|
2025-05-20 02:19:19 +00:00
|
|
|
void flush() const;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! Write log to file
|
|
|
|
|
/*!
|
|
|
|
|
This outputter writes output to the file. The level for each
|
|
|
|
|
message is ignored.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
class FileLogOutputter : public ILogOutputter
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2025-05-01 02:04:58 +00:00
|
|
|
explicit FileLogOutputter(const char *logFile);
|
|
|
|
|
~FileLogOutputter() override = default;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// ILogOutputter overrides
|
2025-04-28 01:27:48 +00:00
|
|
|
void open(const char *title) override;
|
|
|
|
|
void close() override;
|
|
|
|
|
void show(bool showIfEmpty) override;
|
2025-07-07 21:44:21 +00:00
|
|
|
bool write(LogLevel level, const char *message) override;
|
2014-10-27 14:11:43 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void setLogFilename(const char *title);
|
2014-10-27 14:11:43 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
std::string m_fileName;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! Write log to system log
|
|
|
|
|
/*!
|
|
|
|
|
This outputter writes output to the system log.
|
|
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class SystemLogOutputter : public ILogOutputter
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2025-05-01 02:04:58 +00:00
|
|
|
SystemLogOutputter() = default;
|
|
|
|
|
~SystemLogOutputter() override = default;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// ILogOutputter overrides
|
2025-04-28 01:27:48 +00:00
|
|
|
void open(const char *title) override;
|
|
|
|
|
void close() override;
|
|
|
|
|
void show(bool showIfEmpty) override;
|
2025-07-07 21:44:21 +00:00
|
|
|
bool write(LogLevel level, const char *message) override;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! Write log to system log only
|
|
|
|
|
/*!
|
2014-11-11 13:51:47 +00:00
|
|
|
Creating an object of this type inserts a StopLogOutputter followed
|
|
|
|
|
by a SystemLogOutputter into Log. The destructor removes those
|
2012-06-10 16:50:54 +00:00
|
|
|
outputters. Add one of these to any scope that needs to write to
|
|
|
|
|
the system log (only) and restore the old outputters when exiting
|
|
|
|
|
the scope.
|
|
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class SystemLogger
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2024-07-02 19:07:06 +00:00
|
|
|
SystemLogger(const char *title, bool blockConsole);
|
|
|
|
|
SystemLogger(SystemLogger const &) = delete;
|
|
|
|
|
SystemLogger(SystemLogger &&) = delete;
|
|
|
|
|
~SystemLogger();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
SystemLogger &operator=(SystemLogger const &) = delete;
|
|
|
|
|
SystemLogger &operator=(SystemLogger &&) = delete;
|
2020-11-03 10:52:56 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
private:
|
2025-05-22 22:22:20 +00:00
|
|
|
ILogOutputter *m_syslog = nullptr;
|
|
|
|
|
ILogOutputter *m_stop = nullptr;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|