You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by Nandan S <na...@hp.com> on 2014/02/06 15:06:32 UTC

using log4cxx from sca component

I have created a sample application with log4cxx and it works great.

	Requirement in our application was to create a wrapper around log4cxx
functionality, so that in future any other logging functionality can be used
instead of log4cxx. 

	For that, we created a component, wrapping log4cxx functionality using
software component architecture (sca) framework.

a.	This wrapper component is loaded by other components or other
applications
b.	Component method, initialize() is called with the filename argument (xml
properties filename )
c.	Component passes the argument to DOM configurator. 

Issue:
            File name passed from component to DOM configurator never gets
passed and following is the error inside log4cxx. 
“log4cxx: Could not open file [ ] “

We could observe this by setting “LogLog::setInternalDebugging( true );”
(in sample application, file name is printed instead of [] and works fine)

Which means parameter we are passing from our wrapper component to logging
framework is failing. We have tried by passing wstring, string,  passing
hard coded value, declaring a string variable and passing that variable….but
the result is the same, does’t work. We have even tried Configuring using
other overloaded “configureAndWatch” functions.
a.     Void ConfigureAndWatch(filename)
                    Static Methods
b.     Void configureAnd Watch(filename, delay)                
c.      Void doConfigure(filename, hierarchy)        ---------- Public
method

    We were successful in logging with 
 BasicConfigurator::configure() method only (but this does not accept any
configuration filename as argument)

Any help in fixing the issue is greatly appreciated. 




--
View this message in context: http://apache-logging.6191.n7.nabble.com/using-log4cxx-from-sca-component-tp44065.html
Sent from the Log4cxx - Dev mailing list archive at Nabble.com.

RE: using log4cxx from sca component

Posted by Nandan S <na...@hp.com>.
I have tried by passing hard coded absolute and relative path too. Both of
them don't work.
I have tried other over loaded methods configureAndWatch() too, does not
work.

Nandan



--
View this message in context: http://apache-logging.6191.n7.nabble.com/using-log4cxx-from-sca-component-tp44065p44162.html
Sent from the Log4cxx - Dev mailing list archive at Nabble.com.

Re: using log4cxx from sca component

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Nandan S,
am Samstag, 8. Februar 2014 um 11:39 schrieben Sie:

> I have tried using c:\\properties.xml too.

Then use Process Monitor to log file system activity and search for
your file name. If it is found you can see where your application
looks for it and recognize why it isn't used, if your file name is not
found in the logs the filename doesn't get passed to Log4cxx at all
and you need to debug your code.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


Re: using log4cxx from sca component

Posted by Nandan S <na...@hp.com>.
>Not accepted or not found or what? c:\properties.xml would be wrong in 
>any case, you will need at least c:\\properties.xml, recognize the 
>double \. 

I have tried using c:\\properties.xml too. 




--
View this message in context: http://apache-logging.6191.n7.nabble.com/using-log4cxx-from-sca-component-tp44065p44165.html
Sent from the Log4cxx - Dev mailing list archive at Nabble.com.

Re: using log4cxx from sca component

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Nandan S,
am Samstag, 8. Februar 2014 um 11:16 schrieben Sie:

Please read the following link before your next answer, it makes it
easier for others to follow your mails.

https://www.netmeister.org/news/learn2quote.html

> DOMConfigurator::Configure("c:\properties.xml"), file name is not accepted.

Not accepted or not found or what? c:\properties.xml would be wrong in
any case, you will need at least c:\\properties.xml, recognize the
double \.

Besides that, if your are on Windows you should fire up Process
Monitor and have a look if your paths are recognized, searched for and
simply not found where expected or if the paths are don't even used at
all.

http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


Re: using log4cxx from sca component

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Nandan S,
am Samstag, 8. Februar 2014 um 11:16 schrieben Sie:

> I am still thinking of this and not sure, how can i achieve filename and
> line number to be printed correctly.

You need to make your wrapper capable of providing this information to
LOG4CXX core. I created a simple wrapper for some legacy code which is
implemented as a class with a ctor getting file and function
information, saving that in the instance and methods like trace, debug
etc. providing the line information. Afterwards you can redefine the
macro which Log4cxx uses to use the information of this wrapper.

But I only use this wrapper for very few log statements and don't
think that your approach with wrapping Log4cxx is worth your efforts.

Log4cxxNonCppWrapper(   std::wstring    configFilePath,
                        std::wstring    logger,
                        std::string     file,
                        std::string     function);

void trace(     std::wstring    message,
                int             line,
                std::string     function = "");
                        
#pragma warn -8017
#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo(                                      \
                            this->file.c_str(),                                             \
                            function.empty() ? this->function.c_str() : function.c_str(),   \
                            line)
#pragma warn .8017

void Log4cxxNonCppWrapper::trace(       std::wstring    message,
                                        int             line,
                                        std::string     function)
{
        LOG4CXX_TRACE(this->logger, message);
}

Log4cxxNonCppWrapper log4cxxNonCppWrapper(      log4cxxConfigDir + L"\\GosaPrint.exe.log4cxx.xml",
                                                L"GosaPrint.Main", __FILE__, __FUNC__);
log4cxxNonCppWrapper.info(L"Programmstart: \"" + std::wstring(lpCmdLine) + L"\"", __LINE__);

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


Re: using log4cxx from sca component

Posted by Nandan S <na...@hp.com>.
You will loose some of the benefits of Log4cxx that way, e.g. you can't 
use the efficient LOG4CXX_*-macros and will loose things like line 
numbers and function names where the logging occurred because those 
are inserted by the pre processor. The latter will always be the 
methods of your wrapper unless the wrapper is entirely implemented as 
macros itself. 

I am still thinking of this and not sure, how can i achieve filename and
line number to be printed correctly.

Sounds like you need to debug your wrapper, the filename surely gets 
lost somewhere. I don't see how we can help with that.

Even if i pass a hard coded path like 

DOMConfigurator::Configure("c:\properties.xml"), file name is not accepted.
Not sure, what's going wrong here.



--
View this message in context: http://apache-logging.6191.n7.nabble.com/using-log4cxx-from-sca-component-tp44065p44161.html
Sent from the Log4cxx - Dev mailing list archive at Nabble.com.