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

throw std::runtime_error(Temp); 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; std::ostringstream Output;
if (Output.bad() || Output.fail()) { if (Output.bad() || Output.fail()) {
std::string Temp; 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); throw std::runtime_error(Temp);
} }

+ 62
- 2
Common/UtilityConfig.cpp View File

std::string std::string
UtilityConfig::GetStatusSecondLogFileName(void) { 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) { if (CFGData.Scan_XML_Mode) {
std::string std::string
UtilityConfig::GetStatusMinuteLogFileName(void) { 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) { if (CFGData.Scan_XML_Mode) {
} }
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 string
UtilityConfig::GetIdentityFileName(void) { UtilityConfig::GetIdentityFileName(void) {
} }
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::StatusCheckMethod
UtilityConfig::GetPreferredStatusCheckMethod(void) { UtilityConfig::GetPreferredStatusCheckMethod(void) {

+ 16
- 0
Common/UtilityConfig.hpp View File

// \returns the status.minute log file name. // \returns the status.minute log file name.
std::string GetStatusMinuteLogFileName(void); 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. /// Get the identity file name.
// //
// \returns the identity file name. // \returns the identity file name.
// //
void LoadInfo(void); 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. /// Postfix main.cf file path.
std::string PostfixMainCfPath; std::string PostfixMainCfPath;

Loading…
Cancel
Save