Initialize logging based on passed in parameters

This commit is contained in:
Eryn Wells 2014-08-02 00:40:38 -07:00
parent f8ec140f8e
commit 86a4594e7f

View file

@ -28,7 +28,8 @@ int verbosity = 0;
static void static void
usage(const char *progname) usage(const char *progname)
{ {
fprintf(stderr, "Usage: %s [-hv] [-o <outfile>] <infile ...>\n", progname); fprintf(stderr, "Usage: %s [-hv] [-l <logfile>] [-L <log level>] [-o <outfile>] <infile ...>\n",
progname);
} }
@ -37,12 +38,9 @@ main(int argc,
const char *argv[]) const char *argv[])
{ {
using namespace charles::log; using namespace charles::log;
using charles::log::Log;
Scene scene; Scene scene;
Log::Init("charles.log", 50);
scene.get_ambient().set_intensity(1.0); scene.get_ambient().set_intensity(1.0);
#if 0 #if 0
@ -75,23 +73,40 @@ main(int argc,
PointLight *l1 = new PointLight(Vector3(6.0, -4.0, 2), Color::White, 1.0); PointLight *l1 = new PointLight(Vector3(6.0, -4.0, 2), Color::White, 1.0);
scene.add_light(l1); scene.add_light(l1);
std::string logFilename;
unsigned int logLevel = 0;
std::string outfile, infile; std::string outfile, infile;
int opt; int opt;
while ((opt = getopt(argc, (char *const *)argv, "ho:v")) != -1) { while ((opt = getopt(argc, (char *const *)argv, "hl:L:o:v:")) != -1) {
switch (opt) { switch (opt) {
case 'h': case 'h':
usage(argv[0]); usage(argv[0]);
exit(0);
break;
case 'l':
logFilename = optarg;
break;
case 'L':
logLevel = std::stoul(optarg);
break; break;
case 'o': case 'o':
outfile = optarg; outfile = optarg;
break; break;
case 'v': case 'v':
++verbosity;
break; break;
} }
} }
/* Set up logging */
if (logLevel > 0) {
if (logFilename.empty()) {
logFilename = "charles.log";
}
Log::Init(logFilename, logLevel);
}
if (optind >= argc) { if (optind >= argc) {
LOG_ERROR << "Input file required."; LOG_ERROR << "Input file required.";
fprintf(stderr, "Input file required.\n"); fprintf(stderr, "Input file required.\n");
@ -119,7 +134,9 @@ main(int argc,
PNGWriter writer; PNGWriter writer;
scene.write(writer, outfile); scene.write(writer, outfile);
Log::Close(); if (logLevel > 0) {
Log::Close();
}
return 0; return 0;
} }