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

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: How to use SocketAppender?

You can run the server using java -classpath log4j.jar org.apache.log4j.net.SimpleSocketServer 4712 log4j-server.properties The SimpleSocketServer receives logging events sent to the specified port number by the remote SocketAppender, and logs them as if they were generated locally, according to the configuration you supply in log4j-server.properties. It’s up to you to configure the relevant console/file/rolling file appenders … 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

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