From 5388e15c26d47322d2708008748b811af19c89a7 Mon Sep 17 00:00:00 2001 From: Konstantin LEONTEV Date: Fri, 7 Oct 2022 14:09:44 +0300 Subject: [PATCH] dynamic_log_messages: Added initial libSALOMELog files. --- src/SALOMELocalTrace/libSALOMELog.cxx | 70 +++++++++++++++++++++++++++ src/SALOMELocalTrace/libSALOMELog.hxx | 37 ++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/SALOMELocalTrace/libSALOMELog.cxx create mode 100644 src/SALOMELocalTrace/libSALOMELog.hxx diff --git a/src/SALOMELocalTrace/libSALOMELog.cxx b/src/SALOMELocalTrace/libSALOMELog.cxx new file mode 100644 index 000000000..05bc4848b --- /dev/null +++ b/src/SALOMELocalTrace/libSALOMELog.cxx @@ -0,0 +1,70 @@ +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// Author : Konstantin Leontev (OpenCascade) +// Module : KERNEL +// $Header$ +// Cf. C++ Users Journal, June 2004, Tracing Application Execution, Tomer Abramson +// + +#include + +namespace SALOME +{ + +// ============================================================================ +/*! + * Called by any log message macros to decide about log output in Release and + * Debug mode dynamically rely on SALOME_VERBOSE environment variable. + * Checks SALOME_VERBOSE only on the very first call and returns cached result + * for all followed calls. + * Returns true if SALOME_VERBOSE is positioned and not empty and if its + * numeric value greater than 0. + */ +// ============================================================================ + + bool VerbosityActivated() + { + auto isEnvVarSet = []() -> bool + { + const char* envVar = std::getenv("SALOME_VERBOSE"); + + if (envVar && (envVar[0] != '\0')) + { + try + { + const long long numValue = std::stoll(envVar); + return numValue > 0; + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + } + + return false; + }; + + static const bool isActivated = isEnvVarSet(); + return isActivated; + } +} diff --git a/src/SALOMELocalTrace/libSALOMELog.hxx b/src/SALOMELocalTrace/libSALOMELog.hxx new file mode 100644 index 000000000..f5d5dc671 --- /dev/null +++ b/src/SALOMELocalTrace/libSALOMELog.hxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : libSALOMELog.hxx +// Author : Konstantin Leontev (OpenCascade) +// Module : KERNEL +// $Header$ +// +#ifndef _LIBSALOMELOG_HXX_ +#define _LIBSALOMELOG_HXX_ + + +namespace SALOME +{ + bool VerbosityActivated(); +} + +#endif -- 2.39.2