31 char strFileName[255];
32 strcpy(strFileName, strrchr(__argv[0],
'\\') + 1);
33 char *p = strstr(strFileName,
".");
37 strcat(strFileName,
".log");
39 m_fileLog.open(strFileName, ios_base::app);
42 cout <<
"Open Log file faled! [" << strFileName <<
"]" << endl;
53 *
this <<
"[Begin]\t" << strDate <<
" " << strTime << endl;
64 *
this <<
"[End]\t" << strDate <<
" " << strTime << endl;
82 cout <<
"Open Log file faled! [" << path <<
"]" << endl;
91 *
this <<
"[ReFile] bNew = " << bNew << endl;
92 *
this <<
"[Begin]\t" << strDate <<
" " << strTime << endl;
159 long long nCur = _ftelli64(fp);
160 _fseeki64(fp, 0, SEEK_END);
161 Progress(nCur,
true, _ftelli64(fp), head);
162 _fseeki64(fp, nCur, SEEK_SET);
175 memcpy(m_symbol, sym,
sizeof(
char) * 3);
184 memcpy(m_symbol, sym,
sizeof(
char) * 3);
198 int curprec = 100 * n / m_total;
199 if (curprec > m_lastprec) {
200 cout <<
"\r" << m_strhead.c_str() <<
" ";
201 int barlen = (int)(1.0 * curprec / 100 * m_barmaxlen);
203 for (
int i = 0; i < barlen; i++)
205 for (
int i = 0; i < m_barmaxlen - barlen; i++)
207 cout << m_symbol[2]<<
" ";
208 cout << setprecision(2) << setiosflags(ios::fixed) << 1.0 * n / m_total * 100 <<
"%" << setprecision(6);
211 m_lastprec = curprec;
212 if (curprec == 100) {
this class can output to the cmd window and log files simultaneously. In wb-log.cpp, there are a Log variable "lout", which can be directly used just like "cout". For example:
void ReFile(const char *path, bool bNew=true)
relocate the log file. The defualt log file is "program name".log
bool & bOutputCmd()
if output to the cmd window
short m_nLevel
output level
void LevelDown()
level down
void Reset(long long total=100, const char *head="", const char *sym="[=]")
reset the progress bar
ofstream m_fileLog
log file stream
Log & operator<<(ostream &(*op)(ostream &))
output.
a definition of a class Log, which can output to the cmd window and the log file simultaneously. In wb-log.cpp, there are a Log variable "lout", which can be directly used just like "cout". For example:
bool m_bOutputCmd
if output to the cmd window
bool m_bOutputLog
if output to the log file
void Progress(long long n=-1, bool bInit=false, long long total=100, const char *head="")
progress bar
bool & bOutputLog()
if output to the log file
Log lout
the defination is in wb-log.cpp
void Update(long long n=-1)
update the progress bar. n should be from 1 to m_total
ProgressBar m_bar
the build-in progerss bar.
define all the code written by Bin Wang.