Skip to content

Commit

Permalink
Add logger class
Browse files Browse the repository at this point in the history
  • Loading branch information
moisesvw committed Mar 17, 2018
1 parent fb0f34d commit 606fb95
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "logger.h"

Logger::Logger(){
log_path = "./";
file_name = "log.csv";
ifstream filecheck(file_name);

if( !filecheck.good() ){
ofstream outfile_(log_path + file_name);
outfile_.close();
}

outfile.open(log_path + file_name, ios_base::app);
}

Logger::~Logger(){}

void Logger::log(const string & line){
outfile << line.c_str() << std::endl;
}

20 changes: 20 additions & 0 deletions src/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef LOGGER_H_
#define LOGGER_H_
#include <string>
#include <fstream>
using namespace std;

class Logger {
public:
Logger();
virtual ~Logger();
void log(const string &line);

private:
ofstream outfile;
string log_path;
string file_name;

};

#endif /* LOGGER_H_ */
Binary file modified tests/my_googletest
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
googletest ./test_main.cpp ../src/tools.cpp ./test_tools.cpp
googletest ./test_main.cpp ../src/tools.cpp ../src/logger.cpp ./test_tools.cpp ./test_logger.cpp
18 changes: 18 additions & 0 deletions tests/test_logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <gtest/gtest.h>
#include "../src/logger.h"
#include <fstream>
#include <stdio.h>
using namespace std;

TEST(Logger, log) {
Logger log;
char filepath[10] = "./log.csv";

ifstream Infield(filepath);
ASSERT_TRUE( Infield.good() );

remove(filepath);

fstream Infield2(filepath);
ASSERT_TRUE( !Infield2.good() );
}

0 comments on commit 606fb95

Please sign in to comment.