From: Anthony Geay Date: Fri, 8 Sep 2023 15:13:15 +0000 (+0200) Subject: [EDF27562] : Switch on/off log programmaticaly X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=12c44cf5a34a2b574a5d289ce7b60b012a61d393;p=modules%2Fkernel.git [EDF27562] : Switch on/off log programmaticaly --- 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); }