Ken wrote:
Hi,
I would like to use log4cxx in my project. My program is a server will have
many fixed clients connected, nearly 2000 clients. I want to write the
log contents for each client in different file, so I will have 2000
log files nearly. This will be very easy to trace the data transfered
between each client with the server, since the log in different file.
So how could I make this with log4cxx or this thought totally wrong?
Thanks in advance.
--
Ken
Hello,
Have you considered using a Nested Diagnostic Context ?
You could store the ip address of your current client in the NDC, and it
will be logged together
with your log messages, but all the log messages would still be in the
same file.
http://logging.apache.org/log4cxx/manual/Introduction.html#NDC
Or you could programmatically create an appender for every client :
class Session {
string m_ipaddress;
LoggerPtr m_logger;
void initlog4cxx();
public:
Session(string ip);
void doSomething();
};
// ====================================================================
Session::Session(string ip) : m_ipaddress (ip)
{
initlog4cxx();
}
// ====================================================================
void Session::initlog4cxx()
{
PatternLayout* layout = new PatternLayout("%d{ISO8601} [%t] %-5p
%-30.30c - %m%n");
RollingFileAppender* appender = new RollingFileAppender(layout,
"/tmp/log_" + m_ipaddress + ".log", false);
appender->activateOptions();
m_logger = Logger::getLogger("org.example.Session." + m_ipaddress);
m_logger->addAppender (appender);
m_logger->info ("some message for ip " + m_ipaddress);
}
// ====================================================================
void Session::doSomething()
{
m_logger->info ("doing something");
}
Of course, you can also combine this with configuration from a
properties file.
Maarten
|
Try Searching:
servers, voip, java, networking, microsoft ...
|
|
|
|