Xmipp  v3.23.11-Nereus
xmipp_log.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: J.M. De la Rosa Trevin (jmdelarosa@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include <stdio.h>
27 #include <iostream>
28 #include "xmipp_log.h"
29 #include "xmipp_funcs.h"
30 
33 
35 {
36  fileHandler = fopen(filename.c_str(), "w+");
37 }
38 
40 {
41  fclose(fileHandler);
42 }
43 
44 void XmippLog::logMessage(const String &msg)
45 {
46  //printf("%s%s\t%s\n", getCurrentTimeString(), levelSpaces.c_str(), msg.c_str());
47  fprintf(fileHandler, "%s%s %s\n", getCurrentTimeString(), levelSpaces.c_str(), msg.c_str());
48  fflush(fileHandler);
49 }
50 
51 void XmippLog::enterLevel(const String &msg)
52 {
53  logMessage(formatString(">> %s", msg.c_str()));
54  levelSpaces += " ";
55 }
56 
57 void XmippLog::leaveLevel(const String &msg)
58 {
59  levelSpaces.erase(0, 3);
60  if (msg.size())
61  logMessage(formatString("<< %s", msg.c_str()));
62 }
63 
65 {
66  this->log = log;
67  this->block = block;
68  log->enterLevel(block);
69 }
70 
72 {
73  log->leaveLevel();
74 }
75 
void enterLevel(const String &msg="")
Definition: xmipp_log.cpp:51
char * getCurrentTimeString()
XmippLog * __xmippLog
Definition: xmipp_log.cpp:32
void log(Image< double > &op)
XmippLogBlock(XmippLog *log, const String &block)
Definition: xmipp_log.cpp:64
XmippLog(String filename)
Definition: xmipp_log.cpp:34
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
void leaveLevel(const String &msg="")
Definition: xmipp_log.cpp:57
fprintf(glob_prnt.io, "\)
void logMessage(const String &msg)
Definition: xmipp_log.cpp:44