Salome HOME
[EDF27562] : 2 new methods to simulate computation to ease test in charge YACS
[modules/kernel.git] / src / Basics / libSALOMELog.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  Author : Konstantin Leontev (OpenCascade)
21 //  Module : KERNEL
22 //  $Header$
23 //
24
25 #include "libSALOMELog.hxx"
26
27 #include <string>
28 #include <iostream>
29
30 namespace SALOME
31 {
32
33 // ============================================================================
34 /*!
35  *  Called by any log message macros to decide about log output in Release and
36  *  Debug mode dynamically rely on SALOME_VERBOSE environment variable.
37  *  Checks SALOME_VERBOSE only on the very first call and returns cached result
38  *  for all followed calls.
39  *  Returns true if SALOME_VERBOSE is positioned and not empty and if its
40  *  numeric value greater than 0.
41  */
42 // ============================================================================
43
44   bool VerbosityActivated()
45   {
46     auto isEnvVarSet = []() -> bool
47     {
48       const char* envVar = std::getenv("SALOME_VERBOSE");
49
50       if (envVar && (envVar[0] != '\0'))
51       {
52         try
53         {
54           const long long numValue = std::stoll(envVar);
55           return numValue > 0;
56         }
57         catch(const std::exception& e)
58         {
59           std::cerr << e.what() << '\n';
60         }
61       }
62
63       return false;
64     };
65
66     static const bool isActivated = isEnvVarSet();
67     return isActivated;
68   }
69 }