Resync.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CPack / cmCPackLog.h
blobda82e0a0037e243225352ed39ee94b136ab6f217
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPackLog.h,v $
5 Language: C++
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 =========================================================================*/
18 #ifndef cmCPackLog_h
19 #define cmCPackLog_h
21 #include "cmObject.h"
23 #define cmCPack_Log(ctSelf, logType, msg) \
24 do { \
25 cmOStringStream cmCPackLog_msg; \
26 cmCPackLog_msg << msg; \
27 (ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str());\
28 } while ( 0 )
30 #ifdef cerr
31 # undef cerr
32 #endif
33 #define cerr no_cerr_use_cmCPack_Log
35 #ifdef cout
36 # undef cout
37 #endif
38 #define cout no_cout_use_cmCPack_Log
41 /** \class cmCPackLog
42 * \brief A container for CPack generators
45 class cmCPackLog : public cmObject
47 public:
48 cmTypeMacro(cmCPackLog, cmObject);
50 cmCPackLog();
51 ~cmCPackLog();
53 enum __log_tags {
54 NOTAG = 0,
55 LOG_OUTPUT = 0x1,
56 LOG_VERBOSE = 0x2,
57 LOG_DEBUG = 0x4,
58 LOG_WARNING = 0x8,
59 LOG_ERROR = 0x10
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,
76 size_t length);
78 //! Set Verbose
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; }
84 //! Set Debug
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; }
90 //! Set Quiet
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; }
118 private:
119 bool Verbose;
120 bool Debug;
121 bool Quiet;
123 bool NewLine;
125 int LastTag;
127 std::string Prefix;
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
145 public:
146 cmCPackLogWrite(const char* data, size_t length)
147 : Data(data), Length(length) {}
149 const char* Data;
150 size_t Length;
153 inline std::ostream& operator<< (std::ostream& os, const cmCPackLogWrite& c)
155 os.write(c.Data, c.Length);
156 os.flush();
157 return os;
160 #endif