Skip to content

Commit 9069df0

Browse files
authored
Merge pull request #6967 from aldbr/v8.1_FEAT_loggingChanges
[8.1] feat logging changes
2 parents 959bf09 + b189423 commit 9069df0

File tree

15 files changed

+104
-105
lines changed

15 files changed

+104
-105
lines changed

docs/source/AdministratorGuide/Resources/messagequeues.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ like described in :ref:`development_use_mq`, for example::
9595
message = result['Value']
9696

9797

98-
In order not to spam the logs, the log output of Stomp is always silence, unless the environment variable `DIRAC_DEBUG_STOMP` is set to any value.
99-
100-
10198
Message Queue nomenclature in DIRAC
10299
-----------------------------------
103100

docs/source/AdministratorGuide/ServerInstallations/environment_variable_configuration.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ DIRAC_DEBUG_DENCODE_CALLSTACK
1414
DIRAC_DEBUG_M2CRYPTO
1515
If ``true`` or ``yes``, print a lot of SSL debug output
1616

17-
DIRAC_DEBUG_STOMP
18-
If set, the stomp library will print out debug information
19-
2017
DIRAC_DEPRECATED_FAIL
2118
If set, the use of functions or objects that are marked ``@deprecated`` will fail. Useful for example in continuous
2219
integration tests against future versions of DIRAC

src/DIRAC/ConfigurationSystem/Client/LocalConfiguration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def initialize(self, *, returnErrors=False):
311311

312312
def __initLogger(self, componentName, logSection, forceInit=False):
313313
gLogger.initialize(componentName, logSection, forceInit=forceInit)
314+
gLogger.disableLogsFromExternalLibs()
314315

315316
if self.__debugMode == 1:
316317
gLogger.setLevel("VERBOSE")
@@ -320,6 +321,7 @@ def __initLogger(self, componentName, logSection, forceInit=False):
320321
elif self.__debugMode >= 3:
321322
gLogger.setLevel("DEBUG")
322323
gLogger.showHeaders(True)
324+
gLogger.enableLogsFromExternalLibs()
323325

324326
def loadUserData(self):
325327
"""

src/DIRAC/FrameworkSystem/private/standardLogging/Formatter/BaseFormatter.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BaseFormatter
33
"""
44
import logging
5-
import sys
5+
import time
66

77

88
class BaseFormatter(logging.Formatter):
@@ -23,6 +23,9 @@ def __init__(self, fmt=None, datefmt=None):
2323
:param str fmt: log format: "%(asctime)s UTC %(name)s %(levelname)s: %(message)"
2424
:param str datefmt: date format: "%Y-%m-%d %H:%M:%S"
2525
"""
26+
# Initialization of the UTC time
27+
# Actually, time.gmtime is equal to UTC time: it has its DST flag to 0 which means there is no clock advance
28+
self.converter = time.gmtime
2629
super().__init__()
2730

2831
def format(self, record):
@@ -43,7 +46,7 @@ def format(self, record):
4346

4447
if record.headerIsShown:
4548
if record.timeStampIsShown:
46-
timeStamp = "%(asctime)s UTC "
49+
timeStamp = "%(asctime)s "
4750
if record.contextIsShown:
4851
contextComponentList = ["%(componentname)s%(customname)s"]
4952

@@ -63,5 +66,14 @@ def format(self, record):
6366
fmt += "%(message)s%(spacer)s%(varmessage)s"
6467

6568
self._style._fmt = fmt # pylint: disable=no-member
66-
self.datefmt = "%Y-%m-%d %H:%M:%S"
6769
return super().format(record)
70+
71+
def formatTime(self, record, datefmt=None):
72+
""":py:meth:`logging.Formatter.formatTime` with microsecond precision by default"""
73+
ct = self.converter(record.created)
74+
if datefmt:
75+
s = time.strftime(datefmt, ct)
76+
else:
77+
t = time.strftime("%Y-%m-%dT%H:%M:%S", ct)
78+
s = "%s,%06dZ" % (t, (record.created - int(record.created)) * 1e6)
79+
return s

src/DIRAC/FrameworkSystem/private/standardLogging/Formatter/MicrosecondJsonFormatter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def __init__(self, *args, **kwargs):
1010
Add to the list of attributes we don't want to see
1111
all the DIRAC spefic log formating instructions
1212
"""
13+
# Initialization of the UTC time
14+
# Actually, time.gmtime is equal to UTC time: it has its DST flag to 0 which means there is no clock advance
15+
self.converter = time.gmtime
16+
1317
if "reserved_attrs" not in kwargs:
1418
kwargs["reserved_attrs"] = RESERVED_ATTRS + (
1519
"spacer",
@@ -27,6 +31,6 @@ def formatTime(self, record, datefmt=None):
2731
if datefmt:
2832
s = time.strftime(datefmt, ct)
2933
else:
30-
t = time.strftime("%Y-%m-%d %H:%M:%S", ct)
31-
s = "%s,%06d" % (t, (record.created - int(record.created)) * 1e6)
34+
t = time.strftime("%Y-%m-%dT%H:%M:%S", ct)
35+
s = "%s,%06dZ" % (t, (record.created - int(record.created)) * 1e6)
3236
return s

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
LogLevels wrapper
33
"""
4+
from __future__ import annotations
45
from enum import IntEnum
56
import logging
67

@@ -53,7 +54,7 @@ class LogLevels:
5354
}
5455

5556
@classmethod
56-
def getLevelValue(cls, sName):
57+
def getLevelValue(cls, sName: str) -> int | None:
5758
"""
5859
Get a level value from a level name.
5960
We could use logging.getLevelName() to get the level value but it is less simple.
@@ -64,7 +65,7 @@ def getLevelValue(cls, sName):
6465
return cls.__levelDict.get(sName.upper())
6566

6667
@classmethod
67-
def getLevel(cls, level):
68+
def getLevel(cls, level: int) -> str | None:
6869
"""
6970
Get a level name from a level value.
7071
We could use logging.getLevelName() to get the level value but it is less simple.
@@ -78,14 +79,14 @@ def getLevel(cls, level):
7879
return None
7980

8081
@classmethod
81-
def getLevelNames(cls):
82+
def getLevelNames(cls) -> list[str]:
8283
"""
8384
:return: all level names available in the wrapper
8485
"""
8586
return list(cls.__levelDict)
8687

8788
@classmethod
88-
def getLevels(cls):
89+
def getLevels(cls) -> dict[str, int]:
8990
"""
9091
:return: the level dictionary. Must no be redefined
9192
"""

0 commit comments

Comments
 (0)