pmt: reformat code, etc.
This commit is contained in:
@@ -14,22 +14,23 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <exception>
|
||||
#include <fcntl.h>
|
||||
#include <functional>
|
||||
#include <libgen.h>
|
||||
#include <libhelper/lib.hpp>
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace Helper {
|
||||
Error::Error(const char *format, ...) {
|
||||
Error::Error(const char* format, ...) {
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@@ -39,19 +40,23 @@ Error::Error(const char *format, ...) {
|
||||
LOGN(HELPER, ERROR) << _message << std::endl;
|
||||
}
|
||||
|
||||
const char *Error::what() const noexcept { return _message.data(); }
|
||||
const char* Error::what() const noexcept { return _message.data(); }
|
||||
|
||||
Logger::Logger(const LogLevels level, const char *func, const char *file,
|
||||
const char *name, const char *source_file, const int line)
|
||||
: _level(level), _function_name(func), _logFile(file), _program_name(name),
|
||||
_file(source_file), _line(line) {}
|
||||
Logger::Logger(const LogLevels level, const char* func, const char* file,
|
||||
const char* name, const char* source_file, const int line)
|
||||
: _level(level),
|
||||
_function_name(func),
|
||||
_logFile(file),
|
||||
_program_name(name),
|
||||
_file(source_file),
|
||||
_line(line) {}
|
||||
|
||||
Logger::~Logger() {
|
||||
if (LoggingProperties::DISABLE) return;
|
||||
char str[1024];
|
||||
snprintf(str, sizeof(str), "<%c> [ <prog %s> <on %s:%d> %s %s] %s(): %s",
|
||||
static_cast<char>(_level), _program_name,
|
||||
basename(const_cast<char *>(_file)), _line, currentDate().data(),
|
||||
basename(const_cast<char*>(_file)), _line, currentDate().data(),
|
||||
currentTime().data(), _function_name, _oss.str().data());
|
||||
|
||||
if (!isExists(_logFile)) {
|
||||
@@ -76,7 +81,7 @@ Logger::~Logger() {
|
||||
}
|
||||
}
|
||||
|
||||
if (FILE *fp = fopen(_logFile, "a"); fp != nullptr) {
|
||||
if (FILE* fp = fopen(_logFile, "a"); fp != nullptr) {
|
||||
fprintf(fp, "%s", str);
|
||||
fclose(fp);
|
||||
} else {
|
||||
@@ -91,30 +96,25 @@ Logger::~Logger() {
|
||||
if (LoggingProperties::PRINT) printf("%s", str);
|
||||
}
|
||||
|
||||
Logger &Logger::operator<<(std::ostream &(*msg)(std::ostream &)) {
|
||||
Logger& Logger::operator<<(std::ostream& (*msg)(std::ostream&)) {
|
||||
_oss << msg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
garbageCollector::~garbageCollector() {
|
||||
for (auto &ptr_func : _cleaners)
|
||||
ptr_func();
|
||||
for (const auto &fd : _fds)
|
||||
close(fd);
|
||||
for (const auto &fp : _fps)
|
||||
fclose(fp);
|
||||
for (const auto &dp : _dps)
|
||||
closedir(dp);
|
||||
for (const auto &file : _files)
|
||||
eraseEntry(file);
|
||||
for (auto& ptr_func : _cleaners) ptr_func();
|
||||
for (const auto& fd : _fds) close(fd);
|
||||
for (const auto& fp : _fps) fclose(fp);
|
||||
for (const auto& dp : _dps) closedir(dp);
|
||||
for (const auto& file : _files) eraseEntry(file);
|
||||
}
|
||||
|
||||
void garbageCollector::delFileAfterProgress(const std::string &_path) {
|
||||
void garbageCollector::delFileAfterProgress(const std::string& _path) {
|
||||
_files.push_back(_path);
|
||||
}
|
||||
void garbageCollector::closeAfterProgress(const int _fd) {
|
||||
_fds.push_back(_fd);
|
||||
}
|
||||
void garbageCollector::closeAfterProgress(FILE *_fp) { _fps.push_back(_fp); }
|
||||
void garbageCollector::closeAfterProgress(DIR *_dp) { _dps.push_back(_dp); }
|
||||
} // namespace Helper
|
||||
void garbageCollector::closeAfterProgress(FILE* _fp) { _fps.push_back(_fp); }
|
||||
void garbageCollector::closeAfterProgress(DIR* _dp) { _dps.push_back(_dp); }
|
||||
} // namespace Helper
|
||||
|
||||
Reference in New Issue
Block a user