NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
MSGTool.cxx
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#include "NAGASH/MSGTool.h"
7
8using namespace NAGASH;
9using namespace std;
10
14MSGTool::MSGTool(MSGLevel level, const TString &name)
15{
16 DefinedLevel = level;
17 FocusName = name;
18
21 else
22 OutputLevel = level;
23}
24
28MSGTool::MSGTool(const MSGTool &msg, int ThreadNumber)
29{
30 TString num;
31 num.Form("_JobNum%d", ThreadNumber);
34 FocusName = msg.FocusName;
36 isOpenLog = msg.isOpenLog;
37 LogFileName = msg.LogFileName + num;
38 FuncTitle = msg.FuncTitle;
39
40 if (isOpenLog)
42 if (isCreateLog)
44}
45
50
53void MSGTool::CreateLog(const TString &name)
54{
55 if (tolog == true)
56 CloseLog();
57
58 outfile = ofstream(name.TString::Data(), ios::out);
59 LogFileName = name;
60 tolog = true;
61 isCreateLog = true;
62 isOpenLog = false;
63}
64
67void MSGTool::OpenLog(const TString &name)
68{
69 if (tolog == true)
70 CloseLog();
71
72 outfile = ofstream(name.TString::Data(), ios::app);
73 LogFileName = name;
74 tolog = true;
75 isOpenLog = true;
76 isCreateLog = false;
77}
78
81{
82 if (tolog == false)
83 return;
84 else
85 {
86 tolog = false;
87 isCreateLog = false;
88 isOpenLog = false;
89 outfile.close();
90 }
91}
92
95void MSGTool::StartFocusRegion(const TString &name)
96{
97 if ((DefinedLevel == MSGLevel::FOCUS) && (FocusName.TString::EqualTo(name) == true))
99}
100
103void MSGTool::EndFocusRegion(const TString &name)
104{
105 if ((DefinedLevel == MSGLevel::FOCUS) && (FocusName.TString::EqualTo(name) == true))
107}
108
118void MSGTool::StartTitle(const TString &name)
119{
120 std::unique_lock msglock(MSGMutex);
121 FuncTitle.push_back(name);
122}
123
127std::unique_ptr<MSGTool::MSGTitleGuard> MSGTool::StartTitleWithGuard(const TString &name)
128{
129 std::unique_lock msglock(MSGMutex);
130 FuncTitle.push_back(name);
131 return std::unique_ptr<MSGTitleGuard>(new MSGTitleGuard(shared_from_this()));
132}
133
136{
137 std::unique_lock msglock(MSGMutex);
138 if (FuncTitle.size() > 0)
139 FuncTitle.pop_back();
140}
141
143{
144 std::shared_lock msglock(MSGMutex);
145 if (FuncTitle.size() == 0)
146 Print("Title Track Lost");
147 else
148 {
149 for (size_t i = 0; i < FuncTitle.size(); i++)
150 {
151 if (i == FuncTitle.size() - 1)
152 Print(FuncTitle[i]);
153 else
154 Print(FuncTitle[i], "->");
155 }
156 }
157}
158
160{
161 if (level == MSGLevel::FATAL)
162 Print("FATAL");
163 if (level == MSGLevel::ERROR)
164 Print("ERROR");
165 if (level == MSGLevel::WARNING)
166 Print("WARNING");
167 if (level == MSGLevel::INFO)
168 Print("INFO");
169 if (level == MSGLevel::DEBUG)
170 Print("DEBUG");
171}
172
177{
178 auto prev = OutputLevel;
179 OutputLevel = level;
180 return prev;
181}
182
185{
186 return OutputLevel;
187}
Used to call MSGTool::EndTitle() automatically.
Definition MSGTool.h:99
Maniplulate all messages of NAGASH.
Definition MSGTool.h:28
MSGLevel OutputLevel
Definition MSGTool.h:37
void OpenLog(const TString &name)
Open log file with given file name.
Definition MSGTool.cxx:67
bool isCreateLog
Definition MSGTool.h:43
MSGLevel DefinedLevel
Definition MSGTool.h:38
void PrintTitle()
Definition MSGTool.cxx:142
TString FocusName
Definition MSGTool.h:39
std::unique_ptr< MSGTitleGuard > StartTitleWithGuard(const TString &title)
Start a title with given name.
Definition MSGTool.cxx:127
MSGLevel SetOutputLevel(MSGLevel level)
Set the output message level.
Definition MSGTool.cxx:176
void CloseLog()
Close the log file.
Definition MSGTool.cxx:80
void Print(Args &&...args)
Definition MSGTool.h:166
void EndTitle()
End the current title.
Definition MSGTool.cxx:135
std::vector< TString > FuncTitle
Definition MSGTool.h:40
void StartFocusRegion(const TString &name)
Start focus region, inside this region the message level would be set to debug.
Definition MSGTool.cxx:95
void CreateLog(const TString &name)
Create log file with given file name.
Definition MSGTool.cxx:53
MSGLevel Level() const
Get the current message level.
Definition MSGTool.cxx:184
void StartTitle(const TString &name)
Start a title with given name.
Definition MSGTool.cxx:118
MSGTool()=default
void PrintLevel(MSGLevel level)
Definition MSGTool.cxx:159
TString LogFileName
Definition MSGTool.h:45
std::ofstream outfile
Definition MSGTool.h:41
std::shared_mutex MSGMutex
Definition MSGTool.h:47
void EndFocusRegion(const TString &name)
End focus region.
Definition MSGTool.cxx:103
MSGLevel
class to define different message level
Definition MSGTool.h:14