void printhelp(const char *argv0);
-static const char shortopts[] = "hvDc:d:";
+static const char shortopts[] = "hvDc:d:l:";
static const struct option longopts[] = {
{ "help", no_argument, NULL, 'h' }, ///< Print the help text
{ "daemonise", no_argument, NULL, 'D' }, ///< Daemonise
{ "config", required_argument, NULL, 'c' },
{ "debug", required_argument, NULL, 'd' },
+ { "log", required_argument, NULL, 'l' },
{ NULL, 0, NULL, 0 } ///< End
};
int optc;
int th = 0;
string config="/etc/ambd/config";
+ ofstream logfile;
+ string logfn;
while ((optc = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
{
th = atoi(optarg);
DebugOut::setDebugThreshhold(th);
break;
+ case 'l':
+ logfn = optarg;
+ break;
default:
cerr<<"Unknown option "<<optc<<endl;
printhelp(argv[0]);
if(isdeamonize)
daemonize();
+ if(!logfn.empty())
+ {
+ logfile.open(logfn, ios::out | ios::trunc);
+ DebugOut::setOutput(logfile);
+ }
+
#ifdef USE_QT_CORE
#endif
+ if(logfile.is_open())
+ logfile.close();
+
return 0;
}
DebugOut const& operator << (string message) const
{
+ ostream out(buf);
+
if(mDebugLevel <= debugThreshhold)
out<<message<<" ";
return *this;
DebugOut const& operator << (ostream & (*manip)(std::ostream&)) const
{
+ ostream out(buf);
+
if(mDebugLevel <= debugThreshhold)
out<<endl;
return *this;
DebugOut const & operator << (uint16_t val) const
{
+ ostream out(buf);
+
if(mDebugLevel <= debugThreshhold)
out<<val<<" ";
return *this;
debugThreshhold = th;
}
+ static void setOutput(ostream &o)
+ {
+ buf = o.rdbuf();
+ }
+
private:
static int debugThreshhold;
- static ostream &out;
+ static std::streambuf *buf;
int mDebugLevel;
};