You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by JethroXT <ga...@yahoo.de> on 2008/07/27 19:16:03 UTC

Using independent logs at runtime

Hi,
I have a problem that maybe someone could solve:

I have a network consisting of several nodes that all have to log data
independently.
I don't know the exact number of nodes before runtime, so Loggers (or
appenders) have
to be created at runtime.

What I have tried: 
I use loggers for several other things in my application, so I already have
a properties file
containing some loggers and appenders. So I added one logger for this
purpose and 
let every node add an appender at runtime. Problem is that the logs of all
nodes get
merged in all different node-logfiles, so a node logfiles contains the data
of all other nodes.
I turned additivity off for that logger which didn't seem to solve taht
problem.

Creating a logger (instead of appender) for every node at runtime? If so,
how? I 
didn't find any documentation on the LoggerFactory class and don't know if
this is the indended
purpose for it anyway.

Any ideas? 


-- 
View this message in context: http://www.nabble.com/Using-independent-logs-at-runtime-tp18678394p18678394.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Using independent logs at runtime

Posted by JethroXT <ga...@yahoo.de>.
Glad it helped.

I am not certain I understand your description correctly.  Could you 
provide a working example of the behaviour you describe?

-- 
  Thorbjørn

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Thanks for your helping offer,
yet I think that I just got some things mixed up. Looks like I simply
omitted the properties file and didn't 
understand what I was doing. 
So everything works just like it should. 

Thanks again

-- 
View this message in context: http://www.nabble.com/Using-independent-logs-at-runtime-tp18678394p18707596.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Using independent logs at runtime

Posted by Thorbjørn Ravn Andersen <th...@gmail.com>.
JethroXT skrev  den 28-07-2008 16:31:
>
> Surprisingly this resulted in the desired behaviour. I don't quite know why,
> because there simply aren't any loggers with that names, but I anyhow I get
> independent loggers, add appenders to them by every node and get single
> files with only node-relevant data. Still there is a bad taste about it,
> because I don't know why it works and if it will keep working if I add new
> loggers..
>
> Any ideas?
>
>   
Glad it helped.

I am not certain I understand your description correctly.  Could you 
provide a working example of the behaviour you describe?

-- 
  Thorbjørn

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Using independent logs at runtime

Posted by JethroXT <ga...@yahoo.de>.


Thorbjørn Ravn Andersen wrote:
> 
> JethroXT skrev  den 27-07-2008 19:16:
> Is this at program start time or dynamically changing while running?
> 
> If it is at program start time you can set a system property which can 
> then be expanded in the log4j.properties file.  From 
> PropertyConfigurator javadoc
> 
> "All option /values/ admit variable substitution. The syntax of variable 
> substitution is similar to that of Unix shells. The string between an 
> opening *"${"* and closing *"}"* is interpreted as a key. The value of 
> the substituted variable can be defined as a system property or in the 
> configuration file itself. The value of the key is first searched in the 
> system properties, and if not found there, it is then searched in the 
> configuration file being parsed. The corresponding value replaces the 
> ${variableName} sequence. For example, if |java.home| system property is 
> set to |/home/xyz|, then every occurrence of the sequence |${java.home}| 
> will be interpreted as |/home/xyz|. "
> 
> Is this what you need?
> 
> -- 
>   Thorbjørn
> 
> 

Hi,
first of all thanks for the quick reply.
The number of nodes is indeed clear directly after program start. 

I managed to solve the problem while trying to follow your proposition, yet
the way I did it seems quite unsual to me.
First I thought of letting the nodes set a system-property with their Id and
refer to this
property in the log4j.properties to create independent loggers. However I
first used a usual logger with no
references to any variables (so no $-reference). Then I let every node refer
to it by using Logger.getLogger() BUT using a name for the logger, that
consisted of its name (as in the log4j.properties) AND the specific nodeID. 

Surprisingly this resulted in the desired behaviour. I don't quite know why,
because there simply aren't any loggers with that names, but I anyhow I get
independent loggers, add appenders to them by every node and get single
files with only node-relevant data. Still there is a bad taste about it,
because I don't know why it works and if it will keep working if I add new
loggers..

Any ideas?


-- 
View this message in context: http://www.nabble.com/Using-independent-logs-at-runtime-tp18678394p18689236.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Using independent logs at runtime

Posted by Thorbjørn Ravn Andersen <th...@gmail.com>.
JethroXT skrev  den 27-07-2008 19:16:
> Hi,
> I have a problem that maybe someone could solve:
>
> I have a network consisting of several nodes that all have to log data
> independently.
> I don't know the exact number of nodes before runtime, so Loggers (or
> appenders) have
> to be created at runtime.
>
>   
Is this at program start time or dynamically changing while running?

If it is at program start time you can set a system property which can 
then be expanded in the log4j.properties file.  From 
PropertyConfigurator javadoc

"All option /values/ admit variable substitution. The syntax of variable 
substitution is similar to that of Unix shells. The string between an 
opening *"${"* and closing *"}"* is interpreted as a key. The value of 
the substituted variable can be defined as a system property or in the 
configuration file itself. The value of the key is first searched in the 
system properties, and if not found there, it is then searched in the 
configuration file being parsed. The corresponding value replaces the 
${variableName} sequence. For example, if |java.home| system property is 
set to |/home/xyz|, then every occurrence of the sequence |${java.home}| 
will be interpreted as |/home/xyz|. "

Is this what you need?

-- 
  Thorbjørn