LSSTApplications  19.0.0-14-gb0260a2+16456dd421,20.0.0+44dbdb3492,20.0.0+5d43f57eb7,20.0.0+8a208d85ec,20.0.0+a295394073,20.0.0+f15d39cacd,20.0.0-1-g253301a+8a208d85ec,20.0.0-1-g5b95a8c+fc0c0df92e,20.0.0-16-g760a3dc6+b31208f437,20.0.0-18-gcabc0c9fd+54cb7ade16,20.0.0-2-g4dae9ad+71e3c9ad45,20.0.0-2-g61b8584+b4ab3064f8,20.0.0-2-ga51b5d4+1f4ba438e8,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+c85f3a4c63,20.0.0-2-gf072044+8a208d85ec,20.0.0-2-gf1f7952+71e3c9ad45,20.0.0-22-g54e2caa+3351092962,20.0.0-25-g5eafb0f+71e3c9ad45,20.0.0-28-g73474ed+3c7e226ea7,20.0.0-29-g1235a2f+d30e658c1c,20.0.0-3-g8f21e14+558cb18951,20.0.0-3-gbd60e8c+ffb20d0b0d,20.0.0-3-gbecbe05+7f0063ada4,20.0.0-4-g4bc9b9f+57161cfff5,20.0.0-4-gb4befbc+0e003188f4,20.0.0-4-gf910f65+b4ab3064f8,20.0.0-43-gfec247c5+985768289e,20.0.0-5-gcbc8587+3c7e226ea7,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g4aa86cc+b6dcff6f8d,20.0.0-6-g9a5b7a1+4bc2181c53,20.0.0-6-gd222c45+7040a8a6f6,20.0.0-74-g0218c7a+7d276c6844,20.0.0-9-g4aef684+90bf294a58,20.0.0-9-g5051ac2+d529cf1a41,w.2020.47
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