During log renaming process, some log files are getting missed

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
vignesh
Posts: 14
Joined: Mon, 2020-01-20, 11:44

During log renaming process, some log files are getting missed

#1 Post by vignesh »

Hi,

I have created a log file using DCMTK.

Below is the sample code:

Code: Select all

#include <boost/dll.hpp>
#include <boost/filesystem.hpp>
#include <dcmtk/oflog/oflog.h>
#include <dcmtk/oflog/configrt.h>
#include "dcmtk/config/osconfig.h"
#include "dcmtk/oflog/oflog.h"

using namespace std;
using namespace dcmtk::log4cplus;
extern OFLogger sample_logger;

#define LINFO(msg) OFLOG_INFO(sample_logger, msg)
#define LDEBUG(msg) OFLOG_DEBUG(sample_logger, msg)
#define LERROR(msg) OFLOG_ERROR(sample_logger, msg)
#define LWARN(msg) OFLOG_WARN(sample_logger, msg)
#define LTRACE(msg) OFLOG_TRACE(sample_logger, msg)
#define LFATAL(msg) OFLOG_FATAL(sample_logger, msg)
 
class LogHandler
{
 public:
 	std::string logLevel;
	void InitializeLogger(std::string fileName);
	void SetLogProperties(helpers::Properties& props, std::string fileName, std::string logLevel);
};

void  SetLogProperties(helpers::Properties& props, std::string fileName, std::string logLevel)
{
#define SET(propertyKey, propertyValue) props.setProperty(propertyKey, propertyValue)
 	static const char* pattern = "[%-6i][%-6t][%D{%Y-%m-%d %H:%M:%S.%q}] %-5p: %m%n";
	SET("log4cplus.logger.Service", "ALL");
	SET("log4cplus.logger.Session", "ALL");
	SET("log4cplus.appender.logfile", "log4cplus::RollingFileAppender");
	if (logLevel == "debug")
	{
		SET("log4cplus.rootLogger", "DEBUG, console , logfile");
		SET("log4cplus.appender.console", "log4cplus::ConsoleAppender");
		SET("log4cplus.appender.console.ImmediateFlush", "true");
		SET("log4cplus.appender.console.layout", "log4cplus::PatternLayout");
		SET("log4cplus.appender.console.layout.ConversionPattern", pattern);
		SET("log4cplus.appender.logfile.MaxFileSize", "5MB");
	}
	else
	{
		SET("log4cplus.rootLogger", "DEBUG, logfile");
		SET("log4cplus.appender.logfile.MaxFileSize", "3MB");
	}
	SET("log4cplus.appender.logfile.Append", "true");
	SET("log4cplus.appender.logfile.ImmediateFlush", "true");
	SET("log4cplus.appender.logfile.MaxBackupIndex", "10");
	SET("log4cplus.appender.logfile.File", fileName.c_str());
 	SET("log4cplus.appender.logfile.layout", "log4cplus::PatternLayout");
	SET("log4cplus.appender.logfile.layout.ConversionPattern", pattern);
 #undef SET
}
 
void InitializeLogger(std::string fileName)
{
	helpers::Properties props(DCMTK_LOG4CPLUS_EXPORT(""));
	if (props.size() == 0)
		SetLogProperties(props, fileName, "debug");
 	unsigned int flags = 0;
	flags |= PropertyConfigurator::fRecursiveExpansion;

	flags |= PropertyConfigurator::fShadowEnvironment;
 	PropertyConfigurator conf(props, Logger::getDefaultHierarchy(), flags);
	conf.configure();
 	Logger root = Logger::getRoot();
	root.setLogLevel(OFLogger::INFO_LOG_LEVEL);
 	OFLog::reconfigure();
}

int main()
{
	InitializeLogger("D:/log/sample.log");
	// here I have read a json file and print the same
	return 0;
}
The log file's maximum size is 5MB. When the log file reaches 5MB, a backup log file is created, named Sample.log.1. I have set the maximum backup file count to 100, meaning the following log files will be generated:

Code: Select all

Sample.log.1
Sample.log.2
Sample.log.3
...
Sample.log.98
Sample.log.99
Sample.log.100
Once 100 backup files are created, and the application is still running, the oldest file (Sample.log.100) will be deleted. The other files will be renamed as follows:

Sample.log.99 is renamed to Sample.log.100
Sample.log.98 is renamed to Sample.log.99
Sample.log is renamed to Sample.log.1
However, during this renaming process, some log files are getting missed or lost.

I have attached collapsed log files screen shot.

https://drive.google.com/file/d/1RKN32L ... drive_link

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest