Commit 13eb244b authored by Martin Marinov's avatar Martin Marinov

Expose Debug::File settings to control the console and logfile in Debug::Config.

parent 9c2af037
......@@ -4,6 +4,7 @@
#include "DebConfig.hh"
#include "DebDefault.hh"
#include "DebFile.hh"
#include "Base/Utils/Environment.hh"
#include <fstream>
......@@ -140,12 +141,17 @@ int Config::Impl::level(const char* const _flnm, const char* const _fnct) const
}
//////////////////////////////////////////////////////////////////////////
const Config& Config::query()
Config& Config::modify()
{
static Config glbl_cnfg;
return glbl_cnfg;
}
const Config& Config::query()
{
return modify();
}
Config::Config() : impl_(new Impl) {}
Config::~Config() { delete impl_; }
......@@ -155,6 +161,12 @@ int Config::level(const char* const _flnm, const char* const _fnct) const
return impl_->level(_flnm, _fnct);
}
void Config::set_console(const bool _on) { File::modify().set_console(_on); }
bool Config::console() const { return File::query().console(); }
void Config::set_logfile(bool _on) { File::modify().set_logfile(_on); }
bool Config::logfile() const { return File::query().logfile(); }
}//namespace Debug
#endif//DEB_ON
......@@ -11,13 +11,27 @@ namespace Debug {
/*!
Access the global, per-process, configuration options of the Debug system.
\todo Make this a per-thread configuration.
*/
class Config
{
public:
static const Config& query();
static Config& modify();
public:
//! Turn on/off the console. This could be extended to redirect it.
void set_console(const bool _on = true);
//! Get if the console is turned on/off.
bool console() const;
//! Turn on/off the logfile. This could be extended to provide a FILE*.
void set_logfile(const bool _on);
//! Get if the logfile is turned on/off.
bool logfile() const;
//! Get the level for this filename and function
int level(const char* const _flnm, const char* const _fnct) const;
......
......@@ -4,6 +4,7 @@
#include "DebFile.hh"
#include "DebCallStack.hh"
#include "DebDefault.hh"
#include "Base/Utils/Environment.hh"
#include <string>
......@@ -38,16 +39,7 @@ bool is_html_filename(const char* const str)
class File::Impl
{
public:
enum Flags
{
APPEND = 0x01,
HTML = 0x02,
RETAIN = 0x04,
KEEP_OPEN = 0x08
};
public:
Impl(const char* const _flnm, const uint _flags = APPEND | RETAIN)
Impl(const char* const _flnm, const uint _flags)
: flags_(_flags), num_flush_(0), line_strt_(false)
{
set_filename(_flnm);
......@@ -115,7 +107,7 @@ public:
print(' ', false); // indents never go onto the console!
}
bffr_.append(&_c, 1);
if (_cnsl && enbl_cnsl_)
if (_cnsl && console())
std::cerr << _c; // print on the console
if (_c == '\n')
{
......@@ -173,14 +165,6 @@ public:
double_format_ = str;
}
void set_console_output(const bool _enbl) { enbl_cnsl_ = _enbl; }
bool console_output() const { return enbl_cnsl_; }
void set_file_log(const bool _enbl) { enbl_file_log_ = _enbl; }
bool file_log() const { return enbl_file_log_; }
void print(double _d)
{
char buffer[64];
......@@ -312,10 +296,7 @@ public:
bool flush()
{
if (!enbl_file_log_)
return true;
if (bffr_.empty())
if (bffr_.empty() || !logfile())
return true;
const char* const flnm = filename();
......@@ -392,13 +373,17 @@ public:
flush();
}
void set_console(const bool _on = true) { set_flag<CONSOLE>(_on); }
bool console() const { return flag<CONSOLE>(); }
void set_logfile(bool _on) { set_flag<LOGFILE>(_on); }
bool logfile() const { return flag<LOGFILE>(); }
private:
uint flags_;
int num_flush_;
int priority_; // Last permission granted
bool line_strt_; // are we at the start of th line?
bool enbl_cnsl_ = true; // prints on cerr
bool enbl_file_log_ = true; // creates a debug log file
std::string bffr_;
std::string output_;
......@@ -406,6 +391,18 @@ private:
std::fstream file_stream_;
std::string double_format_;
private:
template <Flags _flag>
void set_flag(const bool _on)
{
flags_ = _on ? flags_ | _flag : flags_ & ~_flag;
}
template <Flags _flag>
bool flag() const { return (flags_ & _flag) == _flag; }
};
//////////////////////////////////////////////////////////////////////////
......@@ -417,6 +414,8 @@ File& File::modify()
return glbl_file;
}
const File& File::query() { return modify(); }
File::File(const char* const _flnm, const uint _flags)
: impl_(new Impl(_flnm, _flags))
{}
......@@ -441,25 +440,11 @@ void File::set_double_format(const char* const str)
impl_->set_double_format(str);
}
bool File::console_output()
{
return impl_->console_output();
}
void File::set_console(const bool _on) { impl_->set_console(_on); }
bool File::console() const { return impl_->console(); }
void File::set_console_output(const bool _enbl)
{
impl_->set_console_output(_enbl);
}
bool File::file_log()
{
return impl_->file_log();
}
void File::set_file_log(const bool _enbl)
{
return impl_->set_file_log(_enbl);
}
void File::set_logfile(bool _on) { impl_->set_logfile(_on); }
bool File::logfile() const { return impl_->logfile(); }
}//namespace Debug
......
......@@ -16,6 +16,7 @@ Debug file.
class File
{
public:
static const File& query();
static File& modify();
public:
......@@ -24,11 +25,14 @@ public:
APPEND = 0x01,
HTML = 0x02,
RETAIN = 0x04,
KEEP_OPEN = 0x08
KEEP_OPEN = 0x08,
CONSOLE = 0x10,
LOGFILE = 0x20,
DEFAULT = APPEND | RETAIN | CONSOLE | LOGFILE
};
public:
File(const char* const _flnm, const uint _flags = APPEND | RETAIN);
File(const char* const _flnm, const uint _flags = DEFAULT);
~File();
void enter(const int _id);
......@@ -43,11 +47,17 @@ public:
const char* double_format() const;
void set_double_format(const char* const str);
bool console_output();
void set_console_output(const bool _enbl);
//! Turn on/off the console. This could be extended to redirect it.
void set_console(const bool _on = true);
bool file_log();
void set_file_log(const bool _enbl);
//! Get if the console is turned on/off.
bool console() const;
//! Turn on/off the logfile. This could be extended to provide a FILE*.
void set_logfile(const bool _on);
//! Get if the logfile is turned on/off.
bool logfile() const;
private:
class Impl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment