summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-01-16 11:12:56 +0100
committerAnton Khirnov <anton@khirnov.net>2019-01-16 11:13:50 +0100
commit37acb9a97cd3ff034f529b78739f93707877855c (patch)
tree29c49ec9de3ffbdd0de742fc3bcb00ae720d701f
parentd605be98a5ce957ed36a17182caec20e32132326 (diff)
mg2d: add a context variable to control the log level
Simpler to use than overriding the log callback. API bump.
-rw-r--r--libmg2d.v2
-rw-r--r--mg2d.c3
-rw-r--r--mg2d.h10
-rw-r--r--mg2d_test.c1
4 files changed, 14 insertions, 2 deletions
diff --git a/libmg2d.v b/libmg2d.v
index ec37512..96151a5 100644
--- a/libmg2d.v
+++ b/libmg2d.v
@@ -1,4 +1,4 @@
-LIBMG2D_4 {
+LIBMG2D_5 {
global: mg2d_*;
local: *;
};
diff --git a/mg2d.c b/mg2d.c
index 6b94def..886ef27 100644
--- a/mg2d.c
+++ b/mg2d.c
@@ -570,6 +570,8 @@ static int mg_levels_alloc(MG2DContext *ctx, size_t domain_size)
static void log_default_callback(const MG2DContext *ctx, int level, const char *fmt, va_list vl)
{
+ if (level > ctx->log_level)
+ return;
vfprintf(stderr, fmt, vl);
}
@@ -623,6 +625,7 @@ MG2DContext *mg2d_solver_alloc(size_t domain_size)
ctx->nb_relax_pre = 1;
ctx->nb_relax_post = 1;
ctx->log_callback = log_default_callback;
+ ctx->log_level = MG2D_LOG_INFO;
ctx->nb_threads = 1;
ctx->u = priv->root->solver->u;
diff --git a/mg2d.h b/mg2d.h
index 834e717..a587a18 100644
--- a/mg2d.h
+++ b/mg2d.h
@@ -168,7 +168,9 @@ typedef struct MG2DContext {
/**
* A callback that will be used to print diagnostic messages.
*
- * Defaults to fprintf(stderr, ...)
+ * The default implementation prints to stderr.
+ *
+ * May be set to NULL to disable logging.
*/
void (*log_callback)(const struct MG2DContext *ctx, int level,
const char *fmt, va_list);
@@ -272,6 +274,12 @@ typedef struct MG2DContext {
* Time-stepping factor to use for relaxation.
*/
double cfl_factor;
+
+ /**
+ * Maximum level of messages printed by the default logging callback. Has no
+ * effect when log_callback is overridden.
+ */
+ enum MG2DLogLevel log_level;
} MG2DContext;
/**
diff --git a/mg2d_test.c b/mg2d_test.c
index 9b55963..c04e824 100644
--- a/mg2d_test.c
+++ b/mg2d_test.c
@@ -69,6 +69,7 @@ int main(int argc, char **argv)
ctx->nb_relax_post = 2;
ctx->tol = TOL;
ctx->nb_threads = 1;
+ ctx->log_level = MG2D_LOG_VERBOSE;
{
MG2DBoundary *bnd = ctx->boundaries[MG2D_BOUNDARY_0L];