1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Author : Konstantin Leontev (OpenCascade)
25 #include "libSALOMELog.hxx"
30 enum class VerbosityMode { undefined, nolog, withlog };
32 static VerbosityMode isActivated = VerbosityMode::undefined;
37 // ============================================================================
39 * Called by any log message macros to decide about log output in Release and
40 * Debug mode dynamically rely on SALOME_VERBOSE environment variable.
41 * Checks SALOME_VERBOSE only on the very first call and returns cached result
42 * for all followed calls.
43 * Returns true if SALOME_VERBOSE is positioned and not empty and if its
44 * numeric value greater than 0.
46 // ============================================================================
48 bool VerbosityActivated()
50 auto isEnvVarSet = []() -> VerbosityMode
52 const char* envVar = std::getenv("SALOME_VERBOSE");
54 if (envVar && (envVar[0] != '\0'))
58 const long long numValue = std::stoll(envVar);
59 return numValue > 0?VerbosityMode::withlog:VerbosityMode::nolog;
61 catch(const std::exception& e)
63 std::cerr << e.what() << '\n';
67 return VerbosityMode::nolog;
70 if(isActivated == VerbosityMode::undefined)
71 isActivated = isEnvVarSet();
72 return isActivated == VerbosityMode::withlog;
75 void SetVerbosityActivated(bool flag)
77 isActivated = flag ? VerbosityMode::withlog:VerbosityMode::nolog;