log4j on jboss - subpackage level - log4j

I have JBoss 6.1 and using jboss-logging.xml
I would like to set different log level for one package, and one his subpackage, example:
- com.foo.bar (in DEBUG)
- com.foo.bar.subpack.subsubpack (in INFO)
I have tried with this:
<logger category="com.foo.bar">
<level name="DEBUG"/>
</logger>
<logger category="com.foo.bar.subpack">
<level name="INFO"/>
</logger>
But in the log I continue to see all the debug message from the class in the subpack

I find the problem: using the constructor Logger.getLogger("PIPPO"), in the xml the category is "PIPPO":
<logger category="PIPPO">
<level name="INFO"/>
</logger>
This tag control the level message of the class

I guess the messages are readen twice by the loggers. Disable additivity :
<logger category="com.foo.bar" additivity="false">
<level name="DEBUG"/>
</logger>
<logger category="com.foo.bar.subpack">
<level name="INFO"/>
</logger>
Edit :
Otherwise, check the name by whitch your are instanciating your logger.
According to https://logging.apache.org/log4j/1.2/manual.html#Logger_hierarchy, if you write Logger.getLogger("PIPPO"), and if the logger with name "PIPPO" does not exist in your configuration(s) file(s), the RootLogger will be instanciated by default.
A logger is said to be an ancestor of another logger if its name followed by a dot is a prefix of the descendant logger name. A logger is said to be a parent of a child logger if there are no ancestors between itself and the descendant logger.
To apply your configuration, you have to instanciate the logger by calling it with a name like "com.foo.bar.subpack.YourClass".

Related

Log4Net at Runtime with Logger not Root

I have a working logger from runtime without using a web.config. I want to do this because I am adding my logger to a DLL I will be distributing. Now I have working version using hierarchy but that is using Root. If I use the web config way of configuring it I can use the following nodes....
<logger name="EventLogger">
<level value="ERROR" />
<appender-ref ref="EventLogAppender" />
</logger>
<logger name="FileLogger">
<level value="INFO" />
<appender-ref ref="FileAppender" />
</logger>
This allows me to call each log when I want to use it. Basically I want to do an info log for the fileappender and eventlog for errors....I then will call them on demand based on what error is generated, like catch errors will be going to eventviewer and specific log calls will be going to fileappender...does anyone have any good runtime code for log4net? I have seen a lot of examples and they all are for root loggers.
This is basically for my dll to allow users to have logs for specific items, errors and logging. Can anyone explain exactly what the MemoryAppender means...

Log4Net logger creating a file when it does not have FileAppender

I've set up log4net to potentially log to three locations: console, rolling file, and a database. I need to be able to turn on and off these three separate locations individually, so I've created a set of loggers, one for each combination. For example...
<logger name="Logfile">
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</logger>
<logger name="Console">
<level value="ALL" />
<appender-ref ref="ConsoleAppender" />
</logger>
<logger name="LogfileConsole">
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
<appender-ref ref="ConsoleAppender" />
</logger>
My root logging level is set to OFF with no appenders used so that the default is no logging whatsoever. HOWEVER... when I run one of the projects that has logging set to the root, meaning it is turned off, a log file still gets created. The file remains empty and no logging is performed, but if I'm using a logger without the RollingFileAppender in it, why is it creating the log file?
I thought it might be because the root was totally empty, so I made a logger called "None" and set the level to OFF and gave it the ConsoleAppender just for appearances sake, and it still created the file.
It's not interfering with the running of the project or impacting performance, but I'd prefer my log folder not end up cluttered with empty log files for apps that shouldn't be logging. I CANNOT figure out why it's creating a file when the current logger does not use file appender. Help?

nservicebus SetLoggingLibrary

I cannot get nservicebus to use a named log4net logger. It seems to only use what is defined in the <root> element.
This works fine
NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
<root>
<level value="ALL"/>
<appender-ref ref="NServiceBusAppender"/>
</root>
But i really like it to use a named definition.
<logger name="NServiceBusLogger">
<appender-ref ref="NServiceBusAppender"/>
</logger>
Is this possible?
On their website they are only showing a sample with the <root> behaviour.
http://docs.particular.net/nservicebus/logging/
All loggers in NServicebus begins with the name "NServiceBus". Have you tried this:
<logger name="NServiceBus">
<appender-ref ref="NServiceBusAppender"/>
</logger>
I guess you need specify the level on the named logger:
<logger name="NServiceBusLogger">
<level value="ALL"/>
<appender-ref ref="NServiceBusAppender"/>
</logger>
(I assume now that the name of the logger is correct.)

Log4net: separate log files for each class

i want to log messages from multiple classes. the problem is that currently i can log all messages into single file.i want to do this class A should log its messages into ALog.txt and class B should log its messages into BLog.txt
please tell me the sample config file for these settings
In addition to the root logger, you can configure individual loggers with their own appenders. Assuming you are calling your loggers ClassA and ClassB you can do:
<root>
<appender-ref ref="CommonAppender" />
</root>
<logger name="ClassA">
<appender-ref ref="AppenderA" />
</logger>
<logger name="ClassB">
<appender-ref ref="AppenderB" />
</logger>
This is further described here.

How to configure a child logger with a lower loglevel than the root level in Log4net

The app I'm working on uses a library that generates a lot of INFO level messages I don't want to log. But the rest of the app and libraries produce INFO level messages I need to log.
How can I setup log4net so that all INFO messages are logged except for one logger that need to log only at WARN or above ? All messages need to be logged in the same files.
Julien
<root>
<level value="INFO" />
<appender-ref ref="someappender" />
</root>
<logger name="AnotherLogger">
<level value="WARN" />
</logger>

Resources