Linux multi-monitor fullscreen support
[ryzomcore.git] / nelns / admin_executor_service / log_report.h
blobde9201f3abfc0038e86f62c1c4124db7d52cbc4a
1 // NeLNS - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef NL_LOG_REPORT_H
18 #define NL_LOG_REPORT_H
20 #include "nel/misc/types_nl.h"
21 #include "nel/misc/log.h"
22 #include "nel/misc/thread.h"
23 #include <string>
24 #include <vector>
25 #include <map>
28 class CLogReport;
33 class CMakeLogTask : public NLMISC::IRunnable
35 public:
37 /// Constructor
38 CMakeLogTask() : _Stopping(false), _Complete(false), _Thread(NULL), _OutputLogReport(NULL) {}
40 /// Destructor
41 ~CMakeLogTask();
43 /// Start (called in main thread)
44 void start();
46 /// Ask for stop and wait until terminated (called in main thread)
47 void terminateTask();
49 ///
50 bool isRunning() const { return (_Thread != NULL) && (!_Complete); }
52 ///
53 bool isStopping() const { return _Stopping; }
55 ///
56 bool isComplete() const { return _Complete; }
58 virtual void run();
60 /// Set the path of logfile directory.
61 void setLogPath(const std::string & logPath);
63 /// Set one or more paths of logfile directory. They will be processed when running the background thread.
64 void setLogPaths(const std::vector<std::string>& logPaths);
66 /// Set the path of logfile directory to default value
67 void setLogPathToDefault();
69 /// Return the log paths
70 const std::vector<std::string> getLogPaths() const { return _LogPaths; }
72 /** Set which files are to be browsed:
73 * v --> log*.log (default if setLogTarget() not called or called with an empty string)
74 * v* --> log*.log + v*_log*.log
75 * v<n> --> v<n>_log*.log
76 * v<n>+ --> v<n>_log*.log + all matching greater <n> + log*.log
77 * v<n>- --> v<n>_log*.log + all matching lower <n>
78 * * --> *.log
80 void setLogTarget(const std::string & logTarget) { _LogTarget = logTarget; }
82 /// Return the log report (NULL if task not started yet)
83 CLogReport* getLogReport() { return _OutputLogReport; }
85 private:
87 void pleaseStop() { _Stopping = true; }
88 void clear();
90 volatile bool _Stopping;
91 volatile bool _Complete;
92 std::string _LogTarget;
93 std::vector<std::string> _LogPaths;
95 NLMISC::IThread *_Thread;
97 CLogReport *_OutputLogReport;
101 const uint NB_LINES_PER_PAGE = 100;
107 class CLogLineInfo
109 public:
111 CLogLineInfo() : NbOccurences(0) {}
113 void addAnOccurence( const std::vector<std::string>& lineTokens );
115 uint NbOccurences;
117 std::string SampleLogText;
124 class ILogReport
126 public:
128 virtual void storeLine( const std::vector<std::string>& lineTokens, bool mainCountOnly ) = 0;
130 virtual void report( NLMISC::CLog *targetLog, bool detailed ) = 0;
132 virtual uint getNbDistinctLines() const = 0;
134 virtual uint getNbTotalLines( NLMISC::CLog::TLogType logType ) = 0;
136 virtual ~ILogReport() {}
141 * For one service (service name, not service instance), store info about log lines
143 class CLogReportLeaf : public ILogReport
145 public:
147 /// Constructor
148 CLogReportLeaf( const std::string& service ) : _Service(service), _TotalLines(0) {}
150 std::string service() { return _Service; }
152 virtual uint getNbDistinctLines() const { return (uint)_LogLineInfo.size(); }
154 virtual uint getNbTotalLines( NLMISC::CLog::TLogType logType );
156 virtual void storeLine( const std::vector<std::string>& lineTokens, bool mainCountOnly );
158 virtual void report( NLMISC::CLog *targetLog, bool detailed );
160 uint reportPart( uint beginIndex, uint maxNbLines, NLMISC::CLog *targetLog );
162 protected:
164 typedef std::map< std::string, CLogLineInfo > CLogLineInfoMap;
166 std::string _Service;
168 CLogLineInfoMap _LogLineInfo;
170 std::map< std::string, uint > _Counts; // indexed by log type string
172 uint _TotalLines;
177 * Store info about log lines for several services
179 class CLogReportNode : public ILogReport
181 public:
183 /// Constructor
184 CLogReportNode() {}
186 /// Destructor
187 ~CLogReportNode() { reset(); }
189 /// Clear all
190 void reset()
192 for ( std::vector<CLogReportLeaf*>::iterator it=_Children.begin(); it!=_Children.end(); ++it )
193 delete (*it);
194 _Children.clear();
197 protected:
199 virtual void storeLine( const std::vector<std::string>& lineTokens, bool mainCountOnly=false );
201 CLogReportLeaf* getChild( const std::string& service )
203 for ( std::vector<CLogReportLeaf*>::iterator it=_Children.begin(); it!=_Children.end(); ++it )
205 if ( (*it)->service() == service )
206 return (*it);
208 return NULL;
211 CLogReportLeaf* addChild( const std::string& service )
213 CLogReportLeaf *child = new CLogReportLeaf( service );
214 _Children.push_back( child );
215 return child;
218 virtual void report( NLMISC::CLog *targetLog, bool displayDetailsPerService );
220 virtual uint getNbDistinctLines() const
222 uint n = 0;
223 for ( std::vector<CLogReportLeaf*>::const_iterator it=_Children.begin(); it!=_Children.end(); ++it )
224 n += (*it)->getNbDistinctLines();
225 return n;
228 virtual uint getNbTotalLines( NLMISC::CLog::TLogType logType=NLMISC::CLog::LOG_UNKNOWN )
230 uint n = 0;
231 for ( std::vector<CLogReportLeaf*>::const_iterator it=_Children.begin(); it!=_Children.end(); ++it )
232 n += (*it)->getNbTotalLines( logType );
233 return n;
236 void reportPage( uint pageNum, NLMISC::CLog *targetLog );
238 private:
240 std::vector<CLogReportLeaf*> _Children;
245 * <Class description>
246 * \author Olivier Cado
247 * \author Nevrax France
248 * \date 2004
250 class CLogReport : public CLogReportNode
252 public:
254 /// Constructor
255 CLogReport() : _CurrentFile(~0), _TotalFiles(~0) {}
257 /// Clear all
258 void reset() { CLogReportNode::reset(); }
261 * Add a log line to the report tree.
262 * \param onlyType Type of log to study. If LOG_UNKNOWN, study all.
263 * \param countOtherTypes If true and onlyType not LOG_UNKNOWN, count the number of lines of each other type found.
265 void pushLine( const std::string& line, NLMISC::CLog::TLogType onlyType=NLMISC::CLog::LOG_WARNING, bool countOtherTypes=true );
267 /// Set the current progress
268 void setProgress( uint currentFile, uint totalFiles ) { _CurrentFile = currentFile; _TotalFiles = totalFiles; }
270 /// Get the current progress
271 void getProgress( uint& currentFile, uint& totalFiles ) { currentFile = _CurrentFile; totalFiles = _TotalFiles; }
273 /// Get results for a service
274 void reportByService( const std::string& service, NLMISC::CLog *targetLog );
276 /// Get partial results (pageNum>=1)
277 void reportPage( uint pageNum, NLMISC::CLog *targetLog ) { CLogReportNode::reportPage( pageNum, targetLog ); }
279 /// Get summary of results
280 virtual void report( NLMISC::CLog *targetLog, bool displayDetailsPerService=false ) { CLogReportNode::report( targetLog, displayDetailsPerService ); }
282 private:
284 uint _CurrentFile;
285 uint _TotalFiles;
289 #endif // NL_LOG_REPORT_H
291 /* End of log_report.h */