![]() |
|
|
|
#1 |
|
I'm logging hibernate HQL queries to a log file (file1.log).
The problem is I have a thread which logs to a different file (file2.log). So I want to change appenders at runtime so that 2 different threads would simultaniously write hibernate loggs to a different file. I'm not sure if this will work because I don't know how log4j getLogger is implemented (if it is singleton or not). The idea is to call the code below as needed. Does anyone have any suggestions about this? Thanks in advance. ------------------------------------------------------- public static void setHibernateLogAppender(Logger logger) { Logger.getLogger("org.hibernate.SQL").removeAllApp enders(); while(logger.getAllAppenders().hasMoreElements()) Logger.getLogger("org.hibernate.SQL").addAppender( (Appender)logger.getAllAppenders().nextElement()); } ------------------------------------------------------ Uli Kunkel |
|
|
|
|
#2 |
|
Posts: n/a
|
Uli Kunkel wrote:
> I'm logging hibernate [sic] HQL queries to a log file (file1.log). > > The problem is I have a thread which logs to a different file (file2.log). > > So I want to change appenders at runtime so that 2 different threads > would simultaniously write hibernate [sic] loggs to a different file. > > I'm not sure if this will work because I don't know how log4j getLogger > is implemented (if it is singleton or not). > The idea is to call the code below as needed. > > Does anyone have any suggestions about this? A few minutes with the log4j documentation shows that its loggers are identified by the name given them, usually a class name. You configure loggers hierarchically - one configured for your Hibernate client can have its own destination regardless of thread by the choice of its name. -- Lew Lew |
|
|
|
#3 |
|
Posts: n/a
|
Uli Kunkel wrote:
> I'm logging hibernate HQL queries to a log file (file1.log). > > The problem is I have a thread which logs to a different file (file2.log). > > So I want to change appenders at runtime so that 2 different threads > would simultaniously write hibernate loggs to a different file. > > I'm not sure if this will work because I don't know how log4j getLogger > is implemented (if it is singleton or not). > The idea is to call the code below as needed. > > Does anyone have any suggestions about this? > ------------------------------------------------------- > public static void setHibernateLogAppender(Logger logger) { > Logger.getLogger("org.hibernate.SQL").removeAllApp enders(); > > while(logger.getAllAppenders().hasMoreElements()) > Logger.getLogger("org.hibernate.SQL").addAppender( (Appender)logger.getAllAppenders().nextElement()); > > } > ------------------------------------------------------ Your problem is not easily solvable. Logger.getLogger("org.hibernate.SQL") will under normal circumstances return the same logger for both threads. If the two threads are not logging at the same time, then you may be able to change config at runtime (I have not checked whether your code is good or not). But it is not a good solution. I think a better solution would be a custom appender that are able to log to two files depending on threads and then at runtime config that appender to match threads with files. That will allow concurrent usage. Arne Arne Vajhøj |
|
|
|
#4 |
|
Posts: n/a
|
Arne Vajhøj wrote:
> Uli Kunkel wrote: >> I'm logging hibernate HQL queries to a log file (file1.log). >> >> The problem is I have a thread which logs to a different file >> (file2.log). >> >> So I want to change appenders at runtime so that 2 different threads >> would simultaniously write hibernate loggs to a different file. >> >> I'm not sure if this will work because I don't know how log4j >> getLogger is implemented (if it is singleton or not). >> The idea is to call the code below as needed. >> >> Does anyone have any suggestions about this? > >> ------------------------------------------------------- >> public static void setHibernateLogAppender(Logger logger) { >> Logger.getLogger("org.hibernate.SQL").removeAllApp enders(); >> >> while(logger.getAllAppenders().hasMoreElements()) >> Logger.getLogger("org.hibernate.SQL").addAppender( (Appender)logger.getAllAppenders().nextElement()); >> >> } >> ------------------------------------------------------ > > Your problem is not easily solvable. > > Logger.getLogger("org.hibernate.SQL") will under normal circumstances > return the same logger for both threads. > > If the two threads are not logging at the same time, then > you may be able to change config at runtime (I have not checked > whether your code is good or not). > > But it is not a good solution. > > I think a better solution would be a custom appender > that are able to log to two files depending on threads > and then at runtime config that appender to match threads > with files. > > That will allow concurrent usage. > > Arne I didn't have time to test my idea yet, but as I see it's not gonna work. I'll check if the custom appender is relatively easy to implement.. Uli Kunkel |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can't print multiple copies in XP but can in 2000 on a client/serv | =?Utf-8?B?U3VibWl0MnM=?= | Windows 64bit | 1 | 04-17-2007 07:16 PM |
| Broadband ? | Sam | Computer Support | 38 | 11-06-2004 03:02 AM |
| Re: Broadband ? | Kadaitcha Man | Computer Information | 27 | 11-06-2004 03:02 AM |
| SYMANTEC SECURITY ADVISORIES | sam1967@hetnet.nl | Computer Security | 2 | 02-14-2004 06:07 PM |
| Deluged with multiple copies, sometimes, when using yahoo mail to check POP mail | dakota7 | Computer Support | 3 | 10-05-2003 10:31 PM |