2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2006-01-03 00:14:21 +03:00
|
|
|
|
|
|
|
#include "cmCPackLog.h"
|
|
|
|
|
|
|
|
#include "cmGeneratedFileStream.h"
|
2009-01-22 21:56:13 +03:00
|
|
|
#include "cmSystemTools.h"
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2016-09-07 01:21:35 +03:00
|
|
|
#include <iostream>
|
|
|
|
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLog::cmCPackLog()
|
|
|
|
{
|
2006-03-10 21:06:26 +03:00
|
|
|
this->Verbose = false;
|
|
|
|
this->Debug = false;
|
|
|
|
this->Quiet = false;
|
|
|
|
this->NewLine = true;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
this->LastTag = cmCPackLog::NOTAG;
|
2006-01-03 00:14:21 +03:00
|
|
|
#undef cerr
|
|
|
|
#undef cout
|
2006-03-10 21:06:26 +03:00
|
|
|
this->DefaultOutput = &std::cout;
|
|
|
|
this->DefaultError = &std::cerr;
|
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LogOutput = CM_NULLPTR;
|
2006-03-10 21:06:26 +03:00
|
|
|
this->LogOutputCleanup = false;
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackLog::~cmCPackLog()
|
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
this->SetLogOutputStream(CM_NULLPTR);
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
|
|
|
|
2006-01-03 01:22:39 +03:00
|
|
|
void cmCPackLog::SetLogOutputStream(std::ostream* os)
|
2006-01-03 00:14:21 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LogOutputCleanup && this->LogOutput) {
|
2006-03-10 21:06:26 +03:00
|
|
|
delete this->LogOutput;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
this->LogOutputCleanup = false;
|
|
|
|
this->LogOutput = os;
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackLog::SetLogOutputFile(const char* fname)
|
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
cmGeneratedFileStream* cg = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fname) {
|
2006-01-03 00:14:21 +03:00
|
|
|
cg = new cmGeneratedFileStream(fname);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (cg && !*cg) {
|
2006-01-03 00:14:21 +03:00
|
|
|
delete cg;
|
2016-06-27 23:44:16 +03:00
|
|
|
cg = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-01-03 00:14:21 +03:00
|
|
|
this->SetLogOutputStream(cg);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cg) {
|
2006-01-03 00:14:21 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
this->LogOutputCleanup = true;
|
2006-01-03 00:14:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCPackLog::Log(int tag, const char* file, int line, const char* msg,
|
|
|
|
size_t length)
|
2006-01-03 00:14:21 +03:00
|
|
|
{
|
|
|
|
// By default no logging
|
|
|
|
bool display = false;
|
|
|
|
|
|
|
|
// Display file and line number if debug
|
2006-03-10 21:06:26 +03:00
|
|
|
bool useFileAndLine = this->Debug;
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool output = false;
|
|
|
|
bool debug = false;
|
2006-01-03 00:14:21 +03:00
|
|
|
bool warning = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
bool error = false;
|
2006-01-03 00:14:21 +03:00
|
|
|
bool verbose = false;
|
|
|
|
|
|
|
|
// When writing in file, add list of tags whenever tag changes.
|
|
|
|
std::string tagString;
|
|
|
|
bool needTagString = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LogOutput && this->LastTag != tag) {
|
2006-01-03 00:14:21 +03:00
|
|
|
needTagString = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-01-03 00:14:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tag & LOG_OUTPUT) {
|
2006-01-03 00:14:21 +03:00
|
|
|
output = true;
|
|
|
|
display = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (needTagString) {
|
|
|
|
if (!tagString.empty()) {
|
|
|
|
tagString += ",";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
tagString = "VERBOSE";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (tag & LOG_WARNING) {
|
2006-01-03 00:14:21 +03:00
|
|
|
warning = true;
|
|
|
|
display = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (needTagString) {
|
|
|
|
if (!tagString.empty()) {
|
|
|
|
tagString += ",";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
tagString = "WARNING";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (tag & LOG_ERROR) {
|
2006-01-03 00:14:21 +03:00
|
|
|
error = true;
|
|
|
|
display = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (needTagString) {
|
|
|
|
if (!tagString.empty()) {
|
|
|
|
tagString += ",";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
tagString = "ERROR";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (tag & LOG_DEBUG && this->Debug) {
|
2006-01-03 00:14:21 +03:00
|
|
|
debug = true;
|
|
|
|
display = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (needTagString) {
|
|
|
|
if (!tagString.empty()) {
|
|
|
|
tagString += ",";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
tagString = "DEBUG";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
useFileAndLine = true;
|
|
|
|
}
|
|
|
|
if (tag & LOG_VERBOSE && this->Verbose) {
|
2006-01-03 00:14:21 +03:00
|
|
|
verbose = true;
|
|
|
|
display = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (needTagString) {
|
|
|
|
if (!tagString.empty()) {
|
|
|
|
tagString += ",";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
tagString = "VERBOSE";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->Quiet) {
|
2006-01-03 00:14:21 +03:00
|
|
|
display = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->LogOutput) {
|
|
|
|
if (needTagString) {
|
|
|
|
*this->LogOutput << "[" << file << ":" << line << " " << tagString
|
|
|
|
<< "] ";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
this->LogOutput->write(msg, length);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
this->LastTag = tag;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!display) {
|
2006-01-03 00:14:21 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->NewLine) {
|
|
|
|
if (error && !this->ErrorPrefix.empty()) {
|
2014-03-11 16:35:32 +04:00
|
|
|
*this->DefaultError << this->ErrorPrefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (warning && !this->WarningPrefix.empty()) {
|
2014-03-11 16:35:32 +04:00
|
|
|
*this->DefaultError << this->WarningPrefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (output && !this->OutputPrefix.empty()) {
|
2014-03-11 16:35:32 +04:00
|
|
|
*this->DefaultOutput << this->OutputPrefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (verbose && !this->VerbosePrefix.empty()) {
|
2014-03-11 16:35:32 +04:00
|
|
|
*this->DefaultOutput << this->VerbosePrefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (debug && !this->DebugPrefix.empty()) {
|
2014-03-11 16:35:32 +04:00
|
|
|
*this->DefaultOutput << this->DebugPrefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->Prefix.empty()) {
|
2014-03-11 16:35:32 +04:00
|
|
|
*this->DefaultOutput << this->Prefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (useFileAndLine) {
|
|
|
|
if (error || warning) {
|
2006-03-10 21:06:26 +03:00
|
|
|
*this->DefaultError << file << ":" << line << " ";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-03-10 21:06:26 +03:00
|
|
|
*this->DefaultOutput << file << ":" << line << " ";
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (error || warning) {
|
2006-03-10 21:06:26 +03:00
|
|
|
this->DefaultError->write(msg, length);
|
|
|
|
this->DefaultError->flush();
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-03-10 21:06:26 +03:00
|
|
|
this->DefaultOutput->write(msg, length);
|
|
|
|
this->DefaultOutput->flush();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (msg[length - 1] == '\n' || length > 2) {
|
2006-03-10 21:06:26 +03:00
|
|
|
this->NewLine = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-22 21:56:13 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (error) {
|
2009-01-22 21:56:13 +03:00
|
|
|
cmSystemTools::SetErrorOccured();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-01-03 00:14:21 +03:00
|
|
|
}
|