|
@@ -16,6 +16,10 @@
|
|
|
|
|
|
|
|
using namespace logging;
|
|
using namespace logging;
|
|
|
|
|
|
|
|
|
|
+namespace logging {
|
|
|
|
|
+ level level_from_string(std::string const & value);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
class file_appender : public appender {
|
|
class file_appender : public appender {
|
|
|
public:
|
|
public:
|
|
|
static std::shared_ptr<appender> create(properties const&);
|
|
static std::shared_ptr<appender> create(properties const&);
|
|
@@ -29,12 +33,21 @@ private:
|
|
|
std::ofstream out_;
|
|
std::ofstream out_;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-static bool is_append(properties const & props) {
|
|
|
|
|
- return props.contains("append") && props["append"];
|
|
|
|
|
-}
|
|
|
|
|
|
|
+using namespace logging::property;
|
|
|
|
|
+properties const DEFAULT_FILE_APPENDER{_obj({
|
|
|
|
|
+ {"immediateFlush", _v(true)},
|
|
|
|
|
+ {"threshold", _v("ERROR")},
|
|
|
|
|
+ {"filename", {}}, // Will throw if accessed
|
|
|
|
|
+ {"fileAppend", _v(true)}/*,
|
|
|
|
|
+ {"bufferedIO", _v(false)},
|
|
|
|
|
+ {"bufferSize", _v(8192)}*/
|
|
|
|
|
+})};
|
|
|
|
|
|
|
|
std::shared_ptr<appender> file_appender::create(properties const & props) {
|
|
std::shared_ptr<appender> file_appender::create(properties const & props) {
|
|
|
- file_appender app(props["file"], is_append(props));
|
|
|
|
|
|
|
+ properties const actual = DEFAULT_FILE_APPENDER.mergedWith(props);
|
|
|
|
|
+ file_appender app(actual["filename"], actual["fileAppend"]);
|
|
|
|
|
+ app.flush_immediately_ = actual["immediateFlush"];
|
|
|
|
|
+ app.min_log_level = level_from_string(actual["threshold"]);
|
|
|
return std::make_shared<file_appender>(std::move(app));
|
|
return std::make_shared<file_appender>(std::move(app));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -47,9 +60,7 @@ file_appender::file_appender(const std::string& fname, bool append)
|
|
|
|
|
|
|
|
void file_appender::write(std::string const & msg) {
|
|
void file_appender::write(std::string const & msg) {
|
|
|
out_ << msg;
|
|
out_ << msg;
|
|
|
- if (flush_immediately_) {
|
|
|
|
|
- flush();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (flush_immediately_) { flush(); }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void file_appender::flush() { out_.flush(); }
|
|
void file_appender::flush() { out_.flush(); }
|