You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Ning Zhao <nz...@hacon.de> on 2008/06/09 11:49:56 UTC

how would a wrapper for Log4cxx best look like

Hi all,

I'm trying to write a thin wrapper for log4cxx for my own application, 
so that:

1. Instead of including log4xx-specific headers, I only need to include 
a MyAppLogging.h in each cpp of my source code.
2. For performance's sake, I consider the " 
if(logger->isXxxxxEnabled())" condition check should be used everywhere 
in my logging code. I want to just say "MyAppLog_INFO(logger, "some 
logging info")", and get "if (logger->isInfoEnabled()) 
LOG4CXX_INFO(logger, "some logging info...")" from my wrapper.
3. In my thin wrapper, all method calls would be simply directed to the 
Log4cxx implementation.

I am now studying the source code of apache.commons.logging and want to 
write a C++ clone with my own add-ons. I'm new to C++, and it seems that 
the log4cxx implementation is a bit different from the log4j way. Above 
all, the smart pointers, templates....How would a thin bridge for 
log4cxx best look like? Any tricky points caused by the smart pointers 
and templates I should pay attention to? Any hint would be highly 
appreciated! Thank you very much in advance!


Best Regards,
Ellen N. Zhao
-- 

HaCon Ingenieurgesellschaft mbH
Lister Str. 15
30163 Hannover
Germany/Deutschland
Tel. +49 511 33699-363
Fax. +49 511 33699-99
Email: ning.zhao@hacon.de
http://www.hacon.de

Registry Court/Amtsgericht Hannover HRB 1712
Managing Directors/Geschäftsführer: Michael Frankenberg,
Dr.-Ing. Marian Gaidzik, Dr.-Ing. Werner Kretschmer,
Werner Sommerfeld, Dr.-Ing. Volker Sustrate, Peter Talke 


Re: How to set a FileAppender to STDOUT?

Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
Peter Steele wrote:
> Our developers can set the log filename through an environment variable.
> I wanted to find an option that let them dump their logs to stdout,
> simply by using a "magic" filename, as you can do in log4j...
> 

I see. While lots of development testing options come to my mind from having 
them specify an alternate configuration file to using named pipes and the screen 
program if you can only have one console, none of them include 'System.out'.

I hope you find something workable for your team.

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026

RE: How to set a FileAppender to STDOUT?

Posted by Peter Steele <ps...@maxiscale.com>.
Our developers can set the log filename through an environment variable.
I wanted to find an option that let them dump their logs to stdout,
simply by using a "magic" filename, as you can do in log4j...

-----Original Message-----
From: Jacob L. Anawalt [mailto:janawalt@geckosoftware.com] 
Sent: Wednesday, June 11, 2008 4:09 PM
To: Log4CXX User
Subject: Re: How to set a FileAppender to STDOUT?

Peter Steele wrote:
> Changing to ConsoleAppender isn't an option in our case
unfortunately...
> 

Would you mind sharing why it's not an option? I just see the ends of
writing to 
stdout and must be missing some critical difference.

Thank you,
-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026

Re: How to set a FileAppender to STDOUT?

Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
Peter Steele wrote:
> Changing to ConsoleAppender isn't an option in our case unfortunately...
> 

Would you mind sharing why it's not an option? I just see the ends of writing to 
stdout and must be missing some critical difference.

Thank you,
-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026

RE: How to set a FileAppender to STDOUT?

Posted by Peter Steele <ps...@maxiscale.com>.
>Here's my un-magic invocation:
>
><appender name="FILE" class="org.apache.log4j.ConsoleAppender">

Changing to ConsoleAppender isn't an option in our case unfortunately...

Thanks for the reply...


Re: How to set a FileAppender to STDOUT?

Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
Peter Steele wrote:
> which works in log4j but this just creates a file called System.out in
> log4cxx. What's the magic formula?

Here's my un-magic invocation:

<appender name="FILE" class="org.apache.log4j.ConsoleAppender">
...

I hadn't thought to try this, so I looked it up for you. The API docs for 
FileAppender say:

Note that the special values "System.out" or "System.err" are no longer honored.

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026

Re: How to set a FileAppender to STDOUT?

Posted by Curt Arnold <ca...@apache.org>.
On Jun 11, 2008, at 1:34 PM, Peter Steele wrote:

> What do I need to specify in the File parameter to mean STDOUT? I have
> this:
>
>  <appender name="FILE" class="org.apache.log4j.FileAppender">
>    <param name="File"   value="System.out"/>
>  ...
>
> which works in log4j but this just creates a file called System.out in
> log4cxx. What's the magic formula?
>

The log4cxx API comments are a copy from the log4j API comments,  
log4cxx probably never supported the special values.  Don't know  
exactly when support was removed from log4j, but many years ago and  
maybe at the switch from log4j 1.1 to log4j 1.2.  If it is really  
important to you, then you may need to write a custom appender.

RE: How to set a FileAppender to STDOUT?

Posted by Peter Steele <ps...@maxiscale.com>.
>In Java, stdout is normally accessed using a console appender. Why are
you using this construct in the first place?

In the end it looks that we're not going to need to do this after all so
it is a moot point...

Peter

 


Re: How to set a FileAppender to STDOUT?

Posted by Jo...@kisters.de.
In Java, stdout is normally accessed using a console appender. Why are you 
using this construct in the first place?

Mit freundlichen Grüßen / Regards
Johannes Frank




"Peter Steele" <ps...@maxiscale.com> 
11.06.2008 20:34
Please respond to
"Log4CXX User" <lo...@logging.apache.org>


To
"Log4CXX User" <lo...@logging.apache.org>
cc

Subject
How to set a FileAppender to STDOUT?






What do I need to specify in the File parameter to mean STDOUT? I have
this:

  <appender name="FILE" class="org.apache.log4j.FileAppender">
    <param name="File"   value="System.out"/>
  ...

which works in log4j but this just creates a file called System.out in
log4cxx. What's the magic formula?




How to set a FileAppender to STDOUT?

Posted by Peter Steele <ps...@maxiscale.com>.
What do I need to specify in the File parameter to mean STDOUT? I have
this:

  <appender name="FILE" class="org.apache.log4j.FileAppender">
    <param name="File"   value="System.out"/>
  ...

which works in log4j but this just creates a file called System.out in
log4cxx. What's the magic formula?


Re: how would a wrapper for Log4cxx best look like

Posted by Dale King <da...@gmail.com>.
On Mon, Jun 9, 2008 at 5:49 AM, Ning Zhao <nz...@hacon.de> wrote:
> Hi all,
>
> I'm trying to write a thin wrapper for log4cxx for my own application, so
> that:
>
> 1. Instead of including log4xx-specific headers, I only need to include a
> MyAppLogging.h in each cpp of my source code.

In most places in the code that are doing logging you only have to
include one header <log4cxx\Logger.h>. I see no reason to eliminate
that.

> 2. For performance's sake, I consider the " if(logger->isXxxxxEnabled())"
> condition check should be used everywhere in my logging code. I want to just
> say "MyAppLog_INFO(logger, "some logging info")", and get "if
> (logger->isInfoEnabled()) LOG4CXX_INFO(logger, "some logging info...")" from
> my wrapper.

You aren't gaining any performance. LOG4CXX_INFO already does the if.

> 3. In my thin wrapper, all method calls would be simply directed to the
> Log4cxx implementation.

So what is the purpose of the wrapper?

> I am now studying the source code of apache.commons.logging and want to
> write a C++ clone with my own add-ons.

For what purpose? apache.commons.logging is actually considered bad by
some (See http://www.qos.ch/logging/thinkAgain.jsp for the opinion of
the creator of log4j).

The main reason for the existence of commons logging is to provide
pluggability between different logging frameworks. Do you have another
framework you want to plug in instead of log4cxx.

There might be a reason for a pluggable wrapper if you were writing a
library to be used by others and did not want to tie it to a
particular logger and instead let the user of the library implement
some logging interface.

> I'm new to C++, and it seems that the
> log4cxx implementation is a bit different from the log4j way. Above all, the
> smart pointers, templates....

That is mostly because of the differences between Java and C++. They
are there to make log4cxx more like log4j.

> How would a thin bridge for log4cxx best look
> like? Any tricky points caused by the smart pointers and templates I should
> pay attention to? Any hint would be highly appreciated! Thank you very much
> in advance

I think you first need to figure out why you want a wrapper.

-- 
Dale King