34 #include <boost/shared_ptr.hpp>
45 using boost::shared_ptr;
98 : _threshold(threshold), _defShowAll(new bool(false)), _myShowAll(),
99 _name(name), _thresholds(new threshold::Memory(Log::_sep)),
102 _thresholds->setRootThreshold(threshold);
103 if (name.length() > 0) _thresholds->setThresholdFor(name, threshold);
104 _myShowAll = _defShowAll;
128 Log::Log(
const list<shared_ptr<LogDestination> > &destinations,
130 const string &name,
const int threshold,
bool defaultShowAll)
131 : _threshold(threshold), _defShowAll(new bool(defaultShowAll)),
132 _myShowAll(),
_name(name), _thresholds(new threshold::Memory(Log::_sep)),
133 _destinations(destinations), _preamble(preamble.deepCopy())
135 _thresholds->setRootThreshold(threshold);
136 if (name.length() > 0) _thresholds->setThresholdFor(name, threshold);
143 Log::Log(
const Log& that)
144 : _threshold(that._threshold), _defShowAll(that._defShowAll),
145 _myShowAll(that._myShowAll),
_name(that.
_name),
146 _thresholds(that._thresholds), _destinations(that._destinations),
147 _preamble(that._preamble->deepCopy())
158 Log& Log::operator=(
const Log& that) {
159 _threshold = that._threshold;
160 _defShowAll = that._defShowAll;
161 _myShowAll = that._myShowAll;
163 _thresholds = that._thresholds;
164 _destinations = that._destinations;
165 _preamble = that._preamble->deepCopy();
169 void Log::completePreamble() {
170 _preamble->set<
string>(
"LOG",
_name);
185 Log::Log(
const Log& parent,
const string& childName,
int threshold)
186 : _threshold(threshold), _defShowAll(parent._defShowAll),
187 _myShowAll(),
_name(parent.getName()), _thresholds(parent._thresholds),
188 _destinations(parent._destinations),
189 _preamble(parent._preamble->deepCopy())
194 if (_threshold > INHERIT_THRESHOLD)
195 _thresholds->setThresholdFor(
_name, _threshold);
210 void Log::setThresholdFor(
const string& name,
int threshold) {
211 string fullname(getName());
212 if (fullname.length() > 0) fullname += _sep;
214 _thresholds->setThresholdFor(fullname, threshold);
217 int Log::getThresholdFor(
const string& name)
const {
218 string fullname(getName());
219 if (
_name.length() > 0) fullname += _sep;
220 return _thresholds->getThresholdFor(fullname+name);
251 Log *Log::createChildLog(
const string& childName,
int threshold)
const {
252 return new Log(*
this, childName, threshold);
261 void Log::log(
int importance,
const string& message,
264 int threshold = getThreshold();
265 if (importance < threshold)
267 LogRecord rec(threshold, importance, *_preamble, willShowAll());
268 rec.addComment(message);
269 rec.addProperties(properties);
278 void Log::log(
int importance,
const string& message) {
279 int threshold = getThreshold();
280 if (importance < threshold)
282 LogRecord rec(threshold, importance, *_preamble, willShowAll());
283 rec.addComment(message);
295 void Log::format(
int importance,
const char *fmt, ...) {
296 int threshold = getThreshold();
297 if (importance < threshold)
return;
300 _format(importance, fmt, ap);
304 void Log::_format(
int importance,
const char* fmt, va_list ap) {
308 const int len = vsnprintf(NULL, 0, fmt, ap) + 1;
312 (void)vsnprintf(msg, len, fmt, aq);
314 log(importance, msg);
321 void Log::_send(
int threshold,
int importance,
const char *fmt, va_list ap) {
322 const int len = strlen(fmt) + 100;
324 vsnprintf(message, len, fmt, ap);
326 LogRecord rec(threshold, importance, *_preamble, willShowAll());
327 rec.addComment(message);
335 void Log::send(
const LogRecord& record) {
336 if (record.getImportance() < getThreshold())
338 list<shared_ptr<LogDestination> >::iterator i;
339 for(i = _destinations.begin(); i != _destinations.end(); i++) {
354 void Log::addDestination(ostream& destination,
int threshold) {
355 shared_ptr<LogFormatter> frmtr(
new IndentedFormatter());
356 addDestination(destination, threshold, frmtr);
372 void Log::addDestination(ostream& destination,
int threshold,
373 const shared_ptr<LogFormatter> &formatter)
375 shared_ptr<LogDestination> dest(
376 new LogDestination(&destination, formatter, threshold));
377 addDestination(dest);
380 Log& Log::getDefaultLog() {
381 if (defaultLog == 0) {
382 Log::setDefaultLog(
new ScreenLog());
388 void Log::setDefaultLog(Log *deflog) {
389 if (defaultLog != 0)
delete defaultLog;
391 if (defaultLog != 0) {
392 defaultLog->markPersistent();
396 void Log::createDefaultLog(
const list<shared_ptr<LogDestination> >& dests,
398 const string& name,
const int threshold)
400 Log::setDefaultLog(
new Log(dests, preamble, name, threshold));
403 void Log::closeDefaultLog() { setDefaultLog(0); }
405 Log *Log::defaultLog = 0;
406 const string Log::_sep(
".");
409 if (! _sent) *
this << endr;
table::Key< std::string > name
std::string const & _name
std::ostream & operator<<(std::ostream &os, CameraPoint const &cameraPoint)
lsst::daf::base::PropertySet PropertySet
static const int INHERIT_THRESHOLD
definition of the ScreenLog class
Class for storing generic metadata.
Log(const int threshold=INFO, const std::string &name="")
static void log(std::string const &loggername, log4cxx::LevelPtr level, std::string const &filename, std::string const &funcname, unsigned int lineno, char const *fmt,...)