How to exclude a single Class from a Log4j Logger / Appender?

Simply configure your fifth class to use the log-level OFF: log4j.logger.com.example=INFO, MyAppender log4j.logger.com.example.FifthClass=OFF Actually I suggest you don’t set it to OFF, but to FATAL. ERROR or even WARN instead. The main reason to want to ignore logging from some class is usually if it logs to much (more than is useful and makes it … Read more

How to roll the log file on startup in logback

None of the other suggestions was appropriate for my situation. I didn’t want to use a size-and-time-based solution, because it requires configuring a MaxFileSize, and we are using a strictly time-based policy. Here is how I accomplished rolling the file on startup with a TimeBasedRollingPolicy: @NoAutoStart public class StartupTimeBasedTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { @Override public void … Read more

How to create my own Appender in log4j?

Update: the provided solution is valid for Log4J 1.x . If you’re looking for 2.x versions, take a look at this article: How to create a custom appender in log4j2 You should extend AppenderSkeleton class, that (quoting javadoc) “provides the code for common functionality, such as support for threshold filtering and support for general filters.” … Read more

Log4Net, how to add a custom field to my logging

1) Modify the command text: INSERT INTO Log4Net ([Date],[Thread],[Level],[Logger],[Message],[Exception],[MyColumn]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @CustomColumn) 2) Add the parameter definition for the custom column: <parameter> <parameterName value=”@CustomColumn”/> <dbType value=”String” /> <size value=”255″ /> <layout type=”log4net.Layout.PatternLayout”> <conversionPattern value=”%property{CustomColumn}” /> </layout> </parameter> 3) Then use one of log4net’s contexts to transfer values to the parameter: … Read more

log4j: Log output of a specific class to a specific appender

An example: log4j.rootLogger=ERROR, logfile log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender log4j.appender.logfile.datePattern=’-‘dd’.log’ log4j.appender.logfile.File=log/radius-prod.log log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%-6r %d{ISO8601} %-5p %40.40c %x – %m\n log4j.logger.foo.bar.Baz=DEBUG, myappender log4j.additivity.foo.bar.Baz=false log4j.appender.myappender=org.apache.log4j.DailyRollingFileAppender log4j.appender.myappender.datePattern=’-‘dd’.log’ log4j.appender.myappender.File=log/access-ext-dmz-prod.log log4j.appender.myappender.layout=org.apache.log4j.PatternLayout log4j.appender.myappender.layout.ConversionPattern=%-6r %d{ISO8601} %-5p %40.40c %x – %m\n

Very simple log4j2 XML configuration file using Console and File appender

<?xml version=”1.0″ encoding=”UTF-8″?> <Configuration status=”INFO”> <Appenders> <Console name=”Console” target=”SYSTEM_OUT”> <PatternLayout pattern=”%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} – %msg%n” /> </Console> <File name=”MyFile” fileName=”all.log” immediateFlush=”false” append=”false”> <PatternLayout pattern=”%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} – %msg%n”/> </File> </Appenders> <Loggers> <Root level=”debug”> <AppenderRef ref=”Console” /> <AppenderRef ref=”MyFile”/> </Root> </Loggers> </Configuration> Notes: Put the following content in your configuration file. Name the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)