2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2006-01-03 00:14:21 +03:00
|
|
|
#ifndef cmCPackLog_h
|
|
|
|
#define cmCPackLog_h
|
|
|
|
|
2016-09-07 01:21:35 +03:00
|
|
|
#include <cmConfigure.h>
|
|
|
|
|
2006-01-03 00:14:21 +03:00
|
|
|
#include "cmObject.h"
|
2016-09-07 01:21:35 +03:00
|
|
|
#include "cmTypeMacro.h"
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string>
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define cmCPack_Log(ctSelf, logType, msg) \
|
|
|
|
do { \
|
|
|
|
std::ostringstream cmCPackLog_msg; \
|
|
|
|
cmCPackLog_msg << msg; \
|
|
|
|
(ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str()); \
|
|
|
|
} while (0)
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
#ifdef cerr
|
2016-05-16 17:34:04 +03:00
|
|
|
#undef cerr
|
2006-01-03 00:14:21 +03:00
|
|
|
#endif
|
|
|
|
#define cerr no_cerr_use_cmCPack_Log
|
|
|
|
|
|
|
|
#ifdef cout
|
2016-05-16 17:34:04 +03:00
|
|
|
#undef cout
|
2006-01-03 00:14:21 +03:00
|
|
|
#endif
|
|
|
|
#define cout no_cout_use_cmCPack_Log
|
|
|
|
|
|
|
|
/** \class cmCPackLog
|
|
|
|
* \brief A container for CPack generators
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class cmCPackLog : public cmObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmTypeMacro(cmCPackLog, cmObject);
|
|
|
|
|
|
|
|
cmCPackLog();
|
2016-06-27 22:25:27 +03:00
|
|
|
~cmCPackLog() CM_OVERRIDE;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
enum __log_tags
|
|
|
|
{
|
2006-01-03 00:14:21 +03:00
|
|
|
NOTAG = 0,
|
|
|
|
LOG_OUTPUT = 0x1,
|
|
|
|
LOG_VERBOSE = 0x2,
|
|
|
|
LOG_DEBUG = 0x4,
|
|
|
|
LOG_WARNING = 0x8,
|
|
|
|
LOG_ERROR = 0x10
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Various signatures for logging.
|
2006-03-09 00:33:39 +03:00
|
|
|
void Log(const char* file, int line, const char* msg)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
this->Log(LOG_OUTPUT, file, line, msg);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-09 00:33:39 +03:00
|
|
|
void Log(const char* file, int line, const char* msg, size_t length)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
this->Log(LOG_OUTPUT, file, line, msg, length);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-09 00:33:39 +03:00
|
|
|
void Log(int tag, const char* file, int line, const char* msg)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
this->Log(tag, file, line, msg, strlen(msg));
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-09 00:33:39 +03:00
|
|
|
void Log(int tag, const char* file, int line, const char* msg,
|
2016-05-16 17:34:04 +03:00
|
|
|
size_t length);
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
//! Set Verbose
|
|
|
|
void VerboseOn() { this->SetVerbose(true); }
|
|
|
|
void VerboseOff() { this->SetVerbose(true); }
|
2006-03-10 21:06:26 +03:00
|
|
|
void SetVerbose(bool verb) { this->Verbose = verb; }
|
|
|
|
bool GetVerbose() { return this->Verbose; }
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
//! Set Debug
|
|
|
|
void DebugOn() { this->SetDebug(true); }
|
|
|
|
void DebugOff() { this->SetDebug(true); }
|
2006-03-10 21:06:26 +03:00
|
|
|
void SetDebug(bool verb) { this->Debug = verb; }
|
|
|
|
bool GetDebug() { return this->Debug; }
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
//! Set Quiet
|
|
|
|
void QuietOn() { this->SetQuiet(true); }
|
|
|
|
void QuietOff() { this->SetQuiet(true); }
|
2006-03-10 21:06:26 +03:00
|
|
|
void SetQuiet(bool verb) { this->Quiet = verb; }
|
|
|
|
bool GetQuiet() { return this->Quiet; }
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
//! Set the output stream
|
2006-03-10 21:06:26 +03:00
|
|
|
void SetOutputStream(std::ostream* os) { this->DefaultOutput = os; }
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
//! Set the error stream
|
2006-03-10 21:06:26 +03:00
|
|
|
void SetErrorStream(std::ostream* os) { this->DefaultError = os; }
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
//! Set the log output stream
|
2006-01-03 01:22:39 +03:00
|
|
|
void SetLogOutputStream(std::ostream* os);
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
//! Set the log output file. The cmCPackLog will try to create file. If it
|
|
|
|
// cannot, it will report an error.
|
|
|
|
bool SetLogOutputFile(const char* fname);
|
|
|
|
|
|
|
|
//! Set the various prefixes for the logging. SetPrefix sets the generic
|
|
|
|
// prefix that overwrittes missing ones.
|
2006-03-10 21:06:26 +03:00
|
|
|
void SetPrefix(std::string pfx) { this->Prefix = pfx; }
|
|
|
|
void SetOutputPrefix(std::string pfx) { this->OutputPrefix = pfx; }
|
|
|
|
void SetVerbosePrefix(std::string pfx) { this->VerbosePrefix = pfx; }
|
|
|
|
void SetDebugPrefix(std::string pfx) { this->DebugPrefix = pfx; }
|
|
|
|
void SetWarningPrefix(std::string pfx) { this->WarningPrefix = pfx; }
|
|
|
|
void SetErrorPrefix(std::string pfx) { this->ErrorPrefix = pfx; }
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
private:
|
2006-03-10 21:06:26 +03:00
|
|
|
bool Verbose;
|
|
|
|
bool Debug;
|
|
|
|
bool Quiet;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
bool NewLine;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
int LastTag;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
std::string Prefix;
|
|
|
|
std::string OutputPrefix;
|
|
|
|
std::string VerbosePrefix;
|
|
|
|
std::string DebugPrefix;
|
|
|
|
std::string WarningPrefix;
|
|
|
|
std::string ErrorPrefix;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::ostream* DefaultOutput;
|
|
|
|
std::ostream* DefaultError;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
std::string LogOutputFileName;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::ostream* LogOutput;
|
2006-01-03 00:14:21 +03:00
|
|
|
// Do we need to cleanup log output stream
|
2006-03-10 21:06:26 +03:00
|
|
|
bool LogOutputCleanup;
|
2006-01-03 00:14:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class cmCPackLogWrite
|
|
|
|
{
|
|
|
|
public:
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogWrite(const char* data, size_t length)
|
2016-05-16 17:34:04 +03:00
|
|
|
: Data(data)
|
|
|
|
, Length(length)
|
|
|
|
{
|
|
|
|
}
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
const char* Data;
|
|
|
|
size_t Length;
|
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
inline std::ostream& operator<<(std::ostream& os, const cmCPackLogWrite& c)
|
2006-01-03 00:14:21 +03:00
|
|
|
{
|
|
|
|
os.write(c.Data, c.Length);
|
|
|
|
os.flush();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|