object inside class becomes NULL

I have built LOG4CXX lib and DLL and trying to use it in my application

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Loh.h 
class Log
{
public:
 Log(void);
 ~Log(void);
 void Debug(const char *msg);

private:
static LoggerPtr  oLogger;
};

Log.cpp
LoggerPtr  oLogger = NULL;
Log::Log()
{
        LoggerPtr oLogger(Logger::getLogger("Test"));
    PropertyConfigurator::configure("Logger4CXX.properties");
}

void CLogger::Debug(const char *msg)
{
    if(CLogger::oLogger != NULL)
    {
        LOG4CXX_DEBUG(CLogger::oLogger,"Testing application...");   
    }
}


In my main I am initializing Log class object and calling Debug method to log debug message to a file.

Issue I am facing is at if(CLogger::oLogger != NULL) which is always returning oLogger as NULL.

Can anyone offer any help on this.
Last edited on
> Issue I am facing is at if(CLogger::oLogger != NULL) which is always returning oLogger as NULL.

You initialized it as a null pointer, and never assigned a different value to it after that.

1
2
3
4
5
6
7
8
9
10
11
12
13
Log::Log()
{
    // this defines a local variable with automatic storage duration called 'oLogger'
    LoggerPtr oLogger(Logger::getLogger("Test"));

    // this assigns a value to the static member variable 'oLogger'
    oLogger = Logger::getLogger("Test") ;

    // same as above, but perhaps makes the intent a tad clearer
    Log::oLogger = Logger::getLogger("Test") ;

   // ...
}
Topic archived. No new replies allowed.