1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPackLog.h,v $
6 Date: $Date: 2006-03-10 18:06:26 $
7 Version: $Revision: 1.4 $
9 Copyright (c) 2002 Kitware, Inc. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
23 #define cmCPack_Log(ctSelf, logType, msg) \
25 cmOStringStream cmCPackLog_msg; \
26 cmCPackLog_msg << msg; \
27 (ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str());\
33 #define cerr no_cerr_use_cmCPack_Log
38 #define cout no_cout_use_cmCPack_Log
42 * \brief A container for CPack generators
45 class cmCPackLog
: public cmObject
48 cmTypeMacro(cmCPackLog
, cmObject
);
62 //! Various signatures for logging.
63 void Log(const char* file
, int line
, const char* msg
)
65 this->Log(LOG_OUTPUT
, file
, line
, msg
);
67 void Log(const char* file
, int line
, const char* msg
, size_t length
)
69 this->Log(LOG_OUTPUT
, file
, line
, msg
, length
);
71 void Log(int tag
, const char* file
, int line
, const char* msg
)
73 this->Log(tag
, file
, line
, msg
, strlen(msg
));
75 void Log(int tag
, const char* file
, int line
, const char* msg
,
79 void VerboseOn() { this->SetVerbose(true); }
80 void VerboseOff() { this->SetVerbose(true); }
81 void SetVerbose(bool verb
) { this->Verbose
= verb
; }
82 bool GetVerbose() { return this->Verbose
; }
85 void DebugOn() { this->SetDebug(true); }
86 void DebugOff() { this->SetDebug(true); }
87 void SetDebug(bool verb
) { this->Debug
= verb
; }
88 bool GetDebug() { return this->Debug
; }
91 void QuietOn() { this->SetQuiet(true); }
92 void QuietOff() { this->SetQuiet(true); }
93 void SetQuiet(bool verb
) { this->Quiet
= verb
; }
94 bool GetQuiet() { return this->Quiet
; }
96 //! Set the output stream
97 void SetOutputStream(std::ostream
* os
) { this->DefaultOutput
= os
; }
99 //! Set the error stream
100 void SetErrorStream(std::ostream
* os
) { this->DefaultError
= os
; }
102 //! Set the log output stream
103 void SetLogOutputStream(std::ostream
* os
);
105 //! Set the log output file. The cmCPackLog will try to create file. If it
106 // cannot, it will report an error.
107 bool SetLogOutputFile(const char* fname
);
109 //! Set the various prefixes for the logging. SetPrefix sets the generic
110 // prefix that overwrittes missing ones.
111 void SetPrefix(std::string pfx
) { this->Prefix
= pfx
; }
112 void SetOutputPrefix(std::string pfx
) { this->OutputPrefix
= pfx
; }
113 void SetVerbosePrefix(std::string pfx
) { this->VerbosePrefix
= pfx
; }
114 void SetDebugPrefix(std::string pfx
) { this->DebugPrefix
= pfx
; }
115 void SetWarningPrefix(std::string pfx
) { this->WarningPrefix
= pfx
; }
116 void SetErrorPrefix(std::string pfx
) { this->ErrorPrefix
= pfx
; }
128 std::string OutputPrefix
;
129 std::string VerbosePrefix
;
130 std::string DebugPrefix
;
131 std::string WarningPrefix
;
132 std::string ErrorPrefix
;
134 std::ostream
*DefaultOutput
;
135 std::ostream
*DefaultError
;
137 std::string LogOutputFileName
;
138 std::ostream
*LogOutput
;
139 // Do we need to cleanup log output stream
140 bool LogOutputCleanup
;
143 class cmCPackLogWrite
146 cmCPackLogWrite(const char* data
, size_t length
)
147 : Data(data
), Length(length
) {}
153 inline std::ostream
& operator<< (std::ostream
& os
, const cmCPackLogWrite
& c
)
155 os
.write(c
.Data
, c
.Length
);