Leonardo Straniero | 2 Apr 17:22 2009

How build and use the log4Cxx Library

Hi all,

I want to use the log4Cxx library for the logging of my application. But I have some problem to understanding how to use the library.

Is it request to build the library and if yes how I build it? If I follow the instruction on the site about the building with the Visual Studio, when I execute the configure-aprutil command I read the following error:

 

'sed' is not recognized as an internal or external command, operable program or batch file.

'sed' is not recognized as an internal or external command, operable program or batch file.

 

What is “sed” and how I can resolve this problem?

 

If I open the projects/log4cxx.dsw with Microsoft Visual Studio and start the build process I read a lot of errors how depicted below:

 

include\apr_network_io.h(24) : fatal error C1083: Cannot open include file: 'apr.h': No such file or directory

 

Any ideas? Anyone can help me?

 

Thanks in advance.

Regards.

                Leonardo.

 

Cory Riddell | 7 Apr 21:29 2009

config file questions

Are the configuration options documented somewhere? I've seen the
examples on the quick start page but I'd like more information.
Specifically, how do the java (log4j) properties map to the c++ classes?

Take this line as an example:
  log4j.appender.R.layout=org.apache.log4j.PatternLayout

How do you parse this line? I'm guessing that *log4j.appender* equals
the log4cxx::Appender class. *R* is an instance and *.layout* somehow
invokes Appender::setLayout(), passing it a default instance of
log4cxx::PatternLayout.

Am I even close? Why do some properties have an org.apache prefix and
others do not? Could this line simply be written as
  R.layout = log4j.PatternLayout
? Can I use log4cxx rather than log4j?

Thanks,
Cory

Jacob L. Anawalt | 8 Apr 01:02 2009

Re: config file questions

On 2009-04-07 13:29, Cory Riddell wrote:
> Are the configuration options documented somewhere? 

The log4cxx API is patterned after the log4j one and strives to be compatible 
with it. The most complete log4j specification, short of reading the code, is 
the log4j manual. I really found myself needing this documentation when I moved 
from the Property configuration to the DOM (xml) configuration.

https://www.qos.ch/shop/products/log4j/log4j-Manual.jsp

> I've seen the
> examples on the quick start page but I'd like more information.
> Specifically, how do the java (log4j) properties map to the c++ classes?
> 
> Take this line as an example:
>   log4j.appender.R.layout=org.apache.log4j.PatternLayout
> 
> How do you parse this line?

With a PropertyConfigurator of course. :) (Properties' PropertyParser isn't 
nearly as magical as the PropertySetter and OptionConverter. See 
PropertyConfigurator::parseAppendder)

> I'm guessing that *log4j.appender* equals
> the log4cxx::Appender class. *R* is an instance and *.layout* somehow
> invokes Appender::setLayout(), passing it a default instance of
> log4cxx::PatternLayout.
> 

While I understand the desire to know how it all works and more importantly how 
to know what class you're setting properties for and what it's options are, I 
finally just started using the library without caring what kind of thing the 
appender R is in memory.

You configure appenders of arbitrary names (I prefer ones that represent the 
type of thing they are appending to like CONSOLE and SYSLOG) and attach them to 
loggers. If you're assigning log4j.appender.LOGFILE = 
org.apache.log4j.FileAppender, then you can look at the set* functions of 
FileAppenderand it's parent WriterAppender and grandparent AppenderSkeleton to 
see the options.

You can also check the source for the appender or layout and look at the 
::setOption function.

> Why do some properties have an org.apache prefix and
> others do not?

When you declare appenders and layouts you specify the class on the right hand 
side. The rest of the properties are for setting values.

> Could this line simply be written as
>   R.layout = log4j.PatternLayout
> ? Can I use log4cxx rather than log4j?
> 

See OptionConverter::instantiateByClassName and the code it calls. Specifically 
Class::forName or more simply, try it.

I use the full org.apache.log4j prefixed names just so my configuration files 
stay compatible with either API. Custom (local) classes probably shouldn't be 
loaded as org.apache.log4j to avoid the confusion and potential classpath 
collisions.

--

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt <at> geckosoftware.com
435-752-8026

Lijuan Zhu | 8 Apr 11:17 2009
Picon

Log file should exist? how to log Chinese characters?

I am new to Log4cxx, and just got it into my projects. I have two questions now:

1, The log file I specified in the xml configuration file should exist?  how to change the configuration so the log4cxx could create the log file if it does not exist?
2. I could not log Chinese characters into the log file (there are something like this:2009-04-08 10:02:29,68? ERROR [ps.?f]??????), is there any setting I can change to make it show the logs correctly?

Thanks a lot,
Lijuan

Curt Arnold | 8 Apr 14:29 2009
Picon

Re: Log file should exist? how to log Chinese characters?


On Apr 8, 2009, at 4:17 AM, Lijuan Zhu wrote:

> I am new to Log4cxx, and just got it into my projects. I have two  
> questions now:
> 1, The log file I specified in the xml configuration file should  
> exist?  how to change the configuration so the log4cxx could create  
> the log file if it does not exist?

log4cxx should attempt to create the file specified if it does not  
exist, perhaps you are running your application with reduced  
privileges that prevent it from writing to the directory to create the  
file?

>
> 2. I could not log Chinese characters into the log file (there are  
> something like this:2009-04-08 10:02:29,68? ERROR [ps.?f]??????), is  
> there any setting I can change to make it show the logs correctly?
>
> Thanks a lot,
> Lijuan

Unless you specify otherwise, log4cxx will use the default encoding of  
your operating system if it can detect it.  If you default encoding is  
something like ISO-8859-1 or USASCII, they are incapable of  
representing Asian characters. The easiest way would be to specify

<param name="encoding" value="UTF-8"/>

or

<param name="encoding" value="UTF-16"/>

Curt Arnold | 8 Apr 15:03 2009
Picon

Re: Log file should exist? how to log Chinese characters?


On Apr 8, 2009, at 4:17 AM, Lijuan Zhu wrote:

> I am new to Log4cxx, and just got it into my projects. I have two  
> questions now:
> 1, The log file I specified in the xml configuration file should  
> exist?  how to change the configuration so the log4cxx could create  
> the log file if it does not exist?
> 2. I could not log Chinese characters into the log file (there are  
> something like this:2009-04-08 10:02:29,68? ERROR [ps.?f]??????), is  
> there any setting I can change to make it show the logs correctly?
>
> Thanks a lot,
> Lijuan

Check the mailing list archive for more detail (search for locale and/ 
or encoding).  You likely also need to make a call to setlocale,  
ideally called before your first log statement which will tell the run- 
time what encoding it should use to interpret char*.  Without a call  
to setlocale(), the default is the USASCII.

Lijuan Zhu | 9 Apr 04:51 2009
Picon

Re: Log file should exist? how to log Chinese characters?

Thanks, Curt.
 
The second problem is solved after adding the encoding.

The first one, I am sure my application has the privilege to create file, and the path of the file does exists, just could not create the file.

Do you know where is it in the log4cxx source code attempting to create the file? I will debug into it.

Thanks,
Lijuan

On Wed, Apr 8, 2009 at 8:29 PM, Curt Arnold <carnold <at> apache.org> wrote:

On Apr 8, 2009, at 4:17 AM, Lijuan Zhu wrote:

I am new to Log4cxx, and just got it into my projects. I have two questions now:
1, The log file I specified in the xml configuration file should exist?  how to change the configuration so the log4cxx could create the log file if it does not exist?

log4cxx should attempt to create the file specified if it does not exist, perhaps you are running your application with reduced privileges that prevent it from writing to the directory to create the file?



2. I could not log Chinese characters into the log file (there are something like this:2009-04-08 10:02:29,68? ERROR [ps.?f]??????), is there any setting I can change to make it show the logs correctly?

Thanks a lot,
Lijuan


Unless you specify otherwise, log4cxx will use the default encoding of your operating system if it can detect it.  If you default encoding is something like ISO-8859-1 or USASCII, they are incapable of representing Asian characters. The easiest way would be to specify

<param name="encoding" value="UTF-8"/>

or

<param name="encoding" value="UTF-16"/>




Sylvester Steele | 10 Apr 14:01 2009
Picon

Trivial.cpp example not working

Hi,
I was trying out the the example at https://svn.apache.org/repos/asf/logging/log4cxx/tags/v0_9_6/examples/trivial.cpp. Unfortunately it isn't working yet.

My code looks like:


#include <iostream>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/ndc.h>


using namespace std;
using namespace log4cxx;
using namespace log4cxx::helpers;


int main() {
    BasicConfigurator::configure();
    LoggerPtr rootLogger = Logger::getRootLogger();
    return 0;
}

Thats it. No other conf files or anything.

The errors are:

   1. BasicConfigurator has not been declared
   2. configure was not declared in this scope
   3. LoggerPtr was not declared in this scope
   4. expected ";" before rootLogger




I am using mingw with eclipse. I downloaded log4cxx, unzipped it. Then I configured eclipse by going to: project properties --> C/C++ general --> Paths and Symbols -->Includes tab --> select GNU C++ --> click add--> enter the log4cxx path. I can see the log4cxx files under "includes". If I control+click a log4cxx header that I included, I can see the code as well.

What could I be doing wrong?

Thanks,
Sylvester

Curt Arnold | 10 Apr 15:06 2009
Picon

Re: Trivial.cpp example not working

It was a little unusual that you were going off such a old tag. The current code is so unlike 0.9.7 which was the best release for a long time but no longer can be supported. 

You might try explicitly namesoace qualifying the classes like

::log4cxx::BasicConfigurator::configure 

Otherwise try running the preprocessor to see what is getting expanded. 

Can't help much over a holiday weekend. 

On Apr 10, 2009, at 7:01 AM, Sylvester Steele <sylvestersteele <at> gmail.com> wrote:

Hi,
I was trying out the the example at https://svn.apache.org/repos/asf/logging/log4cxx/tags/v0_9_6/examples/trivial.cpp. Unfortunately it isn't working yet.

My code looks like:


#include <iostream>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/ndc.h>


using namespace std;
using namespace log4cxx;
using namespace log4cxx::helpers;


int main() {
    BasicConfigurator::configure();
    LoggerPtr rootLogger = Logger::getRootLogger();
    return 0;
}

Thats it. No other conf files or anything.

The errors are:

   1. BasicConfigurator has not been declared
   2. configure was not declared in this scope
   3. LoggerPtr was not declared in this scope
   4. expected ";" before rootLogger




I am using mingw with eclipse. I downloaded log4cxx, unzipped it. Then I configured eclipse by going to: project properties --> C/C++ general --> Paths and Symbols -->Includes tab --> select GNU C++ --> click add--> enter the log4cxx path. I can see the log4cxx files under "includes". If I control+click a log4cxx header that I included, I can see the code as well.

What could I be doing wrong?

Thanks,
Sylvester
Sylvester Steele | 11 Apr 10:52 2009
Picon

Re: Trivial.cpp example not working

I want to get started with Log4Cxx, so I just need an example. Any simple example will do.. Where can I find better examples than this?

Thanks,
Sylvester


Gmane