Skip to content

Commit 31e6f40

Browse files
committed
Make empty and '*' debugModules to result in all debug messages to be printed
Previously there was no way to enable debug messages for non-module code. But we want to be able to issue debug messages e.g. from Services or framework. In addition, the empty debugModules (that is also the default value) leading to no debug messages being issued seemed now a poor choice (given the amount of complaints in the past on how difficult MessageLogger is to configure, especially for debug messages).
1 parent 047da1b commit 31e6f40

File tree

11 files changed

+99
-15
lines changed

11 files changed

+99
-15
lines changed

FWCore/MessageService/Readme.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,32 @@ process.MessageLogger.MyCat = dict(limit = 0)
6666
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.
6767

6868

69+
## Have all debug messages be shown
6970

70-
## Have debug message show for a given module
7171
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
7272

7373
```bash
7474
> export USER_CXXFLAGS="-DEDM_ML_DEBUG"
7575
> scram b ...
7676
```
7777

78-
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).
7984

85+
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
8089
```python
8190
process.MessageLogger.cerr.threshold = "DEBUG"
8291
process.MessageLogger.debugModules = ["myModule"]
8392
```
8493

85-
If you are not interested in a particular module but instead want to see all debug messages, you can instead set `debugModules` using `*`
86-
94+
For backwards compatibility, setting `debugModules` to `*` has the same effect as setting `debugModules` empty, i.e. showing all debug messages.
8795
```python
8896
process.MessageLogger.cerr.threshold = "DEBUG"
8997
process.MessageLogger.debugModules = ["*"]

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)