Browse Source

Implemented adding datestamp to log file when Append is specified in

the configuration.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@21 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 years ago
parent
commit
069c987b16
3 changed files with 98 additions and 6 deletions
  1. 20
    4
      Common/Utility.cpp
  2. 62
    2
      Common/UtilityConfig.cpp
  3. 16
    0
      Common/UtilityConfig.hpp

+ 20
- 4
Common/Utility.cpp View File

@@ -91,7 +91,21 @@ Utility::ReadLastPartOfFile(std::string File, long Size) {
throw std::runtime_error(Temp);
}
Input.seekg(Size, ios_base::end);
std::streampos FileSize;
FileSize = Input.tellg();
Input.seekg(0, ios_base::end);
FileSize = Input.tellg() - FileSize;
if (FileSize > Size) {
Input.seekg(-Size, ios_base::end);
} else {
Input.seekg(0, ios_base::beg);
}
std::ostringstream Output;
@@ -104,9 +118,11 @@ Utility::ReadLastPartOfFile(std::string File, long Size) {
if (Output.bad() || Output.fail()) {
std::string Temp;
Temp = "Error " + File;
Temp += ": ";
Temp += strerror(errno);
Temp = "Error reading last part of file " + File;
Temp += ". Content read: '";
Input.close();
Temp += Output.str();
Temp += "'";
throw std::runtime_error(Temp);
}

+ 62
- 2
Common/UtilityConfig.cpp View File

@@ -280,7 +280,11 @@ UtilityConfig::GetLogPath(void) {
std::string
UtilityConfig::GetStatusSecondLogFileName(void) {
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.second.log";
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.second";
AppendDatestampToLogFileName(&FileName);
FileName += ".log";
if (CFGData.Scan_XML_Mode) {
@@ -295,7 +299,11 @@ UtilityConfig::GetStatusSecondLogFileName(void) {
std::string
UtilityConfig::GetStatusMinuteLogFileName(void) {
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.minute.log";
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.minute";
AppendDatestampToLogFileName(&FileName);
FileName += ".log";
if (CFGData.Scan_XML_Mode) {
@@ -307,6 +315,41 @@ UtilityConfig::GetStatusMinuteLogFileName(void) {
}
void
UtilityConfig::AppendDatestampToLogFileName(std::string *FileBaseName) {
if (CFGData.Scan_XML_Rotate ||
CFGData.Status_MinuteReport_Append_OnOff ||
CFGData.Status_SecondReport_Append_OnOff) {
char TimestampBuffer[20];
tm *BrokenDownTime;
time_t Timestamp;
time(&Timestamp);
if (CFGData.Logs_Rotation_LocalTime_OnOff) {
BrokenDownTime = gmtime(&Timestamp);
} else {
BrokenDownTime = localtime(&Timestamp);
}
snprintf(TimestampBuffer, sizeof TimestampBuffer, "%04d%02d%02d",
BrokenDownTime->tm_year+1900,
BrokenDownTime->tm_mon+1,
BrokenDownTime->tm_mday);
*FileBaseName += ".";
*FileBaseName += TimestampBuffer;
}
}
string
UtilityConfig::GetIdentityFileName(void) {
@@ -393,6 +436,23 @@ UtilityConfig::LoadInfo(){
}
void
UtilityConfig::LoadCredentials(void) {
if(0 < CFGData.node_identity.length()) { // If an identity path was provided
ConfigurationData Identity(CFGData.node_identity.c_str()); // then get the data from that file.
ConfigurationElement IdentityReader("snf"); // Create an Identity reader and
IdentityReader // configure it.
.Element("identity")
.Attribute("licenseid", CFGData.node_licenseid)
.Attribute("authentication", CFGData.node_authentication)
.End("identity")
.End("snf");
IdentityReader.interpret(Identity); // Then read the data.
}
}
UtilityConfig::StatusCheckMethod
UtilityConfig::GetPreferredStatusCheckMethod(void) {

+ 16
- 0
Common/UtilityConfig.hpp View File

@@ -117,6 +117,14 @@ public:
// \returns the status.minute log file name.
std::string GetStatusMinuteLogFileName(void);
/// Append the datestamp to the log file name if configured.
//
// \param[in, out] FileBaseName is the log file name up to and not
// including any datestamp.
//
void AppendDatestampToLogFileName(std::string *FileBaseName);
/// Get the identity file name.
//
// \returns the identity file name.
@@ -163,6 +171,14 @@ public:
//
void LoadInfo(void);
/// Load the credentials from the identity.xml file.
//
// This method loads the license ID and authentication from the
// identity.xml file specified in the previously-loaded
// configuration.
//
void LoadCredentials(void);
/// Postfix main.cf file path.
std::string PostfixMainCfPath;

Loading…
Cancel
Save