MessageLogger Tutorial Examples
Contents
Sending Warnings and Error Messages to a File
# warningsToMyOutputFile.py
# -------------------------------
import FWCore.ParameterSet.Config as cms
process.MessageLogger = cms.Service("MessageLogger",
destinations = cms.untracked.vstring( #1
'myOutputFile' #2
),
myOutputFile = cms.untracked.PSet( #3
threshold = cms.untracked.string( 'WARNINGS' ) #4
),
) #5
# set the number of events
process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(200)
)
process.myAnalysisModule = cms.EDAnalyzer('ModuleThatIssuesMessages')
process.p = cms.Path(process.myAnalysisModule)
Explanation:
In the above example, one file, named
myOutputFile.log
, would be produced.
On line 1, we define a vstring named
destinations=cms.untracked.vstring(...
. Every
confugration file should have this vstring defined; the name
destinations is a
keyword telling the logger that one or more files for output are going to be created.
On line 2, we name a file destination. In this example, this is the only destination we name.
Two special names could have been used here:
cerr
or
cout
. Those would not
produce files; they would route the output to
cerr
or
cout
.
On line 3, we start a
PSet
with a name matching one of the destinations we had specified.
In this case, that name is
myOutputFile
. The contents of this
PSet
will control the
behavior of just that destination. The name of the file produced will be taken from the
name of the destination; by default, the logger adds the extension
.log
.
(A later example will explain how to get an extension other than
.log
, or a file name
other than the name of the destination PSet, if you want.)
On line 4, we are controlling the behavior of this destination. In this case, we are saying
that the
threshold for responding to messages issues is at
the level of
WARNING
. This means that this destination will respond to (and output)
message issued via
edm::LogWarning
and anything at least that serious. (For example,
edm::LogPrint
,
edm::LogError
,
edm::LogProblem
, and
edm::LogImportant
will lead to output.)
But levels less severe than
WARNING
will not appear. For example,
edm::LogInfo
and
edm::LogVerbatim
will have no effect on this destination.
Line 5 completes the configuration of the MessageLogger. The other lines of this example
are generic lines to tell cmsRun how many events to process, which modules to use, and
so forth.
--
MarkFischler - 12-Aug-2010