[med-svn] [aghermann] 03/60: use log-facility (part 2/2)
andrei zavada
hmmr-guest at alioth.debian.org
Mon Nov 4 23:49:50 UTC 2013
This is an automated email from the git hooks/post-receive script.
hmmr-guest pushed a commit to branch WIP
in repository aghermann.
commit eb2d5165ab6308e2a60c9575930ce54f9cc9f309
Author: Andrei Zavada <johnhommer at gmail.com>
Date: Sun Sep 29 17:02:33 2013 +0300
use log-facility (part 2/2)
---
upstream/ChangeLog | 1 +
upstream/man/aghermann.1.in | 8 ++-
upstream/src/aghermann/expdesign/dirlevel.cc | 3 +-
upstream/src/aghermann/expdesign/expdesign.cc | 31 +++------
upstream/src/aghermann/expdesign/expdesign.hh | 2 +-
upstream/src/aghermann/expdesign/loadsave.cc | 15 +++--
upstream/src/aghermann/expdesign/recording.cc | 38 +++++------
upstream/src/aghermann/expdesign/subject.cc | 4 +-
upstream/src/aghermann/expdesign/tree-scanner.cc | 77 ++++++++++------------
upstream/src/aghermann/globals.cc | 11 ++--
upstream/src/aghermann/globals.hh | 10 +--
upstream/src/aghermann/main.cc | 12 ++--
upstream/src/aghermann/model/borbely.cc | 16 ++---
upstream/src/aghermann/ui/mw/admit-one.cc | 3 +-
upstream/src/aghermann/ui/mw/populate.cc | 42 ++++++------
upstream/src/common/libcommon.cc | 1 +
upstream/src/common/log-facility.cc | 27 +++++++-
upstream/src/common/log-facility.hh | 17 ++++-
upstream/src/libsigfile/edf-io.cc | 4 +-
upstream/src/libsigfile/edf.cc | 41 ++++++------
upstream/src/libsigfile/edf.hh | 14 ++--
upstream/src/libsigfile/page.cc | 5 +-
upstream/src/libsigfile/page.hh | 15 +++--
upstream/src/libsigfile/source-base.cc | 36 +++++-----
upstream/src/libsigfile/source-base.hh | 15 +++--
upstream/src/libsigfile/tsv.cc | 36 +++++-----
upstream/src/libsigfile/tsv.hh | 11 ++--
upstream/src/libsigfile/typed-source.cc | 19 +++---
upstream/src/libsigfile/typed-source.hh | 15 ++---
upstream/src/tools/agh-profile-gen.cc | 2 +-
upstream/src/tools/edfcat.cc | 8 ++-
upstream/src/tools/edfhed-gtk.cc | 3 +-
upstream/src/tools/edfhed.cc | 3 +-
33 files changed, 298 insertions(+), 247 deletions(-)
diff --git a/upstream/ChangeLog b/upstream/ChangeLog
index 1685d92..3a41e12 100644
--- a/upstream/ChangeLog
+++ b/upstream/ChangeLog
@@ -10,6 +10,7 @@ v.0.9.2 (2013-xx-xx)
stored settings packs (patterns, rk1968, etc).
* Incorporate edfhed.glade in aghermann.gresources.
* SF: basic dialog for RK1968 scoring assistant parameters.
+ * Get a reasonable logging facility (use -l file; "-" is stdout; default is /dev/null).
v.0.9.1.1 (2013-07-24)
* Fix 32-bit builds where sizeof(size_t) != sizeof(unsigned long).
diff --git a/upstream/man/aghermann.1.in b/upstream/man/aghermann.1.in
index 521e955..ef22656 100644
--- a/upstream/man/aghermann.1.in
+++ b/upstream/man/aghermann.1.in
@@ -1,8 +1,8 @@
.TH Aghermann 1 "@build_date@" @VERSION@ "Aghermann"
.SH NAME
- Aghermann -- a sleep research experiment manager and Achermann et al (1993) model simulator
+Aghermann -- a sleep research experiment manager and Achermann et al (1993) model simulator
.SH SYNOPSIS
- aghermann [\-n] [\fIEXP_ROOT_DIR\fR]
+aghermann [\-l \fILOG_FILE\fR] [\-n] [\fIEXP_ROOT_DIR\fR]
.B
.PP
@@ -31,6 +31,10 @@ will exit. No windows will be open and no GTK+ code run; this option
was implemented with the idea of running the core structural part of
\fBAghermann\fR under valgrind.
+With option \fB\-l\fR \fILOG_FILE\fR, aghermann will write a log of
+its inner workings to \fILOG_FILE\fR; if the latter is "-", stdout is
+used. By default, (almost all) logging is suppressed.
+
.SH NOTE ON EDF FILE METADATA
.PP
For Aghermann to be able to manage an EDF file, all relevant fields in
diff --git a/upstream/src/aghermann/expdesign/dirlevel.cc b/upstream/src/aghermann/expdesign/dirlevel.cc
index 8eaae66..952c912 100644
--- a/upstream/src/aghermann/expdesign/dirlevel.cc
+++ b/upstream/src/aghermann/expdesign/dirlevel.cc
@@ -16,6 +16,7 @@
#include "common/string.hh"
#include "common/fs.hh"
+#include "aghermann/globals.hh"
#include "expdesign.hh"
#include "dirlevel.hh"
@@ -104,7 +105,7 @@ save()
string p = path();
if ( fs::mkdir_with_parents( fs::dirname(p)) ) {
- fprintf( stderr, "CStorablePPack::save(\"%s\"): mkdir failed: %s\n", p.c_str(), strerror(errno));
+ APPLOG_WARN ("CStorablePPack::save(\"%s\"): mkdir failed: %s", p.c_str(), strerror(errno));
return -1;
}
diff --git a/upstream/src/aghermann/expdesign/expdesign.cc b/upstream/src/aghermann/expdesign/expdesign.cc
index a7b6c3c..e0d5cd7 100644
--- a/upstream/src/aghermann/expdesign/expdesign.cc
+++ b/upstream/src/aghermann/expdesign/expdesign.cc
@@ -90,7 +90,7 @@ CExpDesign (const string& session_dir_,
throw invalid_argument (string ("Failed to canonicalize dir: ") + session_dir_);
if ( session_dir_ != tmp ) {
- LOG_INFO( "canonicalized session_dir \"%s\" to \"%s\"", session_dir_.c_str(), tmp);
+ APPLOG_INFO( "canonicalized session_dir \"%s\" to \"%s\"", session_dir_.c_str(), tmp);
_session_dir.assign( tmp);
} else
_session_dir = session_dir_;
@@ -112,10 +112,10 @@ CExpDesign (const string& session_dir_,
#ifdef _OPENMP
omp_set_num_threads( (num_threads == 0) ? global::num_procs : num_threads);
- LOG_INFO( "SMP enabled with %d threads", omp_get_max_threads());
+ APPLOG_INFO( "SMP enabled with %d threads", omp_get_max_threads());
#endif
if ( last_used_version != VERSION ) {
- LOG_INFO( "Purging old files as we are upgrading from version %s to %s", last_used_version.c_str(), VERSION);
+ APPLOG_INFO( "Purging old files as we are upgrading from version %s to %s", last_used_version.c_str(), VERSION);
}
// last_used_version = VERSION;
/// leave it so SExpDesignUI::populate will see it and pop the changelog
@@ -126,25 +126,13 @@ CExpDesign (const string& session_dir_,
void
agh::CExpDesign::
-log_message( const char* fmt, ...)
+log_message( TLogEntryStyle style, const char* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
- char *buf0;
- int np = vasprintf( &buf0, fmt, ap);
- char *buf = buf0;
- if ( np > 0 ) {
- TLogEntryStyle style =
- (strncmp( buf, "$$", 2) == 0)
- ? ((buf += 2), TLogEntryStyle::bold)
- : (strncmp( buf, "//", 2) == 0)
- ? ((buf += 2), TLogEntryStyle::italic)
- : TLogEntryStyle::plain;
- _error_log.emplace_back( buf, style);
- }
- if ( np != -1 )
- free( (void*)buf0);
+ string line = str::svasprintf( fmt, ap);
+ _error_log.emplace_back( line, style);
va_end (ap);
}
@@ -497,13 +485,14 @@ setup_modrun( const string& j, const string& d, const string& h,
. modrun_sets[profile_params0][h];
} catch (invalid_argument ex) { // thrown by CProfile ctor
- fprintf( stderr, "CExpDesign::setup_modrun( %s, %s, %s): %s\n", j.c_str(), d.c_str(), h.c_str(), ex.what());
+ APPLOG_WARN ("setup_modrun( %s, %s, %s): %s", j.c_str(), d.c_str(), h.c_str(), ex.what());
return -1;
} catch (out_of_range ex) {
- fprintf( stderr, "CExpDesign::setup_modrun( %s, %s, %s): %s\n", j.c_str(), d.c_str(), h.c_str(), ex.what());
+ APPLOG_WARN ("setup_modrun( %s, %s, %s): %s", j.c_str(), d.c_str(), h.c_str(), ex.what());
return -1;
} catch (int ex) { // thrown by CModelRun ctor
- log_message( "CExpDesign::setup_modrun( %s, %s, %s): %s", j.c_str(), d.c_str(), h.c_str(), CProfile::explain_status(ex).c_str());
+ APPLOG_WARN ("setup_modrun( %s, %s, %s): %s", j.c_str(), d.c_str(), h.c_str(), CProfile::explain_status(ex).c_str());
+ log_message( TLogEntryStyle::plain, "setup_modrun( %s, %s, %s): %s", j.c_str(), d.c_str(), h.c_str(), CProfile::explain_status(ex).c_str());
return ex;
}
diff --git a/upstream/src/aghermann/expdesign/expdesign.hh b/upstream/src/aghermann/expdesign/expdesign.hh
index 2bf1fc8..f3b8ec0 100644
--- a/upstream/src/aghermann/expdesign/expdesign.hh
+++ b/upstream/src/aghermann/expdesign/expdesign.hh
@@ -92,7 +92,7 @@ class CExpDesign {
string error_log_serialize() const;
size_t error_log_n_messages() const
{ return _error_log.size(); }
- void log_message( const char* fmt, ...) __attribute__ (( format (printf, 2, 3) ));
+ void log_message( TLogEntryStyle, const char* fmt, ...) __attribute__ (( format (printf, 3, 4) ));
// contains
typedef map<string, CJGroup> TJGroups;
diff --git a/upstream/src/aghermann/expdesign/loadsave.cc b/upstream/src/aghermann/expdesign/loadsave.cc
index c81fae4..4e82752 100644
--- a/upstream/src/aghermann/expdesign/loadsave.cc
+++ b/upstream/src/aghermann/expdesign/loadsave.cc
@@ -10,6 +10,7 @@
*/
#include "project_strings.h"
+#include "aghermann/globals.hh"
#include "aghermann/model/achermann.hh"
#include "expdesign.hh"
@@ -38,7 +39,7 @@ load_settings()
tstep [t] = A[3];
}
} catch (...) {
- fprintf( stderr, "CExpDesign::load_settings(): Something is wrong with %s\n", EXPD_FILE);
+ APPLOG_INFO ("load_settings(\"%s\"): File not readable or has invalid contents", EXPD_FILE);
_status = _status | load_fail;
@@ -59,33 +60,33 @@ load_settings()
freq_bands[i][0] = f0;
freq_bands[i][1] = f1;
} else
- fprintf( stderr, "agh::SExpDesign::load_settings(): Invalid Band range\n");
+ APPLOG_WARN ("load_settings(\"%s\"): Invalid Band range", EXPD_FILE);
}
} catch (...) {
- fprintf( stderr, "agh::SExpDesign::load_settings(): Something is wrong with section Band\n");
+ APPLOG_WARN ("load_settings(\"%s\"): Something is wrong with Band section", EXPD_FILE);
}
try { ctl_params0.check(); }
catch (...) {
ctl_params0.reset();
- fprintf( stderr, "agh::CExpDesign::load_settings(): Invalid ctl params\n");
+ APPLOG_WARN ("load_settings(\"%s\"): Invalid ctl parameters", EXPD_FILE);
}
if ( tunables0.check() ) {
tunables0.set_defaults();
- fprintf( stderr, "agh::CExpDesign::load_settings(): Invalid tunables\n");
+ APPLOG_WARN ("load_settings(\"%s\"): Invalid tunables", EXPD_FILE);
}
try { fft_params.check(); }
catch (invalid_argument ex) {
fft_params.reset();
- fprintf( stderr, "agh::CExpDesign::load_settings(): Invalid fft params (%s)\n", ex.what());
+ APPLOG_WARN ("load_settings(\"%s\"): Invalid FFT params (%s)", EXPD_FILE, ex.what());
}
try { mc_params.check(); }
catch (invalid_argument ex) {
mc_params.reset();
- fprintf( stderr, "agh::CExpDesign::load_settings(): Invalid mc params (%s)\n", ex.what());
+ APPLOG_WARN ("load_settings(\"%s\"): Invalid MC params (%s)", EXPD_FILE, ex.what());
}
return 0;
diff --git a/upstream/src/aghermann/expdesign/recording.cc b/upstream/src/aghermann/expdesign/recording.cc
index d0345dc..a3b2efb 100644
--- a/upstream/src/aghermann/expdesign/recording.cc
+++ b/upstream/src/aghermann/expdesign/recording.cc
@@ -124,13 +124,13 @@ CProfile (CSubject& J, const string& d, const sigfile::SChannel& h,
pz = pa + M.hypnogram().n_pages();
// anchor zero page, get pagesize from edf^W CBinnedPower^W either goes
time_t dima = F.start_time();
- LOG_INFO ("adding %s of [%s, %s, %s] %zu pages (%zu full, %zu in hypnogram) recorded %s",
- metrics::name(params.metric), F.subject().id.c_str(), F.session(), F.episode(),
- M.total_pages(), M.full_pages(), M.hypnogram().n_pages(), ctime( &dima));
+ APPLOG_INFO ("adding %s of [%s, %s, %s] %zu pages (%zu full, %zu in hypnogram) recorded %s",
+ metrics::name(params.metric), F.subject().id.c_str(), F.session(), F.episode(),
+ M.total_pages(), M.full_pages(), M.hypnogram().n_pages(), ctime( &dima));
if ( pz - pa != (int)M.full_pages() ) {
- LOG_WARN ("correcting end page to match full page count in EDF: %d->%zu",
- pz, pa + M.full_pages());
+ APPLOG_WARN ("correcting end page to match full page count in EDF: %d->%zu",
+ pz, pa + M.full_pages());
pz = pa + M.full_pages();
}
_pages_in_bed += (pz-pa);
@@ -152,12 +152,12 @@ CProfile (CSubject& J, const string& d, const sigfile::SChannel& h,
create_timeline();
if ( _sim_start != (size_t)-1 )
- LOG_INFO ("sim start-end: %zu-%zu; avg SWA = %.4g (over %zu pp, or %.3g%% of all time in bed); "
- " SWA_L = %g; SWA[%zu] = %g",
- _sim_start, _sim_end, _SWA_100, _pages_with_SWA, (double)_pages_with_SWA / _pages_in_bed * 100,
- _SWA_L, _sim_start, _SWA_0);
+ APPLOG_INFO ("sim start-end: %zu-%zu; avg SWA = %.4g (over %zu pp, or %.3g%% of all time in bed); "
+ " SWA_L = %g; SWA[%zu] = %g",
+ _sim_start, _sim_end, _SWA_100, _pages_with_SWA, (double)_pages_with_SWA / _pages_in_bed * 100,
+ _SWA_L, _sim_start, _SWA_0);
else
- LOG_WARN ("status %xd, %s", _status, CProfile::explain_status( _status).c_str());
+ APPLOG_WARN ("status %xd, %s", _status, CProfile::explain_status( _status).c_str());
}
@@ -179,12 +179,12 @@ CProfile (CRecording& M,
int pa = (size_t)difftime( M.F().start_time(), _0at) / _pagesize,
pz = (size_t)difftime( M.F().end_time(), _0at) / _pagesize;
time_t dima = M.F().start_time();
- LOG_INFO ("adding single recording %s of [%s, %s, %s] %zu pages (%zu full, %zu in hypnogram) recorded %s",
- metrics::name(params.metric), M.F().subject().id.c_str(), M.F().session(), M.F().episode(),
- M.total_pages(), M.full_pages(), M.hypnogram().n_pages(), ctime( &dima));
+ APPLOG_INFO ("adding single recording %s of [%s, %s, %s] %zu pages (%zu full, %zu in hypnogram) recorded %s",
+ metrics::name(params.metric), M.F().subject().id.c_str(), M.F().session(), M.F().episode(),
+ M.total_pages(), M.full_pages(), M.hypnogram().n_pages(), ctime( &dima));
if ( pz - pa != (int)M.full_pages() ) {
- LOG_WARN ("correcting end page to match full page count in EDF: %d->%zu",
+ APPLOG_WARN ("correcting end page to match full page count in EDF: %d->%zu",
pz, pa + M.full_pages());
pz = pa + M.full_pages();
}
@@ -206,12 +206,12 @@ CProfile (CRecording& M,
create_timeline();
if ( _sim_start != (size_t)-1 )
- LOG_INFO ("CProfile::CProfile(): sim start-end: %zu-%zu; avg SWA = %.4g (over %zu pp, or %.3g%% of all time in bed); "
- " SWA_L = %g; SWA[%zu] = %g",
- _sim_start, _sim_end, _SWA_100, _pages_with_SWA, (double)_pages_with_SWA / _pages_in_bed * 100,
- _SWA_L, _sim_start, _SWA_0);
+ APPLOG_INFO ("CProfile::CProfile(): sim start-end: %zu-%zu; avg SWA = %.4g (over %zu pp, or %.3g%% of all time in bed); "
+ " SWA_L = %g; SWA[%zu] = %g",
+ _sim_start, _sim_end, _SWA_100, _pages_with_SWA, (double)_pages_with_SWA / _pages_in_bed * 100,
+ _SWA_L, _sim_start, _SWA_0);
else
- LOG_WARN ("status %xd, %s", _status, CProfile::explain_status( _status).c_str());
+ APPLOG_WARN ("status %xd, %s", _status, CProfile::explain_status( _status).c_str());
}
diff --git a/upstream/src/aghermann/expdesign/subject.cc b/upstream/src/aghermann/expdesign/subject.cc
index 962ffdb..d421f21 100644
--- a/upstream/src/aghermann/expdesign/subject.cc
+++ b/upstream/src/aghermann/expdesign/subject.cc
@@ -70,8 +70,8 @@ SEpisode (sigfile::CTypedSource&& F_,
sources.emplace_back( move(F_));
auto& F = sources.back();
auto HH = F().channel_list();
- LOG_INFO ("SEpisode( \"%s\"): %s",
- F().filename(), sigfile::join_channel_names(HH, ", ").c_str());
+ APPLOG_INFO ("SEpisode( \"%s\"): %s",
+ F().filename(), sigfile::join_channel_names(HH, ", ").c_str());
int h = 0;
for ( auto& H : HH )
recordings.insert( {H, {F, h++, fft_params, swu_params, mc_params}});
diff --git a/upstream/src/aghermann/expdesign/tree-scanner.cc b/upstream/src/aghermann/expdesign/tree-scanner.cc
index f42879e..2363f59 100644
--- a/upstream/src/aghermann/expdesign/tree-scanner.cc
+++ b/upstream/src/aghermann/expdesign/tree-scanner.cc
@@ -28,7 +28,7 @@ namespace {
struct progress_fun_stdout_fo {
void operator()( const string& current, size_t n, size_t i) const
{
- LOG_INFO ("(%zu of %zu) %s\n", i, n, current.c_str());
+ APPLOG_INFO ("(%zu of %zu) %s\n", i, n, current.c_str());
}
};
} // namespace
@@ -73,8 +73,8 @@ add_one( sigfile::CTypedSource&& Fmc,
} else { // same as SEpisode() but done on an existing one
// check that the edf source being added has exactly the same timestamp and duration
- LOG_INFO( "SEpisodeSequence::add_one( \"%s\") try in-place\n",
- Fmc().filename());
+ APPLOG_INFO( "SEpisodeSequence::add_one( \"%s\") try in-place\n",
+ Fmc().filename());
if ( fabs( difftime( Ei->start_time(), Fmc().start_time())) > 1 )
return AGH_EPSEQADD_TOOFAR;
Ei->sources.emplace_back( move(Fmc));
@@ -100,9 +100,6 @@ add_one( sigfile::CTypedSource&& Fmc,
// October, which makes no sense in circadian
// context
e0.start_rel = mktime( &t0);
- // printf( "E0 %s: ", e0.name());
- // puts( asctime( localtime(&e0.start_time())));
- // puts( asctime( localtime(&e0.start_rel)));
double shift = difftime( e0.start_rel, e0.start_time());
e0.end_rel = e0.end_time() + shift;
@@ -111,10 +108,6 @@ add_one( sigfile::CTypedSource&& Fmc,
{
E.start_rel = E.start_time() + shift;
E.end_rel = E.end_time() + shift;
- // printf("E %s: ", E.name());
- // puts( asctime( localtime(&E.start_time())));
- // puts( asctime( localtime(&E.start_rel)));
- // printf( "--\n");
});
return episodes.size();
@@ -164,16 +157,16 @@ register_intree_source( sigfile::CTypedSource&& F,
// refuse to register sources of wrong subjects
if ( j_name != F().subject().id ) {
- log_message( "$$%s:", F().filename());
- log_message( "file belongs to subject %s (\"%s\"), is misplaced here under subject \"%s\"",
+ log_message( TLogEntryStyle::bold, "%s:", F().filename());
+ log_message( TLogEntryStyle::plain, "file belongs to subject %s (\"%s\"), is misplaced here under subject \"%s\"",
F().subject().id.c_str(), F().subject().name.c_str(), j_name.c_str());
return -1;
}
try {
auto existing_group = group_of( F().subject().id.c_str());
if ( g_name != existing_group ) {
- log_message( "$$%s:", F().filename());
- log_message( "subject %s (\"%s\") belongs to a different group (\"%s\")",
+ log_message( TLogEntryStyle::bold, "%s:", F().filename());
+ log_message( TLogEntryStyle::plain, "subject %s (\"%s\") belongs to a different group (\"%s\")",
F().subject().id.c_str(), F().subject().name.c_str(), existing_group);
return -1;
}
@@ -183,13 +176,13 @@ register_intree_source( sigfile::CTypedSource&& F,
// but correct session/episode fields
if ( d_name != F().session() ) {
- log_message( "$$%s:", F().filename());
- log_message( "correcting embedded session \"%s\" to match placement in the tree (\"%s\")",
+ log_message( TLogEntryStyle::bold, "%s:", F().filename());
+ log_message( TLogEntryStyle::plain, "correcting embedded session \"%s\" to match placement in the tree (\"%s\")",
F().session(), d_name.c_str());
F().set_session( d_name.c_str());
}
if ( e_name != F().episode() ) {
- log_message( "correcting embedded episode \"%s\" to match file name",
+ log_message( TLogEntryStyle::plain, "correcting embedded episode \"%s\" to match file name",
F().episode());
F().set_episode( e_name.c_str());
}
@@ -205,42 +198,39 @@ register_intree_source( sigfile::CTypedSource&& F,
}
// check/update CSubject::SSubjectId fields against those in the file being added
- // printf( "Update subject details: [%s, %s, %c, %s] <- [%s, %s, %c, %s]\n",
- // J->id.c_str(), J->name.c_str(), J->gender_sign(), ctime(&J->dob),
- // F().subject().id.c_str(), F().subject().name.c_str(), F().subject().gender_sign(), ctime(&F().subject().dob));
if ( J->try_update_subject_details( F().subject()) ) {
if ( strict_subject_id_checks ) {
- LOG_WARN( "%s: subject details mismatch", F().filename());
+ APPLOG_WARN( "%s: subject details mismatch", F().filename());
return -1;
} else
- LOG_WARN( "%s: keeping previously recorded subject details", F().filename());
+ APPLOG_WARN( "%s: keeping previously recorded subject details", F().filename());
}
// insert/update episode observing start/end times
- LOG_INFO( "register_intree_source( file: \"%s\", J: %s (\"%s\"), E: \"%s\", D: \"%s\")",
- F().filename(), F().subject().id.c_str(), F().subject().name.c_str(), F().episode(), F().session());
+ APPLOG_INFO( "register_intree_source( file: \"%s\", J: %s (\"%s\"), E: \"%s\", D: \"%s\")",
+ F().filename(), F().subject().id.c_str(), F().subject().name.c_str(), F().episode(), F().session());
switch ( J->measurements[F().session()].add_one(
move(F), fft_params, swu_params, mc_params) ) { // this will do it
case AGH_EPSEQADD_OVERLAP:
- log_message( "%s: not added as it overlaps with existing episodes", F().filename());
- LOG_WARN( "%s: not added as it overlaps with existing episodes", F().filename());
+ log_message( TLogEntryStyle::plain, "%s: not added as it overlaps with existing episodes", F().filename());
+ APPLOG_WARN ("%s: not added as it overlaps with existing episodes", F().filename());
return -1;
case AGH_EPSEQADD_TOOFAR:
- log_message( "%s: not added as it is too far removed from the rest", F().filename());
- LOG_WARN ( "%s: not added as it is too far removed from the rest", F().filename());
+ log_message( TLogEntryStyle::plain, "%s: not added as it is too far removed from the rest", F().filename());
+ APPLOG_WARN ("%s: not added as it is too far removed from the rest", F().filename());
return -1;
default:
return 0;
}
} catch (invalid_argument ex) {
- log_message( "%s", ex.what());
+ log_message( TLogEntryStyle::plain, "%s", ex.what());
if ( reason_if_failed_p )
*reason_if_failed_p = ex.what();
return -1;
} catch (int status) {
- log_message( "Bad edf header or data");
- LOG_WARN( "Bad edf header or data");
+ log_message( TLogEntryStyle::plain, "Bad edf header or data");
+ APPLOG_WARN( "Bad edf header or data");
if ( reason_if_failed_p )
*reason_if_failed_p = "Bad edf header or data";
return -1;
@@ -274,20 +264,23 @@ supported_sigfile_processor( const char *fname, const struct stat*, int flag, st
only_progress_fun( fname, fs::total_supported_sigfiles, current_sigfile_source);
try {
using namespace sigfile;
- CTypedSource F {fname, (size_t)roundf(only_expdesign->fft_params.pagesize)};
+ CTypedSource F {fname,
+ (size_t)roundf(only_expdesign->fft_params.pagesize),
+ 0,
+ agh::global::default_log_facility};
string st = F().explain_status();
if ( not st.empty() ) {
- only_expdesign->log_message( "$$%s:", fname);
- only_expdesign->log_message( "%s", st.c_str());
+ only_expdesign->log_message( CExpDesign::TLogEntryStyle::bold, "%s:", fname);
+ only_expdesign->log_message( CExpDesign::TLogEntryStyle::plain, "%s", st.c_str());
}
if ( sigfile::is_supported_source(F) )
only_expdesign -> register_intree_source( move(F));
else
- only_expdesign -> log_message( "File %s: unsupported format", fname);
+ only_expdesign -> log_message( CExpDesign::TLogEntryStyle::bold, "%s: unsupported format", fname);
} catch ( invalid_argument ex) {
- only_expdesign->log_message( "%s", ex.what());
+ only_expdesign->log_message( CExpDesign::TLogEntryStyle::plain, "%s", ex.what());
}
}
}
@@ -327,8 +320,8 @@ scan_tree( TMsmtCollectProgressIndicatorFun user_progress_fun)
// glob it!
fs::total_supported_sigfiles = 0;
nftw( "./", fs::supported_sigfile_counter, 20, 0);
- LOG_INFO( "scan_tree(\"%s\"): %zu edf file(s) found",
- session_dir(), fs::total_supported_sigfiles);
+ APPLOG_INFO( "scan_tree(\"%s\"): %zu edf file(s) found",
+ session_dir(), fs::total_supported_sigfiles);
if ( fs::total_supported_sigfiles == 0 )
return;
@@ -336,10 +329,10 @@ scan_tree( TMsmtCollectProgressIndicatorFun user_progress_fun)
only_progress_fun = user_progress_fun;
only_expdesign = this;
nftw( "./", supported_sigfile_processor, 10, 0);
- LOG_INFO( "scan_tree(): recordings collected");
+ APPLOG_INFO( "scan_tree(): recordings collected");
compute_profiles(); // in an SMP fashion
- LOG_INFO( "scan_tree(): all computed");
+ APPLOG_INFO( "scan_tree(): all computed");
// find any subjects with incomplete episode sets
list<string> complete_episode_set = enumerate_episodes();
@@ -351,8 +344,8 @@ scan_tree( TMsmtCollectProgressIndicatorFun user_progress_fun)
for ( auto &D : J.measurements )
if ( D.second.episodes.size() < n_episodes &&
complete_episode_set.front() != D.second.episodes.begin()->name() ) { // the baseline is missing
- log_message( "No Baseline episode in %s's %s: skip this session", J.id.c_str(), D.first.c_str());
- LOG_WARN( "No Baseline episode in %s's %s: skip this session", J.id.c_str(), D.first.c_str());
+ log_message( TLogEntryStyle::plain, "No Baseline episode in %s's %s: skip this session", J.id.c_str(), D.first.c_str());
+ APPLOG_WARN ("No Baseline episode in %s's %s: skip this session", J.id.c_str(), D.first.c_str());
J.measurements.erase(D.first);
goto startover;
}
diff --git a/upstream/src/aghermann/globals.cc b/upstream/src/aghermann/globals.cc
index 514dae4..5a2013c 100644
--- a/upstream/src/aghermann/globals.cc
+++ b/upstream/src/aghermann/globals.cc
@@ -37,7 +37,7 @@ int agh::global::num_procs = 1;
void
agh::global::
-init()
+init( const string& lf_fname)
{
// 1. init rng
{
@@ -61,7 +61,8 @@ init()
// 3. log facility
{
- default_log_facility = new agh::log::CLogFacility ("-");
+ default_log_facility =
+ lf_fname.empty() ? nullptr : new agh::log::CLogFacility (lf_fname);
}
}
@@ -72,7 +73,8 @@ fini()
{
gsl_rng_free( rng);
rng = nullptr;
- delete default_log_facility;
+ if ( default_log_facility )
+ delete default_log_facility;
default_log_facility = nullptr;
}
@@ -84,7 +86,8 @@ void
agh::global::
log( agh::log::TLevel level, const char* issuer, const char* fmt, ...)
{
- assert (default_log_facility);
+ if ( !default_log_facility )
+ return;
va_list ap;
va_start (ap, fmt);
default_log_facility -> vmsg( level, issuer, fmt, ap);
diff --git a/upstream/src/aghermann/globals.hh b/upstream/src/aghermann/globals.hh
index f0f5f52..e3ec71f 100644
--- a/upstream/src/aghermann/globals.hh
+++ b/upstream/src/aghermann/globals.hh
@@ -31,12 +31,12 @@ extern int num_procs;
extern agh::log::CLogFacility* default_log_facility;
void log( agh::log::TLevel, const char* issuer, const char* fmt, ...) __attribute__ ((format (printf, 3, 4)));
-#define LOG_DEBUG(...) do agh::global::log( agh::log::TLevel::debug, agh::str::sasprintf("%s:%zu", __FILE__, __LINE__).c_str(), __VA_ARGS__); while (0)
-#define LOG_INFO(...) do agh::global::log( agh::log::TLevel::info, agh::str::sasprintf("%s:%zu", __FILE__, __LINE__).c_str(), __VA_ARGS__); while (0)
-#define LOG_WARN(...) do agh::global::log( agh::log::TLevel::warning, agh::str::sasprintf("%s:%zu", __FILE__, __LINE__).c_str(), __VA_ARGS__); while (0)
-#define LOG_ERROR(...) do agh::global::log( agh::log::TLevel::error, agh::str::sasprintf("%s:%zu", __FILE__, __LINE__).c_str(), __VA_ARGS__); while (0)
+#define APPLOG_DEBUG(...) do agh::global::log( agh::log::TLevel::debug, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
+#define APPLOG_INFO(...) do agh::global::log( agh::log::TLevel::info, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
+#define APPLOG_WARN(...) do agh::global::log( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
+#define APPLOG_ERROR(...) do agh::global::log( agh::log::TLevel::error, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
-void init();
+void init( const string& lf_fname);
void fini();
} // namespace global
diff --git a/upstream/src/aghermann/main.cc b/upstream/src/aghermann/main.cc
index c2b3813..2c24253 100644
--- a/upstream/src/aghermann/main.cc
+++ b/upstream/src/aghermann/main.cc
@@ -42,12 +42,16 @@ main( int argc, char **argv)
print_version();
bool headless = false;
+ string lf_fname = "";
int c;
- while ( (c = getopt( argc, argv, "hn")) != -1 )
+ while ( (c = getopt( argc, argv, "hnl:")) != -1 )
switch ( c ) {
case 'n': // headless
headless = true;
break;
+ case 'l':
+ lf_fname.assign( optarg);
+ break;
case 'h':
print_usage( argv[0]);
return 0;
@@ -61,7 +65,7 @@ main( int argc, char **argv)
return -1;
}
- global::init();
+ global::init( lf_fname);
CExpDesign ED (explicit_session); // essentially a very thoughtful no-op
global::fini();
@@ -82,7 +86,7 @@ main( int argc, char **argv)
(GCallback)message_received_cb,
NULL);
- agh::global::init();
+ agh::global::init( lf_fname);
if ( agh::ui::global::prepare_for_expdesign() ) {
ui::pop_ok_message(
@@ -141,7 +145,7 @@ message_received_cb(
void
print_usage( const char* argv0)
{
- printf( "Usage: %s [-n] [exp_root_dir]\n", argv0);
+ printf( "Usage: %s [-n] [-l log_file] [exp_root_dir]\n", argv0);
}
} // namespace
diff --git a/upstream/src/aghermann/model/borbely.cc b/upstream/src/aghermann/model/borbely.cc
index 4e281f3..04d0ded 100644
--- a/upstream/src/aghermann/model/borbely.cc
+++ b/upstream/src/aghermann/model/borbely.cc
@@ -89,12 +89,10 @@ expb_fdf( const gsl_vector* x, void *data,
void
print_state( size_t iter, gsl_multifit_fdfsolver* s)
{
- LOG_DEBUG ("iter: %3zu x = % 15.8f "
- "|f(x)| = %g",
- iter,
- gsl_vector_get (s->x, 0),
-// gsl_vector_get (s->x, 1),
- gsl_blas_dnrm2 (s->f));
+ APPLOG_DEBUG ("iter: %3zu x = % 15.8f |f(x)| = %g",
+ iter,
+ gsl_vector_get (s->x, 0),
+ gsl_blas_dnrm2 (s->f));
}
} // namespace
@@ -166,7 +164,7 @@ classic_fit( agh::CRecording& M,
print_state( iter, S);
if ( status ) {
- LOG_WARN ("status = %s", gsl_strerror( status));
+ APPLOG_WARN ("status = %s", gsl_strerror( status));
break;
}
@@ -183,8 +181,8 @@ classic_fit( agh::CRecording& M,
double dof = pp - 1;
double c = GSL_MAX_DBL(1, chi / sqrt(dof));
- LOG_DEBUG ("chisq/dof = %g", gsl_pow_2(chi) / dof);
- LOG_DEBUG ("r = %.5f +/- %.5f", FIT(0), c*ERR(0));
+ APPLOG_DEBUG ("chisq/dof = %g", gsl_pow_2(chi) / dof);
+ APPLOG_DEBUG ("r = %.5f +/- %.5f", FIT(0), c*ERR(0));
}
double rate = gsl_vector_get( S->x, 0);
diff --git a/upstream/src/aghermann/ui/mw/admit-one.cc b/upstream/src/aghermann/ui/mw/admit-one.cc
index b3dee39..c5055b2 100644
--- a/upstream/src/aghermann/ui/mw/admit-one.cc
+++ b/upstream/src/aghermann/ui/mw/admit-one.cc
@@ -11,6 +11,7 @@
#include "libsigfile/edf.hh"
+#include "aghermann/globals.hh"
#include "aghermann/ui/misc.hh"
#include "mw.hh"
@@ -24,7 +25,7 @@ dnd_maybe_admit_one( const char* fname)
{
try {
string info;
- sigfile::CTypedSource F_ (fname, ED->fft_params.pagesize);
+ sigfile::CTypedSource F_ (fname, ED->fft_params.pagesize, 0, agh::global::default_log_facility);
switch ( F_.type() ) {
case sigfile::CTypedSource::TType::edf:
{
diff --git a/upstream/src/aghermann/ui/mw/populate.cc b/upstream/src/aghermann/ui/mw/populate.cc
index e382543..463f2e9 100644
--- a/upstream/src/aghermann/ui/mw/populate.cc
+++ b/upstream/src/aghermann/ui/mw/populate.cc
@@ -27,7 +27,7 @@ int
SExpDesignUI::
populate( bool do_load)
{
- LOG_INFO ("SExpDesignUI::populate():");
+ APPLOG_INFO ("SExpDesignUI::populate():");
AghDD = ED->enumerate_sessions();
_AghDi = AghDD.begin();
AghGG = ED->enumerate_groups();
@@ -39,29 +39,29 @@ populate( bool do_load)
AghEE = ED->enumerate_episodes();
_AghEi = AghEE.begin();
- LOG_INFO ("* Sessions: %s\n"
- "* Groups: %s\n"
- "* All Channels: %s\n"
- "* EEG Channels: %s\n"
- "* Episodes: %s",
- agh::str::join( AghDD, "; ").c_str(),
- agh::str::join( AghGG, "; ").c_str(),
- sigfile::join_channel_names( AghHH, "; ").c_str(),
- sigfile::join_channel_names( AghTT, "; ").c_str(),
- agh::str::join( AghEE, "; ").c_str());
+ APPLOG_INFO ("* Sessions: %s\n"
+ "* Groups: %s\n"
+ "* All Channels: %s\n"
+ "* EEG Channels: %s\n"
+ "* Episodes: %s",
+ agh::str::join( AghDD, "; ").c_str(),
+ agh::str::join( AghGG, "; ").c_str(),
+ sigfile::join_channel_names( AghHH, "; ").c_str(),
+ sigfile::join_channel_names( AghTT, "; ").c_str(),
+ agh::str::join( AghEE, "; ").c_str());
used_samplerates =
ED->used_samplerates();
used_eeg_samplerates =
ED->used_samplerates( sigfile::SChannel::TType::eeg);
if ( used_eeg_samplerates.size() == 1 )
- LOG_INFO ("single common EEG samplerate: %zu", used_eeg_samplerates.front());
+ APPLOG_INFO ("single common EEG samplerate: %zu", used_eeg_samplerates.front());
else
- LOG_INFO ("multiple EEG samplerates (%zu)", used_eeg_samplerates.size());
+ APPLOG_INFO ("multiple EEG samplerates (%zu)", used_eeg_samplerates.size());
if ( do_load ) {
if ( load_settings() ) {
- LOG_WARN ("load_settings() had issues");
+ APPLOG_WARN ("load_settings() had issues");
pop_ok_message( wMainWindow, "Settings could not be loaded", "It's ok, we'll use the defaults.");
}
if ( geometry.w > 0 ) {// implies the rest are, too
@@ -76,7 +76,7 @@ populate( bool do_load)
(string ("Aghermann: ") + agh::str::homedir2tilda( ED->session_dir())).c_str());
if ( ED->last_used_version != VERSION ) {
- LOG_INFO ("Upgrading from version %s, here's ChangeLog for you", ED->last_used_version.c_str());
+ APPLOG_INFO ("Upgrading from version %s, here's ChangeLog for you", ED->last_used_version.c_str());
show_changelog();
}
ED->last_used_version = VERSION;
@@ -407,7 +407,7 @@ populate_1()
(GtkCallback)gtk_widget_destroy,
NULL);
- LOG_INFO ("populate_1(): session \"%s\", channel \"%s\"", AghD(), AghT());
+ APPLOG_INFO ("populate_1(): session \"%s\", channel \"%s\"", AghD(), AghT());
time_t earliest_start = (time_t)-1,
latest_end = (time_t)-1;
@@ -444,16 +444,12 @@ populate_1()
tl_width = (timeline_end - timeline_start) / 3600 * tl_pph;
tl_pages = (timeline_end - timeline_start) / ED->fft_params.pagesize;
- LOG_INFO ("populate_1(): common timeline:");
+ APPLOG_INFO ("populate_1(): common timeline:");
{
string t {asctime( localtime(&earliest_start))};
+ t += asctime( localtime(&latest_end));
t.pop_back();
- LOG_INFO (t.c_str());
- }
- {
- string t {asctime( localtime(&latest_end))};
- t.pop_back();
- LOG_INFO (t.c_str());
+ APPLOG_INFO (t.c_str());
}
tl_left_margin = tl_right_margin = 0;
diff --git a/upstream/src/common/libcommon.cc b/upstream/src/common/libcommon.cc
index c11719a..44acb56 100644
--- a/upstream/src/common/libcommon.cc
+++ b/upstream/src/common/libcommon.cc
@@ -378,6 +378,7 @@ sensible_scale_reduction_factor( double display_scale,
}
+
// Local Variables:
// Mode: c++
// indent-tabs-mode: 8
diff --git a/upstream/src/common/log-facility.cc b/upstream/src/common/log-facility.cc
index 0339e19..f9fa6f6 100644
--- a/upstream/src/common/log-facility.cc
+++ b/upstream/src/common/log-facility.cc
@@ -15,6 +15,7 @@
#include <cmath>
#include <stdexcept>
#include <gsl/gsl_math.h>
+#include "lang.hh"
#include "string.hh"
#if HAVE_CONFIG_H && !defined(VERSION)
@@ -74,6 +75,9 @@ void
CLogFacility::
msg( TLevel this_level, const char *issuer, const char* fmt, ...)
{
+ if ( level < this_level && this_level != TLevel::self )
+ return;
+
va_list ap;
va_start (ap, fmt);
vmsg( this_level, issuer, fmt, ap);
@@ -85,7 +89,7 @@ void
CLogFacility::
vmsg( TLevel this_level, const char *issuer, const char* fmt, va_list ap)
{
- if ( level > this_level && this_level != TLevel::self )
+ if ( level < this_level && this_level != TLevel::self )
return;
char timestampbuf[32 + 8 + 3];
@@ -113,11 +117,11 @@ vmsg( TLevel this_level, const char *issuer, const char* fmt, va_list ap)
// -- but it's just ok, because it avoids confusion as to what exactly "above message" can refer to
char *line = strtok( &the_line[0], "\n");
string to_print;
- size_t mline = 0;
+ int mline = 0;
do {
if ( mline > 0 )
fprintf( _f,
- "%s %s %*zu %s\n",
+ "%s %s %+*d %s\n",
timestampbuf, level_s(this_level),
strlen(issuer), mline,
line);
@@ -134,6 +138,23 @@ vmsg( TLevel this_level, const char *issuer, const char* fmt, va_list ap)
_last_line = the_line;
}
+
+void
+agh::log::SLoggingClient::
+log( agh::log::TLevel level, const char* issuer, const char* fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ if (_log_facility) {
+ _log_facility->vmsg( level, issuer, fmt, ap);
+ } else {
+ printf( "%s %s ", agh::log::level_s(level), issuer);
+ vprintf( fmt, ap);
+ printf( "\n");
+ }
+}
+
+
// Local Variables:
// Mode: c++
// indent-tabs-mode: nil
diff --git a/upstream/src/common/log-facility.hh b/upstream/src/common/log-facility.hh
index 4188453..07f9efd 100644
--- a/upstream/src/common/log-facility.hh
+++ b/upstream/src/common/log-facility.hh
@@ -54,7 +54,22 @@ class CLogFacility {
size_t _repeating_last;
};
-#define LOGHERE()
+
+struct SLoggingClient {
+ agh::log::CLogFacility*
+ _log_facility;
+ SLoggingClient (agh::log::CLogFacility* log_facility_ = nullptr)
+ : _log_facility (log_facility_)
+ {}
+ void log( agh::log::TLevel, const char* issuer, const char* fmt, ...) __attribute__ ((format (printf, 4, 5)));
+};
+
+#define LOG_SOURCE_ISSUER agh::str::sasprintf("%s:%zu:", __FILE__, __LINE__).c_str()
+
+#define LOG_DEBUG(...) do this->log( agh::log::TLevel::debug, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
+#define LOG_INFO(...) do this->log( agh::log::TLevel::info, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
+#define LOG_WARN(...) do this->log( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
+#define LOG_ERROR(...) do this->log( agh::log::TLevel::error, LOG_SOURCE_ISSUER, __VA_ARGS__); while (0)
}} // namespace agh::log
diff --git a/upstream/src/libsigfile/edf-io.cc b/upstream/src/libsigfile/edf-io.cc
index 1d98909..8ff8be3 100644
--- a/upstream/src/libsigfile/edf-io.cc
+++ b/upstream/src/libsigfile/edf-io.cc
@@ -76,8 +76,8 @@ put_region_smpl( const int h,
if ( unlikely (offset >= samplerate(h) * recording_time()) )
throw range_error("CEDFFile::put_region_(): offset beyond end of file");
if ( unlikely (offset + src.size() > samplerate(h) * recording_time()) ) {
- fprintf( stderr, "CEDFFile::put_region_(): attempt to write past end of file (%zu + %zu > %zu * %g)\n",
- offset, src.size(), samplerate(h), recording_time());
+ LOG_ERROR ("CEDFFile::put_region_(): attempt to write past end of file (%zu + %zu > %zu * %g)",
+ offset, src.size(), samplerate(h), recording_time());
throw range_error("CEDFFile::put_region_(): attempt to write past end of file");
}
diff --git a/upstream/src/libsigfile/edf.cc b/upstream/src/libsigfile/edf.cc
index 1114d2a..a198596 100644
--- a/upstream/src/libsigfile/edf.cc
+++ b/upstream/src/libsigfile/edf.cc
@@ -77,7 +77,7 @@ int
CEDFFile::
set_reserved( const string& s)
{
- fprintf( stderr, "You just voided your warranty: Writing to \"reserved\" field in EDF header:\n%s\n", s.c_str());
+ LOG_ERROR ("You just voided your warranty: Writing this to \"reserved\" field in EDF header: %s", s.c_str());
_recording_id = s;
memcpy( header.reserved, pad( s, 44).c_str(), 44);
return s.size() > 44;
@@ -118,8 +118,8 @@ const char version_string[8] = {'0',' ',' ',' ', ' ',' ',' ',' '};
CEDFFile::
-CEDFFile (const string& fname_, const int flags_)
- : CSource (fname_, flags_)
+CEDFFile (const string& fname_, const int flags_, agh::log::CLogFacility* log_facility_)
+ : CSource (fname_, flags_, log_facility_)
{
{
struct stat stat0;
@@ -150,7 +150,7 @@ CEDFFile (const string& fname_, const int flags_)
munmap( _mmapping, _fsize);
throw invalid_argument (explain_status(_status));
} else
- fprintf( stderr, "CEDFFile::CEDFFile(\"%s\") Warning: parse header failed, but proceeding anyway\n", fname_.c_str());
+ LOG_WARN ("CEDFFile(\"%s\") parse header failed, but proceeding anyway", fname_.c_str());
}
// channels now available
@@ -158,19 +158,19 @@ CEDFFile (const string& fname_, const int flags_)
// lest we ever access past mmapped region
{
- size_t total_samples_per_record = 0;
+ size_t total_samples_per_record = 0;
for ( auto& H : channels )
total_samples_per_record += H.samples_per_record;
- size_t expected_fsize = header_length + sizeof(int16_t) * total_samples_per_record * n_data_records;
+ size_t expected_fsize = header_length + sizeof(int16_t) * total_samples_per_record * n_data_records;
if ( _fsize < expected_fsize ) {
- fprintf( stderr, "CEDFFile::CEDFFile(\"%s\") file size less than declared in header\n", fname_.c_str());
+ LOG_WARN ("CEDFFile(\"%s\") file size less than declared in header", fname_.c_str());
close( _fd);
munmap( _mmapping, _fsize);
_status |= file_truncated;
throw invalid_argument (explain_status(_status));
} else if ( _fsize > expected_fsize ) {
_status |= trailing_junk;
- fprintf( stderr, "CEDFFile::CEDFFile(\"%s\") Warning: %zu bytes of trailing junk\n",
+ LOG_WARN ("CEDFFile(\"%s\") Warning: %zu bytes of trailing junk",
fname_.c_str(), _fsize - expected_fsize);
}
}
@@ -188,8 +188,9 @@ CEDFFile::
CEDFFile (const string& fname_, const TSubtype subtype_, const int flags_,
const list<pair<SChannel, size_t>>& channels_,
const size_t data_record_size_,
- const size_t n_data_records_)
- : CSource (fname_, flags_),
+ const size_t n_data_records_,
+ agh::log::CLogFacility* log_facility_)
+ : CSource (fname_, flags_, log_facility_),
data_record_size (data_record_size_),
n_data_records (n_data_records_),
_subtype (subtype_)
@@ -410,16 +411,16 @@ _lay_out_header()
#define FOR(A, C) \
for ( h = 0, H = channels.begin(); H != channels.end(); ++h, ++H, p += C ) H->A = p;
- FOR (header.label, 16);
- FOR (header.transducer_type, 80);
- FOR (header.physical_dim, 8);
- FOR (header.physical_min, 8);
- FOR (header.physical_max, 8);
- FOR (header.digital_min, 8);
- FOR (header.digital_max, 8);
- FOR (header.filtering_info, 80);
- FOR (header.samples_per_record, 8);
- FOR (header.reserved, 32);
+ FOR (header.label, 16);
+ FOR (header.transducer_type, 80);
+ FOR (header.physical_dim, 8);
+ FOR (header.physical_min, 8);
+ FOR (header.physical_max, 8);
+ FOR (header.digital_min, 8);
+ FOR (header.digital_max, 8);
+ FOR (header.filtering_info, 80);
+ FOR (header.samples_per_record, 8);
+ FOR (header.reserved, 32);
#undef FOR
}
diff --git a/upstream/src/libsigfile/edf.hh b/upstream/src/libsigfile/edf.hh
index bca5ed9..d48fd10 100644
--- a/upstream/src/libsigfile/edf.hh
+++ b/upstream/src/libsigfile/edf.hh
@@ -69,21 +69,21 @@ class CEDFFile
// ctor
CEDFFile( const CEDFFile&)
- : CSource("")
- {
- throw invalid_argument("nono");
- }
+ : CSource("", 0, nullptr)
+ { throw invalid_argument("nono"); }
+
enum TFlags {
no_mmap = 1<<3,
no_cache = 1<<4, // just considering
};
// open existing
- CEDFFile (const string& fname, int flags = 0);
+ CEDFFile (const string& fname, int flags, agh::log::CLogFacility*);
// create new
CEDFFile (const string& fname, TSubtype, int flags,
const list<pair<SChannel, size_t>>&,
- size_t data_record_size = 1,
- size_t n_data_records = 0);
+ size_t data_record_size,
+ size_t n_data_records,
+ agh::log::CLogFacility*);
CEDFFile (CEDFFile&&);
// dtor
~CEDFFile ();
diff --git a/upstream/src/libsigfile/page.cc b/upstream/src/libsigfile/page.cc
index 66f8afc..991e21e 100644
--- a/upstream/src/libsigfile/page.cc
+++ b/upstream/src/libsigfile/page.cc
@@ -18,6 +18,7 @@
#include <functional>
#include <initializer_list>
#include <algorithm>
+#include "source-base.hh"
#include "page.hh"
using namespace std;
@@ -92,8 +93,8 @@ load( const string& fname)
return CHypnogram::TError::baddata;
if ( saved_pagesize != _pagesize ) {
- fprintf( stderr, "CHypnogram::load(\"%s\"): read pagesize (%zu) different from that specified at construct (%zu)\n",
- fname.c_str(), saved_pagesize, _pagesize);
+ LOG_WARN ("CHypnogram::load(\"%s\"): read pagesize (%zu) different from that specified at construct (%zu)",
+ fname.c_str(), saved_pagesize, _pagesize);
_pagesize = saved_pagesize;
return CHypnogram::TError::wrongpagesize;
}
diff --git a/upstream/src/libsigfile/page.hh b/upstream/src/libsigfile/page.hh
index 4f1ae9c..2ca4aa4 100644
--- a/upstream/src/libsigfile/page.hh
+++ b/upstream/src/libsigfile/page.hh
@@ -10,14 +10,15 @@
*/
-#ifndef SIGFILE_PAGE_H_
-#define SIGFILE_PAGE_H_
+#ifndef AGH_SIGFILE_PAGE_H_
+#define AGH_SIGFILE_PAGE_H_
#include <vector>
#include <array>
#include <stdexcept>
#include "common/lang.hh"
+#include "common/log-facility.hh"
#if HAVE_CONFIG_H && !defined(VERSION)
# include <config.h>
@@ -172,21 +173,25 @@ struct SPageSimulated : public SPageWithMetric {
-class CHypnogram {
+class CHypnogram
+ : public agh::log::SLoggingClient {
protected:
size_t _pagesize;
vector<SPage>
_pages;
+
public:
CHypnogram() = delete;
- CHypnogram( size_t psize)
- : _pagesize (psize)
+ CHypnogram( size_t pagesize_, agh::log::CLogFacility* log_facility_ = nullptr)
+ : SLoggingClient (log_facility_),
+ _pagesize (pagesize_)
{}
CHypnogram( CHypnogram&& rv)
{
_pagesize = rv._pagesize;
+ _log_facility = rv._log_facility;
swap( _pages, rv._pages);
}
diff --git a/upstream/src/libsigfile/source-base.cc b/upstream/src/libsigfile/source-base.cc
index f2134fd..10d4b82 100644
--- a/upstream/src/libsigfile/source-base.cc
+++ b/upstream/src/libsigfile/source-base.cc
@@ -9,7 +9,7 @@
* License: GPL
*/
-
+#include <cstdarg>
#include <fstream>
#include "common/string.hh"
#include "libsigproc/sigproc.hh"
@@ -37,6 +37,24 @@ is_fname_ext_supported( const string& fname)
+
+
+sigfile::CSource::
+CSource (CSource&& rv)
+ : SLoggingClient (move(rv)),
+ _subject (move(rv._subject))
+{
+ swap( _filename, rv._filename);
+ _status = rv._status;
+ _flags = rv._flags;
+ SLoggingClient::_log_facility = rv._log_facility;
+
+ _start_time = rv._start_time;
+ _end_time = rv._end_time;
+}
+
+
+
void
SArtifacts::
mark_artifact( const double aa, const double az)
@@ -281,20 +299,6 @@ save_ancillary_files()
-sigfile::CSource::
-CSource (CSource&& rv)
- : _subject (move(rv._subject))
-{
- swap( _filename, rv._filename);
- _status = rv._status;
- _flags = rv._flags;
-
- _start_time = rv._start_time;
- _end_time = rv._end_time;
-}
-
-
-
int
CSource::
@@ -558,6 +562,8 @@ explain_status( const int status)
}
+
+
// Local Variables:
// Mode: c++
// indent-tabs-mode: nil
diff --git a/upstream/src/libsigfile/source-base.hh b/upstream/src/libsigfile/source-base.hh
index 34e688b..3de382a 100644
--- a/upstream/src/libsigfile/source-base.hh
+++ b/upstream/src/libsigfile/source-base.hh
@@ -9,13 +9,14 @@
* License: GPL
*/
-#ifndef _SIGFILE_SOURCE_BASE_H
-#define _SIGFILE_SOURCE_BASE_H
+#ifndef AGH_SIGFILE_SOURCE_BASE_H_
+#define AGH_SIGFILE_SOURCE_BASE_H_
#include <tuple>
-#include "common/fs.hh"
#include "common/alg.hh"
+#include "common/fs.hh"
+#include "common/log-facility.hh"
#include "common/subject_id.hh"
#include "libsigproc/winfun.hh"
#include "channel.hh"
@@ -224,7 +225,8 @@ struct SFilterPack {
-class CSource {
+class CSource
+ : public agh::log::SLoggingClient {
friend class CTypedSource;
public:
enum TFlags {
@@ -260,8 +262,9 @@ class CSource {
public:
DELETE_DEFAULT_METHODS (CSource);
- CSource (const string& fname_, int flags_ = 0)
- : _filename (fname_),
+ CSource (const string& fname_, int flags_, agh::log::CLogFacility* log_facility_)
+ : SLoggingClient (log_facility_),
+ _filename (fname_),
_status (0),
_flags (flags_)
{
diff --git a/upstream/src/libsigfile/tsv.cc b/upstream/src/libsigfile/tsv.cc
index bb4bafd..b87c86f 100644
--- a/upstream/src/libsigfile/tsv.cc
+++ b/upstream/src/libsigfile/tsv.cc
@@ -14,6 +14,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <regex.h>
+#include <errno.h>
#include <sstream>
#include <list>
#include <stdexcept>
@@ -37,8 +38,8 @@ using sigfile::CTSVFile;
CTSVFile::
-CTSVFile (const string& fname_, const int flags_)
- : CSource (fname_, flags_)
+CTSVFile (const string& fname_, const int flags_, agh::log::CLogFacility* log_facility_)
+ : CSource (fname_, flags_, log_facility_)
{
{
struct stat stat0;
@@ -60,7 +61,7 @@ CTSVFile (const string& fname_, const int flags_)
if ( not (flags_ & sigfile::CSource::no_field_consistency_check) ) {
throw invalid_argument (explain_status(_status)); // _status set in _parse_header()
} else
- fprintf( stderr, "CTSVFile::CTSVFile(\"%s\") Warning: parse header failed, but proceeding anyway\n", fname_.c_str());
+ LOG_WARN ("CTSVFile(\"%s\"): parse header failed, but proceeding anyway", fname_.c_str());
}
// channels now available
@@ -78,15 +79,17 @@ CTSVFile::
CTSVFile (const string& fname_, const TSubtype subtype_, const int flags_,
const list<SChannel>& channels_,
const size_t samplerate_,
- const double recording_time_)
- : CSource (fname_, flags_),
+ const double recording_time_,
+ agh::log::CLogFacility* log_facility_)
+ : CSource (fname_, flags_, log_facility_),
_subtype (subtype_),
_samplerate (samplerate_),
_line0 (nullptr)
{
_f = fopen( fname_.c_str(), "r");
if ( !_f ) {
- fprintf( stderr, "CTSVFile::CTSVFile(\"%s\"): Failed to open file for writing\n", fname_.c_str());
+ LOG_ERROR ("CTSVFile(\"%s\"): Failed to open file for writing: %s",
+ fname_.c_str(), strerror(errno));
throw invalid_argument (explain_status(_status |= CSource::TStatus::sysfail));
}
@@ -184,13 +187,13 @@ _parse_header()
// 2. pick essential bits
if ( metadata.find( "recording_id") == metadata.end() ) {
- fprintf( stderr, "No session/episode in header\n");
+ LOG_WARN ("\"%s\": No session/episode in header", _filename.c_str());
_status |= bad_session_or_episode;
return -1;
}
if ( metadata.find( "patient_id") == metadata.end() ) {
- fprintf( stderr, "No patient_id in header\n");
+ LOG_WARN ("\"%s\": No patient_id in header", _filename.c_str());
_status |= CSource::missing_patient_id;;
return -1;
}
@@ -199,7 +202,7 @@ _parse_header()
if ( metadata.find( "recording_date") == metadata.end() ||
metadata.find( "recording_time") == metadata.end() ) {
- fprintf( stderr, "No recording_date in header\n");
+ LOG_WARN ("\"%s\": No recording_date in header", _filename.c_str());
_status |= CSource::bad_datetime;
return -1;
}
@@ -216,13 +219,13 @@ _parse_header()
if ( metadata.find( "samplerate") == metadata.end() ||
(_samplerate = stoi( metadata["samplerate"])) > 2048 ) {
- fprintf( stderr, "Samplerate missing or too high in header\n");
+ LOG_WARN ("\"%s\": Samplerate missing or too high in header", _filename.c_str());
_status |= bad_header;
return -1;
}
if ( metadata.find( "channels") == metadata.end() ) {
- fprintf( stderr, "No channels in header\n");
+ LOG_ERROR ("\"%s\": No channels in header", _filename.c_str());
_status |= bad_header;
return -1;
}
@@ -242,10 +245,9 @@ _parse_header()
}
}
outer_break:
-
// 4. sample one line of channel data
if ( agh::str::tokens( _line0, "\t;, ").size() != channels.size() ) {
- fprintf( stderr, "Number of channels declared in header (%zu) different from number of columns of data\n", channels.size());
+ LOG_ERROR ("\"%s\": Number of channels declared in header (%zu) different from number of columns of data", _filename.c_str(), channels.size());
_status |= bad_channel_count;
return -1;
}
@@ -269,12 +271,12 @@ _read_data()
do {
double ts;
if ( 1 != sscanf( _line0, "%lg%*[,\t]", &ts) ) {
- fprintf( stderr, "Bad offset (at data line %zu)\n", ll);
+ LOG_ERROR ("\"%s\": Bad offset (at data line %zu)", _filename.c_str(), ll);
_status |= bad_offset;
return -1;
}
if ( ll > 0 && ts * _samplerate <= offsets.back() ) {
- fprintf( stderr, "Offsets not increasing (at data line %zu)\n", ll);
+ LOG_ERROR ("\"%s\": Offsets not increasing (at data line %zu)\n", _filename.c_str(), ll);
_status |= offsets_not_incteasing;
return -1;
}
@@ -292,7 +294,7 @@ _read_data()
outer_break1:
if ( r != 0 && r != channels.size() ) {
- fprintf( stderr, "Number of data read (%zu) not a multiple of channel count (%zu)\n", r, channels.size());
+ LOG_ERROR ("\"%s\": Number of data read (%zu) not a multiple of channel count (%zu)\n", _filename.c_str(), r, channels.size());
_status |= bad_channel_count;
return -1;
}
@@ -323,7 +325,7 @@ _read_data()
outer_break2:
if ( r != 0 && r != channels.size() ) {
- fprintf( stderr, "Number of data read (%zu) not a multiple of channel count (%zu)\n", r, channels.size());
+ LOG_ERROR ("\"%s\": Number of data read (%zu) not a multiple of channel count (%zu)", _filename.c_str(), r, channels.size());
_status |= bad_channel_count;
return -1;
}
diff --git a/upstream/src/libsigfile/tsv.hh b/upstream/src/libsigfile/tsv.hh
index 9a58805..87aa0da 100644
--- a/upstream/src/libsigfile/tsv.hh
+++ b/upstream/src/libsigfile/tsv.hh
@@ -67,17 +67,16 @@ class CTSVFile
// ctor
CTSVFile (const CTSVFile&)
- : CSource("")
- {
- throw invalid_argument("nono");
- }
+ : CSource("", 0, nullptr)
+ { throw invalid_argument("nono"); }
// open existing
- CTSVFile (const string& fname, int flags = 0);
+ CTSVFile (const string& fname, int flags, agh::log::CLogFacility*);
// create new
CTSVFile (const string& fname, TSubtype, int flags,
const list<SChannel>&,
const size_t samplerate_,
- const double recording_time_);
+ const double recording_time_,
+ agh::log::CLogFacility*);
CTSVFile (CTSVFile&&);
// dtor
~CTSVFile ();
diff --git a/upstream/src/libsigfile/typed-source.cc b/upstream/src/libsigfile/typed-source.cc
index 83f0ccb..e70f1cb 100644
--- a/upstream/src/libsigfile/typed-source.cc
+++ b/upstream/src/libsigfile/typed-source.cc
@@ -48,15 +48,16 @@ is_supported_source( CTypedSource& F)
CTypedSource::
CTypedSource (const string& fname,
const size_t pagesize,
- const int flags)
- : CHypnogram (pagesize)
+ const int flags,
+ agh::log::CLogFacility* log_facility)
+ : CHypnogram (pagesize, log_facility)
{
switch ( _type = source_file_type(fname) ) {
case TType::ascii:
- _obj = new CTSVFile( fname, flags);
+ _obj = new CTSVFile( fname, flags, log_facility);
break;
case TType::edf:
- _obj = new CEDFFile( fname, flags);
+ _obj = new CEDFFile( fname, flags, log_facility);
break;
case TType::bin:
@@ -70,10 +71,12 @@ CTypedSource (const string& fname,
CHypnogram::load( sigfile::make_fname_hypnogram(fname, pagesize));
size_t scorable_pages = ceil( _obj->recording_time() / pagesize);
if ( CHypnogram::n_pages() != scorable_pages ) {
- if ( CHypnogram::n_pages() > 0 )
- fprintf( stderr, "CSource(\"%s\"): number of scorable pages @pagesize=%zu (%g / %zu = %zu) "
- "differs from the number read from hypnogram file (%zu); adjusting hypnogram size\n",
- fname.c_str(), pagesize, _obj->recording_time(), pagesize, scorable_pages, CHypnogram::n_pages());
+ if ( CHypnogram::n_pages() > 0 && log_facility )
+ log_facility->msg(
+ agh::log::TLevel::warning, agh::str::sasprintf("%s:%zu", __FILE__, __LINE__).c_str(),
+ "CSource(\"%s\"): number of scorable pages @pagesize=%zu (%g / %zu = %zu) "
+ "differs from the number read from hypnogram file (%zu); adjusting hypnogram size",
+ fname.c_str(), pagesize, _obj->recording_time(), pagesize, scorable_pages, CHypnogram::n_pages());
CHypnogram::_pages.resize( scorable_pages);
}
}
diff --git a/upstream/src/libsigfile/typed-source.hh b/upstream/src/libsigfile/typed-source.hh
index 3e81f6e..a7701e9 100644
--- a/upstream/src/libsigfile/typed-source.hh
+++ b/upstream/src/libsigfile/typed-source.hh
@@ -9,9 +9,10 @@
* License: GPL
*/
-#ifndef AGH_SIGFILE_SOURCE_H_
-#define AGH_SIGFILE_SOURCE_H_
+#ifndef AGH_SIGFILE_TYPED_SOURCE_H_
+#define AGH_SIGFILE_TYPED_SOURCE_H_
+#include "common/log-facility.hh"
#include "source-base.hh"
#include "forward-decls.hh"
#include "page.hh"
@@ -33,24 +34,22 @@ class CTypedSource
void operator=( const CTypedSource&) = delete;
CTypedSource () = delete;
public:
- enum class TType : int {
+ enum class TType {
unrecognised,
bin, ascii,
edf,
};
private:
- TType _type; // rtti is evil
+ TType _type; // rtti is evil
CSource
*_obj;
public:
CTypedSource (const CTypedSource&)
: CHypnogram (-1)
- {
- throw invalid_argument("nono");
- }
+ { throw invalid_argument("nono"); }
// ctor
- CTypedSource (const string& fname, size_t pagesize, int flags = 0);
+ CTypedSource (const string& fname, size_t pagesize, int flags, agh::log::CLogFacility*);
CTypedSource (CTypedSource&& rv);
~CTypedSource ();
diff --git a/upstream/src/tools/agh-profile-gen.cc b/upstream/src/tools/agh-profile-gen.cc
index 1f83108..1c394d1 100644
--- a/upstream/src/tools/agh-profile-gen.cc
+++ b/upstream/src/tools/agh-profile-gen.cc
@@ -196,7 +196,7 @@ main( int argc, char **argv)
if ( A.file.empty() )
throw invalid_argument ("Missing file name");
- sigfile::CTypedSource F (A.file, A.pagesize, 0|sigfile::CSource::no_ancillary_files);
+ sigfile::CTypedSource F (A.file, A.pagesize, 0|sigfile::CSource::no_ancillary_files, nullptr);
if ( do_psd ) {
metrics::psd::CProfile P (F, A.h, A.psd_pp);
if ( P.go_compute() )
diff --git a/upstream/src/tools/edfcat.cc b/upstream/src/tools/edfcat.cc
index b85a29c..b6ca124 100644
--- a/upstream/src/tools/edfcat.cc
+++ b/upstream/src/tools/edfcat.cc
@@ -339,7 +339,8 @@ exec_convert( const SOperation::SObject& obj)
0|sigfile::CSource::no_ancillary_files,
make_channel_headers_for_CEDFFile( Hh.size(), "channel%zu", obj.samplerate),
obj.record_size,
- ceilf(duration / obj.record_size));
+ ceilf(duration / obj.record_size),
+ nullptr);
for ( size_t f = 0; f < Hh.size(); ++f ) {
F[f].set_physical_range( grand_min, grand_max);
F.put_signal( f, valarray<TFloat> {Hh[f][slice (0, total_samples, 1)]});
@@ -359,7 +360,7 @@ exec_convert( const SOperation::SObject& obj)
int
exec_prune( const SOperation::SObject& obj)
{
- sigfile::CEDFFile F (obj.c_str(), sigfile::CSource::no_ancillary_files);
+ sigfile::CEDFFile F (obj.c_str(), sigfile::CSource::no_ancillary_files, nullptr);
list<pair<sigfile::SChannel, size_t>> selected_channels;
for ( auto& select_this : obj.channels ) {
@@ -382,7 +383,8 @@ exec_prune( const SOperation::SObject& obj)
sigfile::CSource::no_ancillary_files,
selected_channels,
F.data_record_size,
- F.n_data_records);
+ F.n_data_records,
+ nullptr);
G.set_patient_id( F.patient_id());
string tmp = F.recording_id();
diff --git a/upstream/src/tools/edfhed-gtk.cc b/upstream/src/tools/edfhed-gtk.cc
index 1f6328f..c029635 100644
--- a/upstream/src/tools/edfhed-gtk.cc
+++ b/upstream/src/tools/edfhed-gtk.cc
@@ -145,7 +145,8 @@ main( int argc, char **argv)
auto F = sigfile::CEDFFile (
fname,
sigfile::CSource::no_ancillary_files |
- sigfile::CEDFFile::no_field_consistency_check);
+ sigfile::CEDFFile::no_field_consistency_check,
+ nullptr);
channel_no = 0;
Fp = &F;
diff --git a/upstream/src/tools/edfhed.cc b/upstream/src/tools/edfhed.cc
index 28e6099..357565e 100644
--- a/upstream/src/tools/edfhed.cc
+++ b/upstream/src/tools/edfhed.cc
@@ -329,7 +329,8 @@ main( int argc, char **argv)
auto F = sigfile::CEDFFile (
fname,
sigfile::CSource::no_ancillary_files |
- sigfile::CEDFFile::no_field_consistency_check);
+ sigfile::CEDFFile::no_field_consistency_check,
+ nullptr);
if ( Opts.settables.empty() &&
not Opts.from_timestamp && not Opts.from_tree && not Opts.to_timestamp ) {
cout << F.details(
--
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git
More information about the debian-med-commit
mailing list