Merge topic 'vs-framework-references'
[kiteware-cmake.git] / Source / CPack / cmCPackLog.h
blob347b0f72dc6b05f57403c54cb3fa89029a13809b
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <cstring>
8 #include <memory>
9 #include <ostream>
10 #include <string>
12 #define cmCPack_Log(ctSelf, logType, msg) \
13 do { \
14 std::ostringstream cmCPackLog_msg; \
15 cmCPackLog_msg << msg; \
16 (ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str()); \
17 } while (false)
19 /** \class cmCPackLog
20 * \brief A container for CPack generators
23 class cmCPackLog
25 public:
26 cmCPackLog();
27 ~cmCPackLog();
29 cmCPackLog(const cmCPackLog&) = delete;
30 cmCPackLog& operator=(const cmCPackLog&) = delete;
32 enum cm_log_tags
34 NOTAG = 0,
35 LOG_OUTPUT = 0x1,
36 LOG_VERBOSE = 0x2,
37 LOG_DEBUG = 0x4,
38 LOG_WARNING = 0x8,
39 LOG_ERROR = 0x10
42 //! Various signatures for logging.
43 void Log(const char* file, int line, const char* msg)
45 this->Log(LOG_OUTPUT, file, line, msg);
47 void Log(const char* file, int line, const char* msg, size_t length)
49 this->Log(LOG_OUTPUT, file, line, msg, length);
51 void Log(int tag, const char* file, int line, const char* msg)
53 this->Log(tag, file, line, msg, strlen(msg));
55 void Log(int tag, const char* file, int line, const char* msg,
56 size_t length);
58 //! Set Verbose
59 void VerboseOn() { this->SetVerbose(true); }
60 void VerboseOff() { this->SetVerbose(true); }
61 void SetVerbose(bool verb) { this->Verbose = verb; }
62 bool GetVerbose() { return this->Verbose; }
64 //! Set Debug
65 void DebugOn() { this->SetDebug(true); }
66 void DebugOff() { this->SetDebug(true); }
67 void SetDebug(bool verb) { this->Debug = verb; }
68 bool GetDebug() { return this->Debug; }
70 //! Set Quiet
71 void QuietOn() { this->SetQuiet(true); }
72 void QuietOff() { this->SetQuiet(true); }
73 void SetQuiet(bool verb) { this->Quiet = verb; }
74 bool GetQuiet() { return this->Quiet; }
76 //! Set the output stream
77 void SetOutputStream(std::ostream* os) { this->DefaultOutput = os; }
79 //! Set the error stream
80 void SetErrorStream(std::ostream* os) { this->DefaultError = os; }
82 //! Set the log output stream
83 void SetLogOutputStream(std::ostream* os);
85 //! Set the log output file. The cmCPackLog will try to create file. If it
86 // cannot, it will report an error.
87 bool SetLogOutputFile(const char* fname);
89 //! Set the various prefixes for the logging. SetPrefix sets the generic
90 // prefix that overwrites missing ones.
91 void SetPrefix(std::string const& pfx) { this->Prefix = pfx; }
92 void SetOutputPrefix(std::string const& pfx) { this->OutputPrefix = pfx; }
93 void SetVerbosePrefix(std::string const& pfx) { this->VerbosePrefix = pfx; }
94 void SetDebugPrefix(std::string const& pfx) { this->DebugPrefix = pfx; }
95 void SetWarningPrefix(std::string const& pfx) { this->WarningPrefix = pfx; }
96 void SetErrorPrefix(std::string const& pfx) { this->ErrorPrefix = pfx; }
98 private:
99 bool Verbose = false;
100 bool Debug = false;
101 bool Quiet = false;
103 bool NewLine = true;
105 int LastTag = cmCPackLog::NOTAG;
107 std::string Prefix;
108 std::string OutputPrefix;
109 std::string VerbosePrefix;
110 std::string DebugPrefix;
111 std::string WarningPrefix;
112 std::string ErrorPrefix;
114 std::ostream* DefaultOutput = nullptr;
115 std::ostream* DefaultError = nullptr;
117 std::ostream* LogOutput = nullptr;
118 std::unique_ptr<std::ostream> LogOutputStream;
121 class cmCPackLogWrite
123 public:
124 cmCPackLogWrite(const char* data, size_t length)
125 : Data(data)
126 , Length(length)
130 const char* Data;
131 std::streamsize Length;
134 inline std::ostream& operator<<(std::ostream& os, const cmCPackLogWrite& c)
136 os.write(c.Data, c.Length);
137 os.flush();
138 return os;