From 12c44cf5a34a2b574a5d289ce7b60b012a61d393 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 8 Sep 2023 17:13:15 +0200 Subject: [PATCH] [EDF27562] : Switch on/off log programmaticaly --- src/Basics/KernelBasis.i | 6 ++++++ src/Basics/libSALOMELog.cxx | 20 +++++++++++++++----- src/Basics/libSALOMELog.hxx | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Basics/KernelBasis.i b/src/Basics/KernelBasis.i index 7bbcf28d3..b159904c2 100644 --- a/src/Basics/KernelBasis.i +++ b/src/Basics/KernelBasis.i @@ -22,6 +22,7 @@ %{ #include "KernelBasis.hxx" #include "HeatMarcel.hxx" +#include "libSALOMELog.hxx" using namespace SALOME; %} @@ -40,6 +41,11 @@ void setIOROfEmbeddedNS(const std::string& ior); double GetTimeAdjustmentCst(); +bool VerbosityActivated(); + +void SetVerbosityActivated(bool flag); + + %inline { PyObject *HeatMarcelSwig(double timeAjustment, unsigned int nbThreads = 0) diff --git a/src/Basics/libSALOMELog.cxx b/src/Basics/libSALOMELog.cxx index fe0beeb2a..b1d1332e6 100644 --- a/src/Basics/libSALOMELog.cxx +++ b/src/Basics/libSALOMELog.cxx @@ -27,6 +27,10 @@ #include #include +enum class VerbosityMode { undefined, nolog, withlog }; + +static VerbosityMode isActivated = VerbosityMode::undefined; + namespace SALOME { @@ -43,7 +47,7 @@ namespace SALOME bool VerbosityActivated() { - auto isEnvVarSet = []() -> bool + auto isEnvVarSet = []() -> VerbosityMode { const char* envVar = std::getenv("SALOME_VERBOSE"); @@ -52,7 +56,7 @@ namespace SALOME try { const long long numValue = std::stoll(envVar); - return numValue > 0; + return numValue > 0?VerbosityMode::withlog:VerbosityMode::nolog; } catch(const std::exception& e) { @@ -60,10 +64,16 @@ namespace SALOME } } - return false; + return VerbosityMode::nolog; }; - static const bool isActivated = isEnvVarSet(); - return isActivated; + if(isActivated == VerbosityMode::undefined) + isActivated = isEnvVarSet(); + return isActivated == VerbosityMode::withlog; + } + + void SetVerbosityActivated(bool flag) + { + isActivated = flag ? VerbosityMode::withlog:VerbosityMode::nolog; } } diff --git a/src/Basics/libSALOMELog.hxx b/src/Basics/libSALOMELog.hxx index 93949515b..7d4b70611 100644 --- a/src/Basics/libSALOMELog.hxx +++ b/src/Basics/libSALOMELog.hxx @@ -29,4 +29,5 @@ namespace SALOME { bool BASICS_EXPORT VerbosityActivated(); + void BASICS_EXPORT SetVerbosityActivated(bool); } -- 2.39.2