Skip to content

Commit

Permalink
Added name support
Browse files Browse the repository at this point in the history
  • Loading branch information
joeinman committed Oct 8, 2024
1 parent 4ff24e5 commit 4a4771f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 6 additions & 2 deletions include/EmbedLog/EmbedLog.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <functional>
#include <string>

Expand All @@ -13,7 +15,7 @@ namespace EmbedLog
class EmbedLog
{
public:
EmbedLog(OpenFunction openFunc, CloseFunction closeFunc, PrintFunction printFunc, MicrosecondFunction microsecondFunc, LogLevel logLevel = LogLevel::INFO);
EmbedLog(OpenFunction openFunc, CloseFunction closeFunc, PrintFunction printFunc, MicrosecondFunction microsecondFunc, std::string name = "", LogLevel logLevel = LogLevel::INFO);
~EmbedLog();

bool open();
Expand All @@ -27,8 +29,10 @@ namespace EmbedLog
CloseFunction closeFunc;
PrintFunction printFunc;
MicrosecondFunction microsecondFunc;
LogLevel logLevel;

bool isOpen = false;
LogLevel logLevel;
std::string name = " ";

std::string getTimestamp();
};
Expand Down
17 changes: 14 additions & 3 deletions src/EmbedLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

namespace EmbedLog
{
EmbedLog::EmbedLog(OpenFunction openFunc, CloseFunction closeFunc, PrintFunction printFunc, MicrosecondFunction microsecondFunc, LogLevel logLevel)
: openFunc(openFunc), closeFunc(closeFunc), printFunc(printFunc), microsecondFunc(microsecondFunc), logLevel(logLevel)
EmbedLog::EmbedLog(OpenFunction openFunc,
CloseFunction closeFunc,
PrintFunction printFunc,
MicrosecondFunction microsecondFunc,
std::string name,
LogLevel logLevel)
: openFunc(openFunc),
closeFunc(closeFunc),
printFunc(printFunc),
microsecondFunc(microsecondFunc),
logLevel(logLevel)
{
if (!name.empty())
this->name = " " + name + " ";
}

EmbedLog::~EmbedLog()
Expand Down Expand Up @@ -45,7 +56,7 @@ namespace EmbedLog
break;
}

printFunc(getTimestamp() + " [" + logLevelString + "] " + message);
printFunc("[" + getTimestamp() + name + logLevelString + "] " + message);
}
}

Expand Down

0 comments on commit 4a4771f

Please sign in to comment.