consolidate all repos to one for archive
This commit is contained in:
38
semester_2/programiranje_2/naloga1102/Log.cpp
Normal file
38
semester_2/programiranje_2/naloga1102/Log.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by Nik on 20/05/2022.
|
||||
//
|
||||
|
||||
#include "Log.h"
|
||||
#include <ctime>
|
||||
|
||||
Log::Log(LogType type) {
|
||||
file.open(fileName,std::ios_base::out | std::ios_base::app);
|
||||
time_t now = time(0);
|
||||
tm* strucTime = localtime(&now);
|
||||
|
||||
std::string time;
|
||||
time = std::to_string(strucTime->tm_year + 1900) + "-" +
|
||||
std::to_string(strucTime->tm_mon + 1) + "-" +
|
||||
std::to_string(strucTime->tm_mday) + " " +
|
||||
std::to_string(strucTime->tm_hour) + ":" +
|
||||
std::to_string(strucTime->tm_min) + ":" +
|
||||
std::to_string(strucTime->tm_sec) + " ";
|
||||
operator<<(time + GetStringLogType(type));
|
||||
}
|
||||
|
||||
Log::~Log() {
|
||||
file.close();
|
||||
}
|
||||
|
||||
std::string Log::GetStringLogType(LogType type) {
|
||||
switch (type) {
|
||||
case LogType::ERROR:
|
||||
return "[ERROR] ";
|
||||
case LogType::INFO:
|
||||
return "[INFO] ";
|
||||
case LogType::DEBUG:
|
||||
return "[DEBUG] ";
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user