nidas v1.2.3
SampleTracer.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 Copyright 2016 UCAR, NCAR, All Rights Reserved
6 ********************************************************************
7*/
8#ifndef NIDAS_CORE_SAMPLETRACER_H
9#define NIDAS_CORE_SAMPLETRACER_H
10
11#include "SampleMatcher.h"
12
13namespace nidas { namespace core {
14
15
23{
24public:
25 SampleTracer(int level, const char* file, const char* function, int line);
26
27 inline bool
28 active(const Sample* samp)
29 {
30 return _context.active() && _matcher.match(samp);
31 }
32
33 inline bool
35 {
36 return _context.active() && _matcher.match(id);
37 }
38
39 inline static std::string
41 {
42 return nidas::util::UTime(tt).format(true, "%Y %m %d %H:%M:%S.%4f");
43 }
44
45 inline static std::string
46 format_time(dsm_time_t tt, const std::string& format)
47 {
48 return nidas::util::UTime(tt).format(true, format);
49 }
50
71 msg(const Sample* samp = 0, const std::string& text = "")
72 {
73 if (samp)
74 {
75 dsm_time_t tt = samp->getTimeTag();
76 dsm_sample_id_t sid = samp->getId();
77 _msg << text
78 << "[" << GET_DSM_ID(sid) << ',' << GET_SPS_ID(sid) << "]"
79 << "@" << format_time(tt);
80 }
81 return _msg;
82 }
83
85 msg(dsm_time_t tt, dsm_sample_id_t sid, const std::string& text = "")
86 {
87 _msg << text
88 << "[" << GET_DSM_ID(sid) << ',' << GET_SPS_ID(sid) << "]"
89 << "@" << format_time(tt);
90 return _msg;
91 }
92
93private:
97
98};
99
100}} // namespace nidas namespace core
101
102#endif // NIDAS_CORE_SAMPLETRACER_H
#define GET_SPS_ID(tid)
Definition Sample.h:85
#define GET_DSM_ID(tid)
Definition Sample.h:82
Match samples according to DSM and Sample ID ranges, and configure the ranges with criteria in text f...
Definition SampleMatcher.h:21
bool match(dsm_sample_id_t id)
Return true if the given id satisfies the current range criteria.
Definition SampleMatcher.cc:164
SampleTracer uses a Logger to log messages about samples as they are encountered in the code.
Definition SampleTracer.h:23
nidas::util::LogMessage & msg(dsm_time_t tt, dsm_sample_id_t sid, const std::string &text="")
Definition SampleTracer.h:85
bool active(const Sample *samp)
Definition SampleTracer.h:28
nidas::util::LogMessage _msg
Definition SampleTracer.h:95
nidas::util::LogMessage & msg(const Sample *samp=0, const std::string &text="")
Format a basic log message tracing the given the sample, using text as a prefix, then return a refere...
Definition SampleTracer.h:71
static std::string format_time(dsm_time_t tt, const std::string &format)
Definition SampleTracer.h:46
SampleTracer(int level, const char *file, const char *function, int line)
Definition SampleTracer.cc:14
static std::string format_time(dsm_time_t tt)
Definition SampleTracer.h:40
bool active(dsm_sample_id_t id)
Definition SampleTracer.h:34
nidas::core::SampleMatcher _matcher
Definition SampleTracer.h:96
nidas::util::LogContext _context
Definition SampleTracer.h:94
Interface to a data sample.
Definition Sample.h:190
bool active() const
Return true if log messages from this context have been enabled.
Definition Logger.h:371
The LogContext is created at a point in the application code and filled in with details about that lo...
Definition Logger.h:531
A class for formatting and streaming a log message.
Definition Logger.h:952
A class for parsing, formatting and doing operations on time, based on Unix time conventions,...
Definition UTime.h:95
std::string format(bool utc, const std::string &fmt) const
Format a UTime into a string.
Definition UTime.cc:462
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC.
Definition Sample.h:62
unsigned int dsm_sample_id_t
Definition Sample.h:64
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31