LSSTApplications  19.0.0-10-g4a5fae6+3,19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+16,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+6,19.0.0-20-g5a5a17ab+14,19.0.0-21-g2644856+17,19.0.0-24-g0913cb1,19.0.0-24-g878c510+4,19.0.0-25-g6c8df7140+1,19.0.0-25-gb330496+4,19.0.0-3-g2b32d65+6,19.0.0-3-g8227491+15,19.0.0-3-g9c54d0d+15,19.0.0-3-gca68e65+11,19.0.0-3-gcfc5f51+6,19.0.0-3-ge110943+14,19.0.0-3-ge74d124,19.0.0-30-g9c3fd16+5,19.0.0-4-g06f5963+6,19.0.0-4-g10df615,19.0.0-4-g3d16501+17,19.0.0-4-g4a9c019+6,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+16,19.0.0-4-ge404a01+15,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gb9eeb60,19.0.0-5-gfb03ce7+16,19.0.0-6-gbaebbfb+15,19.0.0-61-gec4c6e08+5,19.0.0-7-g039c0b5+15,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+16,19.0.0-72-g37abf38+2,19.0.0-9-g463f923+15,v20.0.0.rc1
LSSTDataManagementBasePackage
utils.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 #
5 # Copyright 2016 AURA/LSST.
6 #
7 # This product includes software developed by the
8 # LSST Project (http://www.lsst.org/).
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the LSST License Statement and
21 # the GNU General Public License along with this program. If not,
22 # see <https://www.lsstcorp.org/LegalNotices/>.
23 #
24 
25 __all__ = ["traceSetAt", "temporaryLogLevel"]
26 
27 from contextlib import contextmanager
28 
29 from lsst.log import Log
30 
31 
32 def traceSetAt(name, number):
33  """Adjusts logging level to display messages with the trace number being
34  less than or equal to the provided value.
35 
36  Parameters
37  ----------
38  name : `str`
39  Name of the logger.
40  number : `int`
41  The trace number threshold for display.
42  """
43  for i in range(6):
44  level = Log.INFO if i > number else Log.DEBUG
45  Log.getLogger('TRACE%d.%s' % (i, name)).setLevel(level)
46 
47 
48 @contextmanager
49 def temporaryLogLevel(name, level):
50  """A context manager that temporarily sets the level of a `Log`.
51 
52  Parameters
53  ----------
54  name : `str`
55  Name of the log to modify.
56  level : `int`
57  Integer enumeration constant indicating the temporary log level.
58  """
59  log = Log.getLogger(name)
60  old = log.getLevel()
61  log.setLevel(level)
62  try:
63  yield
64  finally:
65  log.setLevel(old)
lsst::log
Definition: Log.h:706
lsst::log.utils.temporaryLogLevel
def temporaryLogLevel(name, level)
Definition: utils.py:49
lsst::log.log.logContinued.setLevel
def setLevel(loggername, level)
Definition: logContinued.py:174
lsst::log.utils.traceSetAt
def traceSetAt(name, number)
Definition: utils.py:32