From 0561d6439b0cb9b0b389223e8ebea5a354a5e6c8 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 22 Dec 2023 13:35:34 +0100 Subject: [PATCH] [EDF29150] : Forward verbosity to Container. Ease access to logfile --- bin/runSalomeCommon.py | 10 ++++-- idl/SALOME_Component.idl | 5 +++ src/Container/Container_i.cxx | 37 ++++++++++++++++++++++- src/Container/Container_init_python.cxx | 5 +-- src/Container/SALOME_Container.py | 6 ++++ src/Container/SALOME_ContainerManager.cxx | 8 +++-- src/Container/SALOME_Container_i.hxx | 9 ++++-- src/Container/SALOME_PyNode.py | 3 +- 8 files changed, 71 insertions(+), 12 deletions(-) diff --git a/bin/runSalomeCommon.py b/bin/runSalomeCommon.py index 841f62a65..632c7e03b 100755 --- a/bin/runSalomeCommon.py +++ b/bin/runSalomeCommon.py @@ -63,10 +63,12 @@ class BackTraceFormatter(logging.Formatter): def format(self, record): import inspect frame = inspect.currentframe() - # go upward of the stack to catch the effective callsite. Not very steady.... + # go upward with ( a limit of 10 steps ) of the stack to catch the effective callsite. Not very steady.... # should be replaced by an analysis of frame.f_code - for i in range(8): + for i in range(10): frame = frame.f_back + if inspect.getsourcefile(frame) != logging.__file__: + break record.msg = "{} ( callsite is {} of file \"{}\" at line {} )".format(record.msg, frame.f_code.co_name,inspect.getsourcefile(frame),inspect.getlineno(frame) ) return logging.Formatter.format(self, record) @@ -90,6 +92,10 @@ def setVerbose(verbose): if verbose in verbose_map: logger.setLevel(verbose_map[verbose]) +def positionVerbosityOfLogger(): + import KernelBasis + setVerbose( {False:"0",True:"2"}[KernelBasis.VerbosityActivated()] ) + # ----------------------------------------------------------------------------- # # Class definitions to launch CORBA Servers diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 2e3b662f4..7c3b0283b 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -178,6 +178,11 @@ module Engines //! name of the %container log file (this has been set by the launcher) attribute string logfilename ; + + //! name of the %container log file + attribute string locallogfilename ; + + attribute long verboselevel; //! Shutdown the Container process. void Shutdown(); diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index dd8ea1843..d43b269b8 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -305,7 +305,7 @@ char* Abstract_Engines_Container_i::workingdir() */ //============================================================================= -char* Abstract_Engines_Container_i::logfilename() +char *Abstract_Engines_Container_i::logfilename() { return CORBA::string_dup(_logfilename.c_str()) ; } @@ -316,6 +316,41 @@ void Abstract_Engines_Container_i::logfilename(const char* name) _logfilename=name; } +char *Abstract_Engines_Container_i::locallogfilename() +{ + return CORBA::string_dup( _localfilename.c_str() ); +} + +void Abstract_Engines_Container_i::locallogfilename(const char *name) +{ + _localfilename = name; +} + +void Abstract_Engines_Container_i::verboselevel(CORBA::Long vl) +{ + SALOME::SetVerbosityActivated( vl ); + if( SALOME::VerbosityActivated() ) + { + AutoGIL gstate; + PyObject *res = PyObject_CallMethod(_pyCont, + (char*)"propageVerbosityToLogging",NULL); + if(res==NULL) + { + //internal error + PyErr_Print(); + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "can not create a python node"; + throw SALOME::SALOME_Exception(es); + } + } +} + +CORBA::Long Abstract_Engines_Container_i::verboselevel() +{ + return (CORBA::Long)SALOME::VerbosityActivated(); +} + //============================================================================= //! Get container host name /*! diff --git a/src/Container/Container_init_python.cxx b/src/Container/Container_init_python.cxx index 93f54ac04..b3ba17777 100644 --- a/src/Container/Container_init_python.cxx +++ b/src/Container/Container_init_python.cxx @@ -165,9 +165,6 @@ void KERNEL_PYTHON::init_python(int argc, char **argv) MESSAGE("Python already initialized"); return; } - MESSAGE("================================================================="); - MESSAGE("Python Initialization..."); - MESSAGE("================================================================="); // set stdout to line buffering (aka C++ std::cout) setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); char* env_python=getenv("SALOME_PYTHON"); @@ -179,7 +176,7 @@ void KERNEL_PYTHON::init_python(int argc, char **argv) Py_Initialize(); // Initialize the interpreter if (Py_IsInitialized()) { - MESSAGE("Python initialized eh eh eh"); + MESSAGE("Python initialized"); } wchar_t **changed_argv = new wchar_t*[argc]; // Setting arguments for (int i = 0; i < argc; i++) diff --git a/src/Container/SALOME_Container.py b/src/Container/SALOME_Container.py index 8abee5f50..14dff9176 100644 --- a/src/Container/SALOME_Container.py +++ b/src/Container/SALOME_Container.py @@ -45,6 +45,7 @@ import SALOME_PyNode from SALOME_utilities import * from Utils_Identity import getShortHostName from launchConfigureParser import verbose +from KernelBasis import VerbosityActivated #============================================================================= @@ -154,3 +155,8 @@ class SALOME_Container_i: exc_typ,exc_val,exc_fr=sys.exc_info() l=traceback.format_exception(exc_typ,exc_val,exc_fr) return 1,"".join(l) + + def propageVerbosityToLogging(self): + if VerbosityActivated(): + import runSalomeCommon + runSalomeCommon.positionVerbosityOfLogger() diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 4fcfca574..964e7d186 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -505,6 +505,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con cont->override_environment_python( envCorba ); if( !_code_to_exe_on_startup.empty() ) cont->execute_python_code( _code_to_exe_on_startup.c_str() ); + cont->verboselevel( SALOME::VerbosityActivated()? 1 : 0 ); return cont._retn(); } else @@ -668,8 +669,10 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par struct stat file_info; stat(val, &file_info); bool is_dir = S_ISDIR(file_info.st_mode); - if (is_dir)logFilename=val; - else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl; + if (is_dir) + logFilename=val; + else + MESSAGE( "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl ); } logFilename += "/"; #endif @@ -720,6 +723,7 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par else { // Setting log file name + ret->locallogfilename( logFilename.c_str() ); logFilename=":"+logFilename; logFilename="@"+Kernel_Utils::GetHostname()+logFilename;//threadsafe logFilename=user+logFilename; diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index ca2fac0a3..900ba01ce 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -115,8 +115,12 @@ public: CORBA::Long getTotalPhysicalMemoryInUseByMe(); char *name(); char *workingdir(); - char *logfilename(); - void logfilename(const char *name); + char *logfilename() override; + void logfilename(const char *name) override; + char *locallogfilename() override; + void locallogfilename(const char *name) override; + void verboselevel(CORBA::Long vl) override; + CORBA::Long verboselevel() override; virtual void Shutdown(); char *getHostName(); @@ -175,6 +179,7 @@ protected: std::string _library_path; std::string _containerName; std::string _logfilename; + std::string _localfilename; std::string _load_script; CORBA::ORB_var _orb; PortableServer::POA_var _poa; diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index 1bb41877d..eea4f4f0c 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -29,6 +29,7 @@ import pickle import Engines__POA import SALOME__POA import SALOME +from KernelBasis import VerbosityActivated MY_CONTAINER_ENTRY_IN_GLBS = "my_container" @@ -384,7 +385,7 @@ class PyScriptNode_i (Engines__POA.PyScriptNode,Generic): self.ccode=compile(code,nodeName,'exec') self.context={} self.context[MY_CONTAINER_ENTRY_IN_GLBS] = self.my_container - + def __del__(self): # force removal of self.context. Don t know why it s not done by default self.removeAllVarsInContext() -- 2.39.2