static or instance call..

closed account (S6k9GNh0)
So, I've been trying to make a very small logger class for debugging and info on my games. The problem I came across is that I couldn't decide if I should make a log class of static functions (which might as well be some C functions at that point) or if I should make a singleton class.

Example 1:
cq::Log::Message("I'm awesome");

Example 2:
cq::Log::GetInstance->Message("I'm awesome");

I figured I'd grab some opinions on ups and downs. I tried looking at some libraries such as log4cpp but they were nowhere near what I wanted and way to large for my taste.
I've used Apache log4cxx and it was fine even for small programs. It requires a few lines of code to configure the logger (either default or with a properties file) and then nothing else. You don't have to use any of the complex features.

http://logging.apache.org/log4cxx/index.html

It's part of Fedora, and I think they have Windows packages available too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "log4cxx/log4cxx.h"
#include "log4cxx/basicconfigurator.h"
#include "log4cxx/helpers/exception.h"

using namespace log4cxx;
using namespace log4cxx::helpers;

LoggerPtr logger(Logger::getLogger("LogTest"));

int main()
{
    BasicConfigurator::configure();

    LOG4CXX_INFO(logger, "Foo " << 2 << " Bar");
    
    return 0;
}

Topic archived. No new replies allowed.