Commit ec3617d5 authored by yiwenshao's avatar yiwenshao

add util/log and the tests

parent e8303817
...@@ -3,3 +3,8 @@ echo "./mtl/test_util_exe/verify_constants" ...@@ -3,3 +3,8 @@ echo "./mtl/test_util_exe/verify_constants"
./mtl/test_util_exe/verify_constants ./mtl/test_util_exe/verify_constants
echo ================================================================== echo ==================================================================
echo "./mtl/test_util_exe/verify_log"
./mtl/test_util_exe/verify_log
echo ==================================================================
#include "util/log.hh"
#include "util/constants.hh"
#include <string>
#include <iostream>
using std::cout;
using std::endl;
int main(){
std::string line("abcdefghehe");
logToFile log(constGlobalConstants.logFile);
log<<line<<"\n";
return 0;
}
OBJDIRS += util OBJDIRS += util
UTILSRC := onions.cc cryptdb_log.cc ctr.cc util.cc version.cc constants.cc UTILSRC := onions.cc cryptdb_log.cc ctr.cc util.cc version.cc constants.cc log.cc
all: $(OBJDIR)/libedbutil.so $(OBJDIR)/libedbutil.a all: $(OBJDIR)/libedbutil.so $(OBJDIR)/libedbutil.a
......
#include "util/log.hh"
#include <assert.h>
#include <stdio.h>
logToFile::logToFile(std::string filename){
logfileHandler = fopen(filename.c_str(),"w");
assert(logfileHandler!=NULL);
}
logToFile&
logToFile::operator<<(std::string record) {
fwrite(record.c_str(),1,record.size(),logfileHandler);
return *this;
}
logToFile::~logToFile(){
fclose(logfileHandler);
}
#pragma once
#include <string>
class logToFile{
FILE* logfileHandler;
public:
logToFile(std::string filename);
logToFile& operator<<(std::string record);
~logToFile();
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment