-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ); | ||
} |