log.cpp
Go to the documentation of this file.
1 
19 #include <iostream>
20 #include <cstring>
21 #include <fstream>
22 #include <cstdio>
23 #include <sys/times.h>
24 #include <sys/time.h>
25 
26 #include "log.h"
27 
29 
31 {
32  debugLevel = 0;
33  inputLevel = 0;
34 }
36 {
37  this->inputLevel = inputLevel;
38 }
39 
41 {
42  this->debugLevel = debugLevel;
43 }
44 
45 void CLog::writeLine(std::string line, bool append)
46 {
47  std::ofstream newFile;
48  newFile.open(this->filename.c_str(), std::ios::out | append ? std::ios::app : std::ios::trunc);
49 
50  if (newFile)
51  newFile << getTimeAsStr() << ": " << line << "\n";
52  newFile.close();
53 }
54 
55 std::string CLog::getTimeAsStr()
56 {
57  static struct timeval tstart;
58  static struct timezone tz;
59  struct tm* ptm;
60 
61  gettimeofday(&tstart, &tz);
62  ptm = localtime(&tstart.tv_sec);
63  char time[1024];
64  strftime(time, sizeof (time), "%Y-%m-%d %H:%M:%S", ptm);
65  return time;
66 }
67 std::string CLog::generateLogname(std::string path)
68 {
69  char buffer[1024];
70  std::string time = getTimeAsStr();
71  sprintf(buffer, "%s/logs/log_%s", path.c_str(), time.c_str());
72  return buffer;
73 }
74 
75 void CLog::setFilename(std::string filename)
76 {
77  this->filename = filename;
78 }
CLog()
Definition: log.cpp:30
static std::string getTimeAsStr()
Definition: log.cpp:55
CLog globalLog
Definition: log.cpp:28
void setDebugLevel(int debugLevel)
Definition: log.cpp:40
int inputLevel
Definition: log.h:50
void setInputLevel(int inputLevel)
Definition: log.cpp:35
std::string filename
Definition: log.h:47
int debugLevel
Definition: log.h:49
void setFilename(std::string filename)
Definition: log.cpp:75
Definition: log.h:44
void writeLine(std::string line, bool append=true)
Definition: log.cpp:45
static std::string generateLogname(std::string path)
Definition: log.cpp:67
std::string path
Definition: log.h:47


asr_kinematic_chain_optimizer
Author(s): Aumann Florian, Heller Florian, Jäkel Rainer, Wittenbeck Valerij
autogenerated on Mon Jun 10 2019 12:35:36