Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Context logging at a class level: msg#00068

apache.logging.log4cxx.user

Subject: Context logging at a class level

Hi,

I have a (hopefully) simple question about getting context information into
my logging.

Say I have a class Agent:

class Agent {
public:
long id() const { return myId_; }
void doSomething();

private:
static LoggerPtr agentLogger_;
};

This agent is connected to by a number of IP clients, and there are a number
of agents in the system (each with their own ID)

I can use NDC to log the IP of the connecting client for all my logging
within the doSomething function, which is good. However I would also like to
include the agent's ID implicitly without having to include it in each call
to .info() or .debug() etc.

So rather than...
agentLogger->info( "Agent " + id() + " processing request" );
(please assume that there is a nice way to concatenate a log4cxx string with
a long, that's merely for ease of reading)

I would rather write
agentLogger->info( "processing request" );

and end up with the same line in my log file, i.e. containing the "Agent 12 "
as context. This would work together with the NDC to show the agent and
client, so the logging may resemble:

1563 192.168.1.1 Agent 12 processing request

This class-context would have to not be on a thread level as multiple threads
may be accessing several agents for the same client IP.

I had thought of creating an extra member for the Agent class, something like

std::string loggingContext_;

and a macro to insert this at the front of any actual logging. Or maybe a
simple class AgentLogger that defers to a static LoggerPtr with context
(this, however, is pretty much the same thing) Both these seem a bit ugly
however, and I was hoping someone would have a more elegant solution for me.

Thank you all for your time,
Ben



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qplus.devel/200...    network.jabber....    debian.qa-packa...    encryption.gpg....    python.dabo.dev...    uclinux.devel/2...    science.mathema...    recreation.pesc...    kernel.ck/2004-...    mozilla.devel.e...    tex.latex.prosp...    ietf.multi6/200...    bbc.cvs/2002-11...    xfree86.newbie/...    jakarta.taglibs...    altlinux.hardwa...    comedi/2002-05/...    horde.bugs/2004...    games.diplomacy...    finance.e-gold....    web.dom.test-su...    lang.ruby.rails...    os.netbsd.devel...    video.gstreamer...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation