Skip to content

Commit 84f0995

Browse files
authored
Merge pull request #6891 from chaen/v8.0_FEAT_globalLogLevel
[8.0] Allow to define global log levels
2 parents ae7ecc2 + 24f6320 commit 84f0995

File tree

8 files changed

+74
-14
lines changed

8 files changed

+74
-14
lines changed

dirac.cfg

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,25 @@ Resources
10001000
}
10011001
}
10021002
##END
1003+
1004+
# Configuration for logging backends
1005+
# https://dirac.readthedocs.io/en/latest/DeveloperGuide/AddingNewComponents/Utilities/gLogger/gLogger/Basics/index.html#backend-resources
1006+
LogBackends
1007+
{
1008+
# Configure the stdout backend
1009+
stdout
1010+
{
1011+
LogLevel = INFO
1012+
}
1013+
# Example for a log backend sending to message queue
1014+
# see https://dirac.readthedocs.io/en/latest/AdministratorGuide/ServerInstallations/centralizedLogging.html
1015+
mqLogs
1016+
{
1017+
MsgQueue = lhcb-mb.cern.ch::Queues::lhcb.dirac.logging
1018+
# Name of the plugin if not the section name
1019+
Plugin = messageQueue
1020+
}
1021+
}
10031022
}
10041023
Operations
10051024
{
@@ -1108,6 +1127,21 @@ Operations
11081127
# Module used for InputData resolution if not specified in the JDL
11091128
InputDataModule = DIRAC.Core.Utilities.InputDataResolution
11101129
}
1130+
Logging
1131+
{
1132+
# Default log backends and level applied to Services if
1133+
# it is not defined in the service specific section
1134+
DefaultServicesBackends = stdout
1135+
DefaultServicesLogLevel = INFO
1136+
1137+
# Similar options for agents
1138+
DefaultAgentsBackends = stdout, mqLogs
1139+
DefaultAgentsLogLevel = VERBOSE
1140+
1141+
# Default log level that is applied in last resort
1142+
DefaultLogLevel = DEBUG
1143+
1144+
}
11111145
# Options for the pilot3
11121146
# See https://dirac.readthedocs.io/en/latest/AdministratorGuide/Systems/WorkloadManagement/Pilots/Pilots3.html
11131147
Pilot

src/DIRAC/ConfigurationSystem/private/ConfigurationData.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, loadDefaultCFG=True):
4141
gLogger.debug("dirac.cfg should be at", f"{defaultCFGFile}")
4242
retVal = self.loadFile(defaultCFGFile)
4343
if not retVal["OK"]:
44-
gLogger.warn(f"Can't load {defaultCFGFile} file")
44+
gLogger.debug(f"Can't load {defaultCFGFile} file")
4545
self.sync()
4646

4747
def getBackupDir(self):

src/DIRAC/Core/Tornado/scripts/tornado_start_CS.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def main():
3535
localCfg = Script.localCfg
3636
localCfg.addMandatoryEntry("/DIRAC/Setup")
3737
localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
38-
localCfg.addDefaultEntry("LogLevel", "INFO")
3938
localCfg.addDefaultEntry("LogColor", True)
4039
resultDict = localCfg.loadUserData()
4140
if not resultDict["OK"]:

src/DIRAC/Core/Tornado/scripts/tornado_start_all.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def main():
3333
localCfg.setConfigurationForTornado()
3434
localCfg.addMandatoryEntry("/DIRAC/Setup")
3535
localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
36-
localCfg.addDefaultEntry("LogLevel", "INFO")
3736
localCfg.addDefaultEntry("LogColor", True)
3837
resultDict = localCfg.loadUserData()
3938
if not resultDict["OK"]:

src/DIRAC/Core/scripts/dirac_agent.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def main():
2525
localCfg.setConfigurationForAgent(agentName)
2626
localCfg.addMandatoryEntry("/DIRAC/Setup")
2727
localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
28-
localCfg.addDefaultEntry("LogLevel", "INFO")
2928
localCfg.addDefaultEntry("LogColor", True)
3029
resultDict = localCfg.loadUserData()
3130
if not resultDict["OK"]:

src/DIRAC/Core/scripts/dirac_executor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def main():
2929
localCfg.setConfigurationForExecutor(mainName)
3030
localCfg.addMandatoryEntry("/DIRAC/Setup")
3131
localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
32-
localCfg.addDefaultEntry("LogLevel", "INFO")
3332
localCfg.addDefaultEntry("LogColor", True)
3433
resultDict = localCfg.loadUserData()
3534
if not resultDict["OK"]:

src/DIRAC/Core/scripts/dirac_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def main():
2828
# localCfg.addMandatoryEntry( "HandlerPath" )
2929
localCfg.addMandatoryEntry("/DIRAC/Setup")
3030
localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
31-
localCfg.addDefaultEntry("LogLevel", "INFO")
3231
localCfg.addDefaultEntry("LogColor", True)
3332
resultDict = localCfg.loadUserData()
3433
if not resultDict["OK"]:

src/DIRAC/FrameworkSystem/private/standardLogging/LoggingRoot.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def __init__(self):
5050
for level in levels:
5151
logging.addLevelName(levels[level], level)
5252

53-
# root Logger level is set to NOTICE by default
54-
self._logger.setLevel(LogLevels.NOTICE)
53+
# root Logger level is set to INFO by default
54+
self._logger.setLevel(LogLevels.INFO)
5555

5656
# initialization of the UTC time
5757
# Actually, time.gmtime is equal to UTC time: it has its DST flag to 0 which means there is no clock advance
@@ -116,14 +116,45 @@ def initialize(self, systemName, cfgPath, forceInit=False):
116116
for handler in handlersToRemove:
117117
self._logger.removeHandler(handler)
118118

119-
levelName = gConfig.getValue(f"{cfgPath}/LogLevel", None)
119+
levelName = self.__getLogLevelFromCFG(cfgPath)
120120
if levelName is not None:
121121
self.setLevel(levelName)
122122

123123
LoggingRoot.__configuredLogging = True
124124
finally:
125125
self._lockConfig.release()
126126

127+
def __getLogLevelFromCFG(self, cfgPath):
128+
"""
129+
Get the logging level from the cfg, following this order:
130+
131+
* cfgPath/LogLevel
132+
* Operations/<setup/vo>/Logging/Default<Agents/Services>LogLevel
133+
* Operations/<setup/vo>/Logging/DefaultLogLevel
134+
135+
:param str cfgPath: configuration path
136+
"""
137+
# We have to put the import line here to avoid a dependancy loop
138+
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
139+
from DIRAC import gConfig
140+
141+
# Search desired log level in the component
142+
logLevel = gConfig.getValue(f"{cfgPath}/LogLevel")
143+
if not logLevel:
144+
# get the second last string representing the component type in the configuration
145+
# example : 'Agents', 'Services'
146+
component = cfgPath.split("/")[-2]
147+
148+
operation = Operations()
149+
# Search desired logLevel in the operation section according to the
150+
# component type
151+
logLevel = operation.getValue(f"Logging/Default{component}LogLevel")
152+
if not logLevel:
153+
# Search desired logLevel in the operation section
154+
logLevel = operation.getValue("Logging/DefaultLogLevel")
155+
156+
return logLevel
157+
127158
def __getBackendsFromCFG(self, cfgPath):
128159
"""
129160
Get backends from the configuration and register them in LoggingRoot.
@@ -135,14 +166,14 @@ def __getBackendsFromCFG(self, cfgPath):
135166
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
136167
from DIRAC import gConfig
137168

138-
# get the second last string representing the component type in the configuration
139-
# example : 'Agents', 'Services'
140-
component = cfgPath.split("/")[-2]
141-
operation = Operations()
142-
143169
# Search desired backends in the component
144170
backends = gConfig.getValue(f"{cfgPath}/LogBackends", [])
145171
if not backends:
172+
# get the second last string representing the component type in the configuration
173+
# example : 'Agents', 'Services'
174+
component = cfgPath.split("/")[-2]
175+
176+
operation = Operations()
146177
# Search desired backends in the operation section according to the
147178
# component type
148179
backends = operation.getValue(f"Logging/Default{component}Backends", [])

0 commit comments

Comments
 (0)