1 // NeLNS - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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"
33 class CMakeLogTask
: public NLMISC::IRunnable
38 CMakeLogTask() : _Stopping(false), _Complete(false), _Thread(NULL
), _OutputLogReport(NULL
) {}
43 /// Start (called in main thread)
46 /// Ask for stop and wait until terminated (called in main thread)
50 bool isRunning() const { return (_Thread
!= NULL
) && (!_Complete
); }
53 bool isStopping() const { return _Stopping
; }
56 bool isComplete() const { return _Complete
; }
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>
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
; }
87 void pleaseStop() { _Stopping
= true; }
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;
111 CLogLineInfo() : NbOccurences(0) {}
113 void addAnOccurence( const std::vector
<std::string
>& lineTokens
);
117 std::string SampleLogText
;
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
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
);
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
177 * Store info about log lines for several services
179 class CLogReportNode
: public ILogReport
187 ~CLogReportNode() { reset(); }
192 for ( std::vector
<CLogReportLeaf
*>::iterator it
=_Children
.begin(); it
!=_Children
.end(); ++it
)
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
)
211 CLogReportLeaf
* addChild( const std::string
& service
)
213 CLogReportLeaf
*child
= new CLogReportLeaf( service
);
214 _Children
.push_back( child
);
218 virtual void report( NLMISC::CLog
*targetLog
, bool displayDetailsPerService
);
220 virtual uint
getNbDistinctLines() const
223 for ( std::vector
<CLogReportLeaf
*>::const_iterator it
=_Children
.begin(); it
!=_Children
.end(); ++it
)
224 n
+= (*it
)->getNbDistinctLines();
228 virtual uint
getNbTotalLines( NLMISC::CLog::TLogType logType
=NLMISC::CLog::LOG_UNKNOWN
)
231 for ( std::vector
<CLogReportLeaf
*>::const_iterator it
=_Children
.begin(); it
!=_Children
.end(); ++it
)
232 n
+= (*it
)->getNbTotalLines( logType
);
236 void reportPage( uint pageNum
, NLMISC::CLog
*targetLog
);
240 std::vector
<CLogReportLeaf
*> _Children
;
245 * <Class description>
246 * \author Olivier Cado
247 * \author Nevrax France
250 class CLogReport
: public CLogReportNode
255 CLogReport() : _CurrentFile(~0), _TotalFiles(~0) {}
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
); }
289 #endif // NL_LOG_REPORT_H
291 /* End of log_report.h */