1 Star 0 Fork 1

Linteeh/BitCrack

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Logger.cpp 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
brichard19 提交于 2018-11-19 11:02 +08:00 . Added --keyspace option: Specify the key space:
#include <stdio.h>
#include <time.h>
#include "Logger.h"
#include "util.h"
bool LogLevel::isValid(int level)
{
switch(level) {
case Info:
case Error:
case Debug:
return true;
default:
return false;
}
}
std::string LogLevel::toString(int level)
{
switch(level) {
case Info:
return "Info";
case Error:
return "Error";
case Debug:
return "Debug";
case Warning:
return "Warning";
}
return "";
}
std::string Logger::getDateTimeString()
{
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
return std::string(buf);
}
std::string Logger::formatLog(int logLevel, std::string msg)
{
std::string dateTime = getDateTimeString();
std::string prefix = "[" + dateTime + "] [" + LogLevel::toString(logLevel) + "] ";
size_t prefixLen = prefix.length();
std::string padding(prefixLen, ' ');
if(msg.find('\n', 0) != std::string::npos) {
size_t pos = 0;
size_t prev = 0;
while((pos = msg.find('\n', prev)) != std::string::npos) {
prefix += msg.substr(prev, pos - prev) + "\n" + padding;
prev = pos + 1;
}
prefix += msg.substr(prev);
} else {
prefix += msg;
}
return prefix;
}
void Logger::log(int logLevel, std::string msg)
{
std::string str = formatLog(logLevel, msg);
fprintf(stderr, "%s\n", str.c_str());
}
void Logger::setLogFile(std::string path)
{
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Linteeh/BitCrack.git
git@gitee.com:Linteeh/BitCrack.git
Linteeh
BitCrack
BitCrack
master

搜索帮助