I have a problem ; security requirement i have java swing app that have logging files generated with log4j for support issues in case of tracking a bug.
I have to ecrypt/cypher/secure the files so the client cant open them and see them (at least not as human readable way) and at the same time when support tech team take these files they will know how to read (decrypt) them .
I did a lot of searches and i tried my best option i found which is build custom appender by extending SkeletonAppender
.
Now know that i have log4j working great as below configuration, but i created new class to encrypt it but i cant get it work even with simple setup it dose not create the file , so i can continue in the ecnryption part.
Any help , links are good.
Working...version
<appender name="cache" class="com.MyAppender">
<param name="Threshold" value="ALL" />
<param name="ImmediateFlush" value="true" />
<param name="File" value="${home}/logs/cache.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="ALL" />
<param name="Encoding" value="UTF-8" />
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%-5p %d{MMM-dd-yyyy HH:mm:ss,SSS} %c{1} - %m%n" />
</layout>
</appender>
Not Working...version
<appender name="cache" class="com.MyAppender">
<param name="Threshold" value="ALL" />
<param name="ImmediateFlush" value="true" />
<param name="File" value="${home}/logs/cache.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="ALL" />
<param name="Encoding" value="UTF-8" />
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern"
value="${home}/logs/cache.%d{yyyy-MM-dd-HH}.gz" />
<param name="ActiveFileName" value="${home}/logs/cache.log" />
</rollingPolicy>
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern"
value="%-5p %d{MMM-dd-yyyy HH:mm:ss,SSS} %c{1} - %m%n" />
</layout>
</appender>
The simple class test
package com.MyAppender;
import org.apache.log4j.spi.LoggingEvent;
public class MyAppender extends org.apache.log4j.RollingFileAppender {
private String file;
private boolean initialized = false;
private String baseFileName = null;
// private static final Log log = LogFactory.getLog(MyAppender.class);
/**
*
* write to ActivityLog
*
* @param event
* logging event invoked.
*
*/
@Override
protected void subAppend(LoggingEvent event) {
if (!initialized) {
createNewFile();
}
synchronized (this) {
super.subAppend(event);
}
}
/**
*
* create a new ActivityLog File
*
*/
public void createNewFile() {
try {
baseFileName = file;
super.setFile(baseFileName);
super.activateOptions();
initialized = true;
} catch (Exception e) {
// log.error("*#*Error in configuration of log4j params,unable to create ActivityLog file");
}
}
/**
*
* invokes File Appender's activateOptions() which controls the creation of
* log files.
*
*/
@Override
public void activateOptions() {
super.setFile(file);
super.activateOptions();
}
/**
*
* Close and rename the current ActivityLog file and reset counter and
* timestamp.
*
*/
public void rollOver() {
closeFile();
initialized = false;
}
@Override
public void setFile(String file) {
this.file = file;
}
}
Then i plan to implement the code in Cipher OutputStream
rollingPolicy
tag in the log4j.xml how to include it *i will update my code * – SirmonsEncoder
which decorates theOutputStream
with yourCypherOutputStream
: logback.qos.ch/manual/encoders.html – Rationale