Is it possible to use environment variable to specify the desired log level for the log4net based logging system? - log4net

We use log4net for logging. I am wondering if it is possible to use environment variables when specifying the log level. The motivation is simple - our QA folks will not have to edit the config files, they will just set certain environment variable once.
In short:
We do not want to set the log level in the config file to some constant value, because the same build is run by different teams and different teams have different, but rarely changing logging needs. Right now, after every installation, one has to change the config file to suit the specific team needs.
I do not want to implement the logic programmatically, if there is a way to avoid it. If not, I think I know how to do it.
Thanks.

I would have to test it but it looks like you can use environment variables as follows in your config file:
<root>
<level value="${LOGLEVEL}" />
...
</root>
Update:
This does not work for the log level. You can use environment variables for the file name of a file appender but apparently not for the log level...

Related

Hi,I am using log4j in my system.Is there a tag which automatically recognises change of level,so that i dont require to start stop my server

I am using log4j.xml to store my logs.
At runtime I need to change the level at production, and want to execute it by making changes in log4j.xml
I have used maxinterval but it does not reflect once I change my log levels.
I need to find a way to change my logger level at runtime at log4j.aml level.
Is it possible?

How to read level changes from log4j.xml when application is running

I am running a executable jar file, which logs using log4j.xml(version 1.2).
Whenever i change the log level in the xml file, i have to restart the java application for the new log level to reflect.
Can i add some configuration in the log4j.xml so that new log level will be taken into account without application restart?
Thanks,
-Venkat
Log4j 1.x has reached end of life on August 5, 2015. So I would like to recommend you to use log4j 2.x which supports this with the monitorInterval configuration.
However according to the log4j 1.x docs here it does support log level changes runtime.
How can I change log behavior at runtime?
Log behavior can be set using configuration files which are parsed at
runtime. Using configuration files the programmer can define loggers
and set their levels.
The PropertyConfigurator defines a particular format of a
configuration file. See also the examples/Sort.java example and
associated configuration files.
Configuration files can be specified in XML. See log4j.dtd and
org.log4j.xml.DOMConfigurator for more details.
See the various Layout and Appender components for specific
configuration options.
In addition to configuration files, the user may disable all messages
belonging to a set of levels. See next item.

How do I permanently disable yaml files on puppet?

It has never happened before, but all of a sudden my server keeps running out of space because of these puppet reports.
Can reports=none inside the puppet.conf file, auto disable the generation of .yaml report files? Or is there a better way of doing it?
Will we ever need these .yaml files and do they affect anything if I delete them all?
Puppet has fairly good online documentation, including for historic versions of the software. You can find a good overview of the reporting feature here: https://docs.puppetlabs.com/guides/reporting.html. A bit more detail is provided in the relevant section of the manual proper, and the configuration reference provides some detail on the relevant configuration settings.
Some of the configurable aspects of reporting are:
whether agents send reports [the report parameter in the [agent] section of the config file]. This is configured on a per-agent basis. By default, they do send reports.
what the master does with the reports it receives [the reports parameter in the [master] section of the config file]. The default is to use (only) the store report handler, which dumps them to YAML files in the configured report directory.
Can reports=none inside the puppet.conf file, auto disable the generation of .yaml report files?
No 'none' handler is documented, but you can write and plug in custom report handlers, as described in the docs. A none handler ought to be trivial to write, but see below.
Or is there a better way of doing it?
I'd recommend configuring your agents to not send reports in the first place. That should be less work for all involved, human and machine. Do that by setting report = false (note: singlular "report") in the [agent] section of each agent's Puppet configuration file. You may need to restart the agents after.
Will we ever need these .yaml files and do they affect anything if I delete all of them?
They are for your benefit. If you have no use for them, then you can safely delete them.

log4net - configure using multiple configurations

I use the Log4Net as my log tool, everything works really well when the test system just has a single database.
But my real system has more than one database. Different user may have the different database. I want to put the log information into different database according to the current logined user.
But so far as I know. It seems that the Log4Net does't support this topic. It seems the log4Net is configured just "once" in the lifetime.
Is it possible for me to make the log4net select database configuration basing on my information on the fly.
I found the answer:
log4net - configure using multiple configuration files
and this: http://logging.apache.org/log4net/release/manual/repositories.html
The reason I thought that Log4Net only supports one configuration is I did NOT dig. As the content of the above links said: We need to create our own repository for each configuration.
Now everything is working well, and log information goes to different databases now based on the given configuration on the fly as I expected.

Log4J and Java Web Start, how to alternate between different configurations?

i'm starting with Log4J and i want to have a default log4j.properties in our Java Web Start distributed application, which only logs errors and important events.
But if something was wrong in one client i want to have a more detailed log, the way to do this is to define an alternate log4j configuration file in this client. This can be done by specifiying the alternate config file with the log4j.configuration system property.
but... How can i define an system property for this particular client in a java web start launched application? (i know that i can define theese propeties in the .jnlp file, but this affects all clients).
Our users work in windows environment but they often have a restricted permissions computer and they can't acces My Pc->Properties-->Advanced Options-->Enviroment Variables (i'm in a spanish configured computer i don't know the exact names in english).
Can you access to a defined directory on the client disk ?
If you can, you can define a convention : if no configuration file is found in the directory, the default config is used. Else, the specific configuration file is loaded.
You can do that with the PropertyConfigurator class of Log4J :
File log4jConfigFile == new File(conventionLocation);
if(log4jConfigFile.isFile() && log4jConfigFile.exists()) {
PropertyConfigurator.configure(conventionLocation);
} else {
PropertyConfigurator.configure(defaultEmbeddedJarLocation);
}
First off if you are using applets you should use an appender that can write to a remote location so you can actually see the errors without being physically on the local machine that the applet is running. Appender Types. Next, you need to create an appender with a threshold of whatever level you are logging the normal "access" type messages. Set the layout to whatever you desire. Then create another appender with a level of at least the level you log "errors" at as well as its own format that suits your needs as being "more detailed". That way when your code calls an error message it will use that different layout. Log4j is fairly complex but not impossible to understand. Look at the documentation at The log4j site and get your feet wet on some simple logging. After that you should be able to modify the code to get what you desire.

Resources