// =========================================================================== // // Filename: logging.cpp // // Description: // // Version: 0.0 // Created: 09/12/2013 03:26:27 PM // Revision: none // Compiler: Tested with g++ // // Author: M. Andy Kass (MAK) // // Organisation: US Geological Survey // // // Email: mkass@usgs.gov // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // =========================================================================== #include "logging.h" namespace formalhaut { std::ostream &operator<<(std::ostream &stream, const Logging &ob) { stream << "Class: Logging\n"; stream << "Output file: " << ob.LogFile << "\n"; stream << "\n"; return stream; } Logging* Logging::New() { return new Logging; } void Logging::Delete() { if (this->outfile.is_open()) { this->outfile.close(); } delete this; } Logging::Logging() { } Logging::~Logging() { } void Logging::CloseLogFile() { if (this->outfile.is_open()) { this->outfile.close(); } } void Logging::WriteLogLine(const std::string line) { this->outfile << line << std::endl; } void Logging::WriteHeader(const std::string& name, const std::string& ver) { this->outfile << name << std::endl; this->outfile << "version " << ver << std::endl << std::endl; this->outfile << "Run began at " << this->GetDateTime() << std::endl << std::endl; } std::string Logging::GetDateTime() { time_t now = time(0); struct tm tstruct; char buf[80]; tstruct = *localtime(&now); strftime(buf,sizeof(buf),"%Y-%m-%d.%X",&tstruct); return buf; } void Logging::WriteCloser() { this->outfile << "Successfully ended at " << this->GetDateTime() << std::endl; this->outfile.close(); } void Logging::WriteDashedLine() { std::string dashes; dashes = "------------------------------------"; dashes = dashes + dashes; this->outfile << dashes << std::endl; } void Logging::SetLogFile(const std::string& fname) { this->LogFile = fname; this->outfile.open(this->LogFile.c_str()); } std::string Logging::GetLogFile() { return this->LogFile; } } // end of namespace formalhaut