1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
12 #define cmCPack_Log(ctSelf, logType, msg) \
14 std::ostringstream cmCPackLog_msg; \
15 cmCPackLog_msg << msg; \
16 (ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str()); \
20 * \brief A container for CPack generators
29 cmCPackLog(const cmCPackLog
&) = delete;
30 cmCPackLog
& operator=(const cmCPackLog
&) = delete;
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
,
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
; }
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
; }
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
; }
105 int LastTag
= cmCPackLog::NOTAG
;
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
124 cmCPackLogWrite(const char* data
, size_t length
)
131 std::streamsize Length
;
134 inline std::ostream
& operator<<(std::ostream
& os
, const cmCPackLogWrite
& c
)
136 os
.write(c
.Data
, c
.Length
);