| Attached Files | logfile.diff [^] (5,132 bytes) 2012-02-06 19:43 [Show Content] [Hide Content]diff -r 688ec9097c55 console/luxconsole.cpp
--- a/console/luxconsole.cpp Sun Feb 05 15:53:35 2012 +0100
+++ b/console/luxconsole.cpp Mon Feb 06 20:41:07 2012 -0700
@@ -131,6 +131,7 @@
("serverinterval,i", po::value < int >(), "Specify the number of seconds between requests to rendering servers.")
("serverport,p", po::value < int >(), "Specify the tcp port used in server mode.")
("serverwriteflm,W", "Write film to disk before transmitting in server mode.")
+ ("logfile,l", po::value< std::string >(), "Specify the log file to use")
;
// Hidden options, will be allowed both on command line and
@@ -170,10 +171,20 @@
return 0;
}
+ if (vm.count("version")) {
+ LOG(LUX_INFO,LUX_NOERROR) << "Lux version " << luxVersion() << " of " << __DATE__ << " at " << __TIME__;
+ return 0;
+ }
+
+ if (vm.count("logfile")) {
+ if(luxSetErrorLogfile (vm["logfile"].as<std::string>().c_str()))
+ {
+ LOG(LUX_SEVERE,LUX_SYSTEM) << "Unable to open logfile '" << vm["logfile"].as<std::string>() << "' for writing";
+ return 1;
+ }
+ }
+
LOG(LUX_INFO,LUX_NOERROR) << "Lux version " << luxVersion() << " of " << __DATE__ << " at " << __TIME__;
-
- if (vm.count("version"))
- return 0;
if (vm.count("threads"))
threads = vm["threads"].as<int>();
diff -r 688ec9097c55 core/api.cpp
--- a/core/api.cpp Sun Feb 05 15:53:35 2012 +0100
+++ b/core/api.cpp Mon Feb 06 20:41:07 2012 -0700
@@ -36,8 +36,7 @@
#include <string>
using std::string;
#include <iostream>
-using std::cerr;
-using std::endl;
+#include <fstream>
#include <cstdarg>
#include <cstdio>
using std::FILE;
@@ -1114,12 +1113,37 @@
// API and allows to perform filtering on the errors by using the
// 'LOG' macro defined in error.h
LuxErrorHandler luxError = luxErrorPrint;
+std::ostream *luxErrorStream = &std::cerr;
extern "C" void luxErrorHandler(LuxErrorHandler handler)
{
luxError = handler;
}
+// Send luxErrorPrint output to a file
+// If no filename is passed (""), sets output to std::cerr
+// Returns 0 on success, 1 on failure
+extern "C" bool luxSetErrorLogfile(const char *filename)
+{
+ if (luxErrorStream != &std::cerr)
+ delete luxErrorStream;
+
+ if (string(filename).empty())
+ luxErrorStream = &std::cerr;
+ else
+ {
+ std::ofstream *file = new std::ofstream (filename, std::ios_base::out | std::ios_base::app);
+ if (!file->fail())
+ luxErrorStream = file;
+ else
+ {
+ delete file;
+ return true;
+ }
+ }
+ return false;
+}
+
extern "C" void luxErrorAbort(int code, int severity, const char *message)
{
luxErrorPrint(code, severity, message);
@@ -1139,24 +1163,24 @@
boost::mutex::scoped_lock lock(stdout_mutex);
luxLastError = code;
- cerr<<"[";
+ *luxErrorStream<<"[";
#if !defined(WIN32) || defined(__CYGWIN__) //windows does not support ANSI escape codes (but CYGWIN does) ...
//set the color
switch (severity) {
case LUX_DEBUG:
- cerr<<"\033[0;34m"; // BLUE
+ *luxErrorStream<<"\033[0;34m"; // BLUE
break;
case LUX_INFO:
- cerr<<"\033[0;32m"; // GREEN
+ *luxErrorStream<<"\033[0;32m"; // GREEN
break;
case LUX_WARNING:
- cerr<<"\033[0;33m"; // YELLOW
+ *luxErrorStream<<"\033[0;33m"; // YELLOW
break;
case LUX_ERROR:
- cerr<<"\033[0;31m"; // RED
+ *luxErrorStream<<"\033[0;31m"; // RED
break;
case LUX_SEVERE:
- cerr<<"\033[0;31m"; // RED
+ *luxErrorStream<<"\033[0;31m"; // RED
break;
}
#else // ... but it does have it's own console API
@@ -1178,32 +1202,32 @@
break;
}
#endif
- cerr<<"Lux ";
- cerr<<boost::posix_time::second_clock::local_time()<<' ';
+ *luxErrorStream<<"Lux ";
+ *luxErrorStream<<boost::posix_time::second_clock::local_time()<<' ';
switch (severity) {
case LUX_DEBUG:
- cerr<<"DEBUG";
+ *luxErrorStream<<"DEBUG";
break;
case LUX_INFO:
- cerr<<"INFO";
+ *luxErrorStream<<"INFO";
break;
case LUX_WARNING:
- cerr<<"WARNING";
+ *luxErrorStream<<"WARNING";
break;
case LUX_ERROR:
- cerr<<"ERROR";
+ *luxErrorStream<<"ERROR";
break;
case LUX_SEVERE:
- cerr<<"SEVERE ERROR";
+ *luxErrorStream<<"SEVERE ERROR";
break;
}
- cerr<<" : "<<code;
+ *luxErrorStream<<" : "<<code;
#if !defined(WIN32) || defined(__CYGWIN__) // windows does not support ANSI escape codes (but CYGWIN does) ...
- cerr<<"\033[0m";
+ *luxErrorStream<<"\033[0m";
#else // ... but it does have it's own console API
w32util::ChangeConsoleColor( FOREGROUND_WHITE );
#endif
- cerr<<"] "<<message<<endl<<std::flush;
+ *luxErrorStream<<"] "<<message<<std::endl<<std::flush;
}
extern "C" void luxSetEpsilon(const float minValue, const float maxValue)
diff -r 688ec9097c55 core/api.h
--- a/core/api.h Sun Feb 05 15:53:35 2012 +0100
+++ b/core/api.h Mon Feb 06 20:41:07 2012 -0700
@@ -314,6 +314,7 @@
LUX_EXPORT extern void luxErrorAbort(int code, int severity, const char *message);
LUX_EXPORT extern void luxErrorIgnore(int code, int severity, const char *message);
LUX_EXPORT extern void luxErrorPrint(int code, int severity, const char *message);
+LUX_EXPORT extern bool luxSetErrorLogfile(const char *filename);
LUX_EXPORT extern LuxErrorHandler luxError;
/**
|