Skip to content

Commit 7573782

Browse files
authored
Merge pull request #48219 from makortel/messageLoggerDebug
Make empty and `'*'` `debugModules` to result in all debug messages to be printed
2 parents 3e3d877 + 31e6f40 commit 7573782

File tree

11 files changed

+101
-24
lines changed

11 files changed

+101
-24
lines changed

FWCore/MessageService/Readme.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Useful MessageLogger Configuration Changes
22

3+
Note that `MessageLogger` is part of `process` by default, i.e. explicit loading of `FWCore.MessageService.MessageLogger_cfi` is not necessary.
4+
35
## Turning off the end of job statistics
46
This requires setting the parameter of cerr
57
```python
6-
process.load("FWCore.MessageService.MessageLogger_cfi")
78
process.MessageLogger.cerr.enableStatistics = False
89
```
910

1011
## Switching from cerr to cout
1112
One needs to switch off cerr and switch on cout
1213

1314
```python
14-
process.load("FWCore.MessageService.MessageLogger_cfi")
1515
process.MessageLogger.cerr.enable = False
1616
process.MessageLogger.cout.enable = True
1717
```
@@ -20,7 +20,6 @@ process.MessageLogger.cout.enable = True
2020
Assuming the file you want to write is name `my_file.log` then
2121

2222
```python
23-
process.load("FWCore.MessageService.MessageLogger_cfi")
2423
process.MessageLogger.files.my_file = dict()
2524
```
2625

@@ -34,14 +33,12 @@ process.MessageLogger.cerr.enable = False
3433
By default the `cerr` will reject all messages below `FWKINFO` (i.e. `threshold = "FWKINFO"`) and the defaut for `INFO` is set to print no output ,i.e. `limit = 0`. So to see all `INFO` messages one would do
3534

3635
```python
37-
process.load("FWCore.MessageService.MessageLogger_cfi")
3836
process.MessageLogger.cerr.threshold = "INFO"
3937
process.MessageLogger.cerr.INFO.limit = -1
4038
```
4139

4240
All messages above `FWKINFO` by default are set to be displayed, that is they have `limit = -1`. You can explicitly set that by doing
4341
```python
44-
process.load("FWCore.MessageService.MessageLogger_cfi")
4542
process.MessageLogger.cerr.WARNING = dict(limit = -1)
4643
```
4744

@@ -52,7 +49,6 @@ The `MessageLogger.cerr` PSet knows that all _extra_ parameter labels must be of
5249
By default the `cerr` will reject all messages below `FWKINFO` (i.e. `threshold = "FWKINFO"`) and the defaut for `INFO` is set to print no output ,i.e. `limit = 0`. In order to see messages for the category 'MyCat' the threshold must be lowered and the category must be explicitly mentioned
5350

5451
```python
55-
process.load("FWCore.MessageService.MessageLogger_cfi")
5652
process.MessageLogger.cerr.threshold = "INFO"
5753
process.MessageLogger.cerr.MyCat = dict()
5854
```
@@ -64,34 +60,39 @@ The `MessageLogger.cerr` PSet knows that all _extra_ parameter labels must be of
6460
In order to supporess messages for a given category, e.g. 'MyCat', the limit should be set to 0
6561

6662
```python
67-
process.load("FWCore.MessageService.MessageLogger_cfi")
6863
process.MessageLogger.MyCat = dict(limit = 0)
6964
```
7065

7166
The `MessageLogger` PSet knows that all _extra_ parameter labels must be of type `cms.untracked.PSet` so one can use a python `dict` set specific parameters for that PSet and allow all other parameters to use their default default values.
7267

7368

69+
## Have all debug messages be shown
7470

75-
## Have debug message show for a given module
7671
By default, all `LogDebug` code is actually removed at compilation time so any messages you want to see have to be recompiled after setting the `EDM_ML_DEBUG` compilation parameter
7772

7873
```bash
7974
> export USER_CXXFLAGS="-DEDM_ML_DEBUG"
8075
> scram b ...
8176
```
8277

83-
Then in the `MessageLogger` configuration you need to lower the `threshold` to `"DEBUG"` and then say you want debug messages from the module. So if your module uses the label `myModule` in the configuration, you'd specify
78+
Then in the `MessageLogger` configuration you need to lower the `threshold` to `"DEBUG"`
79+
```python
80+
process.MessageLogger.cerr.threshold = "DEBUG"
81+
```
82+
83+
The default `MessageLogger` configuration leads to all debug messages to be printed (also outside modules).
84+
8485

86+
## Have debug message show for a given module
87+
88+
It is possible to restrict the shown debug messages to specific module(s). For example, if your module uses the label `myModule` in the configuration, you'd specify
8589
```python
86-
process.load("FWCore.MessageService.MessageLogger_cfi")
8790
process.MessageLogger.cerr.threshold = "DEBUG"
8891
process.MessageLogger.debugModules = ["myModule"]
8992
```
9093

91-
If you are not interested in a particular module but instead want to see all debug messages, you can instead set `debugModules` using `*`
92-
94+
For backwards compatibility, setting `debugModules` to `*` has the same effect as setting `debugModules` empty, i.e. showing all debug messages.
9395
```python
94-
process.load("FWCore.MessageService.MessageLogger_cfi")
9596
process.MessageLogger.cerr.threshold = "DEBUG"
9697
process.MessageLogger.debugModules = ["*"]
9798
```

FWCore/MessageService/plugins/MessageLogger.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,19 @@ namespace edm {
183183
// set up for tracking whether current module is debug-enabled
184184
// (and info-enabled and warning-enabled)
185185
if (debugModules.empty()) {
186-
anyDebugEnabled_ = false; // change log 11
187-
MessageDrop::instance()->debugEnabled = false; // change log 1
186+
anyDebugEnabled_ = true;
187+
everyDebugEnabled_ = true;
188+
MessageDrop::instance()->debugEnabled = true;
188189
} else {
189190
anyDebugEnabled_ = true; // change log 11
190191
MessageDrop::instance()->debugEnabled = false;
191192
// this will be over-ridden when specific modules are entered
192193
}
193194

194-
// if ( debugModules.empty()) anyDebugEnabled_ = true; // wrong; change log 11
195195
for (vString::const_iterator it = debugModules.begin(); it != debugModules.end(); ++it) {
196196
if (*it == "*") {
197197
everyDebugEnabled_ = true;
198+
MessageDrop::instance()->debugEnabled = true;
198199
} else {
199200
debugEnabledModules_.insert(*it);
200201
}

FWCore/MessageService/src/ThreadSafeLogMessageLoggerScribe.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,10 @@ namespace edm {
915915
topDesc.addUntracked<std::vector<std::string>>("suppressFwkInfo", {});
916916
topDesc.addUntracked<std::vector<std::string>>("suppressWarning", {});
917917
topDesc.addUntracked<std::vector<std::string>>("suppressError", {});
918-
topDesc.addUntracked<std::vector<std::string>>("debugModules", {});
918+
topDesc.addUntracked<std::vector<std::string>>("debugModules", {})
919+
->setComment(
920+
"Set to limit the DEBUG-level messages to modules with these labels. If empty or contains '*', all "
921+
"DEBUG messages (also those outside modules) will be issued (if allowed by the threshold parameter).");
919922

920923
edm::ParameterSetDescription category;
921924
category.addUntracked<int>("reportEvery", 1);

FWCore/MessageService/test/BuildFile.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@
6161
<use name="FWCore/Framework"/>
6262
</library>
6363

64+
<library file="UnitTestService_H.cc" name="UnitTestService_H">
65+
<flags EDM_PLUGIN="1"/>
66+
<use name="FWCore/MessageLogger"/>
67+
<use name="FWCore/ParameterSet"/>
68+
<use name="FWCore/ServiceRegistry"/>
69+
</library>
70+
71+
<library file="UnitTestService_Hd.cc" name="UnitTestService_Hd">
72+
<flags EDM_PLUGIN="1"/>
73+
<use name="FWCore/MessageLogger"/>
74+
<use name="FWCore/ParameterSet"/>
75+
<use name="FWCore/ServiceRegistry"/>
76+
</library>
77+
6478
<library file="UnitTestClient_I.cc" name="UnitTestClient_I">
6579
<flags EDM_PLUGIN="1"/>
6680
<use name="FWCore/MessageLogger"/>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifdef EDM_ML_DEBUG
2+
#undef EDM_ML_DEBUG
3+
#endif
4+
5+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
6+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
7+
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
8+
9+
namespace edmtest {
10+
class UnitTestService_H {
11+
public:
12+
UnitTestService_H(edm::ParameterSet const& iConfig, edm::ActivityRegistry& iRegistry) {
13+
iRegistry.watchPreSourceNextTransition(
14+
[]() { LogDebug("cat_S") << "Message from watchPreSourceNextTransition"; });
15+
}
16+
};
17+
} // namespace edmtest
18+
19+
#include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
20+
DEFINE_FWK_SERVICE(edmtest::UnitTestService_H);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef EDM_ML_DEBUG
2+
#define EDM_ML_DEBUG
3+
#endif
4+
5+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
6+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
7+
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
8+
9+
namespace edmtest {
10+
class UnitTestService_Hd {
11+
public:
12+
UnitTestService_Hd(edm::ParameterSet const& iConfig, edm::ActivityRegistry& iRegistry) {
13+
iRegistry.watchPreSourceNextTransition(
14+
[]() { LogDebug("cat_S") << "Message from watchPreSourceNextTransition"; });
15+
}
16+
};
17+
} // namespace edmtest
18+
19+
#include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
20+
DEFINE_FWK_SERVICE(edmtest::UnitTestService_Hd);

FWCore/MessageService/test/u13_cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949

5050
process.p = cms.Path(process.sendSomeMessages)
5151

52-
52+
process.add_(cms.Service("edmtest::UnitTestService_H"))

FWCore/MessageService/test/u13d_cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
)
4444
)
4545
),
46-
debugModules = cms.untracked.vstring('*'),
46+
debugModules = cms.untracked.vstring(),
4747
)
4848

4949
process.maxEvents = cms.untracked.PSet(
@@ -56,4 +56,4 @@
5656

5757
process.p = cms.Path(process.sendSomeMessages)
5858

59-
59+
process.add_(cms.Service("edmtest::UnitTestService_Hd"))

FWCore/MessageService/test/u1_cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Unit test configuration file for MessageLogger service:
22
# threshold levels for destinations
33
# limit=0 for a category (needed to avoid time stamps in files to be compared)
4-
# enabling all (*) LogDebug, with one destination responding
4+
# enabling all LogDebug, with one destination responding
55
# verify that by default, the threshold for a destination is INFO
66

77
import FWCore.ParameterSet.Config as cms
@@ -56,7 +56,7 @@
5656
noTimeStamps = cms.untracked.bool(True)
5757
)
5858
),
59-
debugModules = cms.untracked.vstring('*'),
59+
debugModules = cms.untracked.vstring(),
6060
)
6161

6262
process.CPU = cms.Service("CPU",

FWCore/MessageService/test/u1d_cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Unit test configuration file for MessageLogger service:
22
# threshold levels for destinations
33
# limit=0 for a category (needed to avoid time stamps in files to be compared)
4-
# enabling all (*) LogDebug, with one destination responding
4+
# enabling all LogDebug, with one destination responding
55
# verify that by default, the threshold for a destination is INFO
66
# test done with debug enabled
77

@@ -57,7 +57,7 @@
5757
noTimeStamps = cms.untracked.bool(True)
5858
)
5959
),
60-
debugModules = cms.untracked.vstring('*')
60+
debugModules = cms.untracked.vstring()
6161
)
6262

6363
process.CPU = cms.Service("CPU",

0 commit comments

Comments
 (0)