Simple Logger in C++ I'm currently making a game using C++. I eventually needed a logger, but I wasn't satisfied with any of the existing solutions. After a while, I wrote my own header called log.h:

#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;
#include &lt;ctime&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;

class Logger {
    private:
        std::string logFileName = &quot;log.txt&quot;;
        bool print = true;
        bool save = true;
        
        void log(std::string s, std::string i) {
            time_t cuT;
            struct tm *loT;
            time(&amp;cuT);
            loT = localtime(&amp;cuT);
            
            std::stringstream ss;
            ss &lt;&lt; std::setw(2) &lt;&lt; std::setfill('0') &lt;&lt; loT-&gt;tm_hour &lt;&lt; ':';
            ss &lt;&lt; std::setw(2) &lt;&lt; std::setfill('0') &lt;&lt; loT-&gt;tm_min &lt;&lt; ':';
            ss &lt;&lt; std::setw(2) &lt;&lt; std::setfill('0') &lt;&lt; loT-&gt;tm_sec;
            ss &lt;&lt; i &lt;&lt; s &lt;&lt; &quot;\n&quot;;
            
            if(save) {
                std::ofstream of;
                of.open(logFileName, std::ios_base::app | std::ios::out);
                of &lt;&lt; ss.rdbuf();
            }
            if(print) {
                std::cout &lt;&lt; ss.str();
            }
        }
    public:
        void configure(std::string logFileName_, bool print_, bool save_) {
            this-&gt;print = print_;
            this-&gt;save = save_;
            this-&gt;logFileName = logFileName_;
        }
        
        void note(std::string s) {
            log(s, &quot; NOTE: &quot;);
        }
        
        void error(std::string s) {
            log(s, &quot; ERROR: &quot;);
        }
        
        void warn(std::string s) {
            log(s, &quot; WARNING: &quot;);
        }
};

My library can print the current time as well as other information to the console and save this data into a file. But I did a couple of benchmarks and it turns out that my logging program is a lot slower compared to the normal std::cout.
Since speed is crucial for games, I wanted to ask whether there are ways to optimize my program or, if necessary, to improve it.
Some things to note;

When doing time related things in C++, use std::chrono, not clock().
Your log will not work if it's used in multiple files. Instead of being in a .h file, put the definition of the logger in a cpp file and build both together.
Use include guards for header files

    #ifndef LOG_H
    #define LOG_H

    // Code

    #endif


Define constructors and use them properly and get rid of configure.

    Log(std::string fileName, bool printToConsole, bool saveToFile) :
        logFileName(fileName),
        print(printToConsole),
        save(saveToFile)
    {
    }


Do not use underscores for naming things. General rules for c++ are class names are PascalCase and functions are camelCase.
std::cout is slow, consider using sprintf to make it faster.
Don't write to a file every time you call log. Opening files and writing to them is slow. Consider writing to the file on a timestamp or aggregating a few logs before writing them.