This logger was initially made for a Youtube tutorial.
This is a header-only library consisting of one header file. Simply copy the include/yelloger.h file and #include
it in your project.
Console logging (the simplest use case)
#include <yelloger.h>
int main()
{
const char* name = "User";
Yellog::Info("Hello %s", name);
return 0;
}
Output:
15:07:31 15-02-2021 [Info] Hello User
Yellog doesn't need to be instantiated, just include the header and use it like this
Yellog::Info("Infotmation %d", int_value);
, also there is no need to put newline character at the end of the message, it will be done automatically.
The default log priority is Yellog::InfoPriority
. You can set priority by calling
Yellog::SetPriority(Yellog::DebugPriority); // e.g. Yellog::DebugPriority
Possible values:
Yellog::TracePriority
Yellog::DebugPriority
Yellog::InfoPriority
Yellog::WarnPriority
Yellog::ErrorPriority
Yellog::CriticalPriority
You can get priority by calling
Yellog::GetPriority(); // will return Yellog::InfoPriority if Yellog::SetPriority hasn't been called before
To log:
Yellog::Trace(const char* message, Args... args) // log a message with trace priority
Yellog::Debug(const char* message, Args... args) // log a message with debug priority
Yellog::Info(const char* message, Args... args) // log a message with info priority
Yellog::Warn(const char* message, Args... args) // log a message with warn priority
Yellog::Error(const char* message, Args... args) // log a message with error priority
Yellog::Critical(const char* message, Args... args) // log a message with critical priority
As args you can provide primitives and C-strings. Formatting follows printf format.
To enable file output, call
Yellog::EnableFileOutput("mylogpath/mylog.txt");
before using the logger.
Optionally, you can provide no path
Yellog::EnableFileOutput();
then, the logs will be saved in '/log.txt'.
To get the current filepath for file logging, call
Yellog::GetFilepath();
if file output was not enabled, the filepath will contain NULL, otherwise a const char* value will be returned.
To check if file output was enabled and file was successfully opened, call
Yellog::IsFileOutputEnabled(); // returns true if success, false if failure
Format follows ctime strftime format specification.
Default format is "%T %d-%m-%Y" (e.g. 13:20:25 14-02-2021).
4 spaces are added automatically to the end of timestamp each time the message is logged.
To set a log timestamp format, call
Yellog::SetTimestampFormat("%c"); // e.g. Thu Aug 23 14:55:02 2001
To get the current log timestamp format, call
Yellog::GetTimestampFormat(); // e.g. "13:20:25 14-02-2021"
yelloger's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.