File indexing completed on 2024-05-05 09:51:12
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Sebastian Kügler <sebas@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kscreen_export.h" 0010 0011 #include <QLoggingCategory> 0012 #include <QObject> 0013 0014 namespace KScreen 0015 { 0016 void log(const QString &msg); 0017 0018 /** KScreen-internal file logging. 0019 * 0020 * The purpose of this class is to allow better debugging of kscreen. QDebug falls short here, since 0021 * we need to debug the concert of kscreen components from different processes. 0022 * 0023 * KScreen::Log manages access to kscreen's log file. 0024 * 0025 * The following environment variables are considered: 0026 * - disable logging by setting 0027 * KSCREEN_LOGGING=false 0028 * - set the log file to a custom path, the default is in ~/.local/share/kscreen/kscreen.log 0029 * 0030 * Please do not translate messages written to the logs, it's developer information and should be 0031 * english, independent from the user's locale preferences. 0032 * 0033 * @code 0034 * 0035 * Log::instance()->setContext("resume"); 0036 * Log::log("Applying detected output configuration."); 0037 * 0038 * @endcode 0039 * 0040 * @since 5.8 0041 */ 0042 class KSCREEN_EXPORT Log 0043 { 0044 public: 0045 virtual ~Log(); 0046 0047 static Log *instance(); 0048 0049 /** Log a message to a file 0050 * 0051 * Call this static method to add a new line to the log. 0052 * 0053 * @arg msg The log message to write. 0054 */ 0055 static void log(const QString &msg, const QString &category = QString()); 0056 0057 /** Context for the logs. 0058 * 0059 * The context can be used to indicate what is going on overall, it is used to be able 0060 * to group log entries into subsequential operations. For example the context can be 0061 * "handling resume", which is then added to the log messages. 0062 * 0063 * @arg msg The log message to write to the file. 0064 * 0065 * @see ontext() 0066 */ 0067 QString context() const; 0068 0069 /** Set the context for the logs. 0070 * 0071 * @see context() 0072 */ 0073 void setContext(const QString &context); 0074 0075 /** Logging to file is enabled by environmental var, is it? 0076 * 0077 * @arg msg The log message to write to the file. 0078 * @return Whether logging is enabled. 0079 */ 0080 bool enabled() const; 0081 0082 /** Path to the log file 0083 * 0084 * This is usually ~/.local/share/kscreen/kscreen.log, but can be changed by setting 0085 * KSCREEN_LOGFILE in the environment. 0086 * 0087 * @return The path to the log file. 0088 */ 0089 QString logFile() const; 0090 0091 private: 0092 explicit Log(); 0093 class Private; 0094 Private *const d; 0095 0096 static Log *sInstance; 0097 explicit Log(Private *dd); 0098 }; 0099 0100 } // KSCreen namespace