I would like to write logs into csv files for every minute, those csv files needs to be kept in different folders i.e., 60 minute log files in first hour folder and another 60 minutes which supposed to be the next hour folder.
When i use DailyRollingFileAppender which results in a exception after completing the particular hour, until the exception occurs files are getting created normally. If i start logging at 12:14 and runs fine up to 12:59 and exception occurs.
#include <unistd.h>
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
// Define static logger variable
LoggerPtr loggerMyMain(Logger::getLogger(""));
LoggerPtr loggerFunctionA(Logger::getLogger(""));
void functionA() {
LOG4CXX_INFO(loggerFunctionA, "Executing functionA.");
usleep(2000);
}
int main() {
int value = 5;
// Load properties style configuration file using PropertyConfigurator
PropertyConfigurator::configure("log4j.properties");
for(int j = 1; j < 10000; j++) {
LOG4CXX_TRACE(
loggerMyMain,
"this is a debug message for detailed code discovery. Value=" << j);
LOG4CXX_DEBUG(loggerMyMain, "this is a debug message.");
LOG4CXX_INFO(loggerMyMain, "this is a info message, ignore. Value=" << j);
LOG4CXX_WARN(loggerMyMain, "this is a warn message, not too bad.");
LOG4CXX_ERROR(loggerMyMain,
"this is a error message, something serious is happening.");
LOG4CXX_FATAL(loggerMyMain, "this is a fatal message!!!");
functionA();
if(j > 9998) j = 1;
}
return 0;
}
Configuration file log4j.properties
:
# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
# Set the name of the file
#log4j.appender.FILE.File=${'folder'/}
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=false
# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug
# Set the append to false, should not overwrite
log4j.appender.FILE.Append=false
# Set the DatePattern
log4j.appender.FILE.DatePattern=yyyy-MM/yyyy-MM-dd/yyyy-MM-dd-HH/yyyy-MM-dd_HH:mm'.''csv'
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
output is:
g++ file.cpp -lapr-1 -laprutil-1 -llog4cxx -o kk
kk@deb:~/logs/logcfg$ ./kk
log4cxx: Exception during rollover
expected output structure
day01-|
|----hour1 |----min1.csv
| |----min2.csv
| |----min60.csv
|----hour-N
|----min1.csv
|----min60.csv