Created
December 12, 2016 02:46
-
-
Save indraniel/afdadda18732943a5cecfc1ca8fa283e to your computer and use it in GitHub Desktop.
Example Simple C++ logging (w/o C++11 or later)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <ctime> | |
| void logMsg( const std::string& msg ) { | |
| time_t rawtime; | |
| struct tm * timeinfo; | |
| char buffer[80]; | |
| time (&rawtime); | |
| timeinfo = localtime(&rawtime); | |
| strftime(buffer,80,"%Y-%m-%d %H:%M:%S",timeinfo); | |
| std::string str(buffer); | |
| std::cout << "[" << str << "]" << " ---> " << msg << std::endl; | |
| } | |
| int main() { | |
| logMsg("Here I am!"); | |
| logMsg("Bye Bye"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment