@@ -8,8 +8,6 @@ C++ YAML parser/reader and writer of *.yaml/*.yml files with keeping user format
88
99include files:
1010
11- - src.wsjcpp/wsjcpp_core/wsjcpp_core.h
12- - src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp
1311- src/wsjcpp_yaml.cpp
1412- src/wsjcpp_yaml.h
1513
@@ -28,20 +26,33 @@ In you main file configure logger:
2826#include < string.h>
2927#include < iostream>
3028#include " wsjcpp_yaml.h"
31- #include " wsjcpp_core.h"
3229
30+ class MyLogger : public IWsjcppYamlLog {
31+ public:
32+ // IWsjcppYamlLog
33+ virtual void err(const std::string &TAG, const std::string &sMessage) override {
34+ std::cerr << TAG << " [ error] : " << sMessage << std::endl;
35+ };
36+ virtual void throw_err(const std::string &TAG, const std::string &sMessage) override {
37+ std::cerr << TAG << " [ critical_error] : " << sMessage << std::endl;
38+ throw std::runtime_error(TAG + " [ critical_error] : " + sMessage);
39+ };
40+ virtual void warn(const std::string &TAG, const std::string &sMessage) override {
41+ std::cerr << TAG << " [ warn] : " << sMessage << std::endl;
42+ };
43+ virtual void info(const std::string &TAG, const std::string &sMessage) override {
44+ std::cout << TAG << " [ info] : " << sMessage << std::endl;
45+ };
46+ };
3347
3448int main(int argc, char* argv[ ] ) {
3549 std::string TAG = "MAIN";
3650 std::string appLogPath = ".logs";
37- WsjcppLog::setLogDirectory(appLogPath);
38- if (!WsjcppCore::dirExists(appLogPath)) {
39- WsjcppCore::makeDir(appLogPath);
40- }
41- WsjcppLog::info(TAG, "Hello!");
51+ MyLogger * pLogger = new MyLogger();
4252
4353 // now you can use WsjcppYaml
4454 WsjcppYaml yaml;
55+ yaml.setLogger(pLogger);
4556 if (yaml.loadFromString(
4657 "# yaml content\n"
4758 "yaml1: nice format\n"
@@ -57,7 +68,7 @@ int main(int argc, char* argv[]) {
5768 " p2: v4 \n"
5869 "param2: 111\n"
5970 )) {
60- WsjcppLog:: throw_err(TAG, "Error parsing");
71+ yaml. throw_err(TAG, "Error parsing");
6172 return -1;
6273 }
6374
0 commit comments