Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // c++2.cpp : Defines the entry point for the console application.
- #include "stdafx.h"
- #include "program_options_1.h"
- #include "utils_logger.h"
- int main(int argc, char* argv[])
- {
- //1 init program_options and configure it
- po::variables_map vm =init_program_options(argc, argv);
- //2 init logger and configure it
- init_logging();
- //3
- src::channel_logger<std::string> lg_chan_0(keywords::channel = "0");
- src::channel_logger<std::string> lg_chan_1(keywords::channel = "1");
- src::channel_logger<std::string> lg_chan_2(keywords::channel = "2");
- src::channel_logger<std::string> lg_chan_3(keywords::channel = "3");
- src::channel_logger<std::string> lg_chan_4(keywords::channel = "4");
- src::channel_logger<std::string> lg_chan_5(keywords::channel = "5");
- src::channel_logger<std::string> lg_chan_6(keywords::channel = "6");
- BOOST_LOG(lg_chan_0) << "Hello world0!";
- BOOST_LOG(lg_chan_1) << "Hello world1!";
- BOOST_LOG(lg_chan_2) << "Hello world2!";
- BOOST_LOG(lg_chan_3) << "Hello world3!";
- BOOST_LOG(lg_chan_4) << "Hello world4!";
- BOOST_LOG(lg_chan_5) << "Hello world5!";
- BOOST_LOG(lg_chan_6) << "Hello world6!";
- return 0;
- }
- #pragma once
- /*
- * Copyright Andrey Semashev 2007 - 2015.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
- #include <stdexcept>
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <boost/smart_ptr/shared_ptr.hpp>
- #include <boost/core/null_deleter.hpp>
- #include <boost/lambda/lambda.hpp>
- #include <boost/date_time/posix_time/posix_time.hpp>
- #include <boost/log/attributes/current_thread_id.hpp>
- #include <boost/log/utility/setup/common_attributes.hpp>
- #include <boost/log/expressions/formatters/format.hpp>
- #include <boost/log/core.hpp>
- #include <boost/log/sinks/sync_frontend.hpp>
- #include <boost/log/sinks/text_ostream_backend.hpp>
- #include <boost/log/sources/severity_channel_logger.hpp>
- #include <boost/log/sources/record_ostream.hpp>
- #include <boost/log/common.hpp>
- #include <boost/log/expressions.hpp>
- #include <boost/log/attributes.hpp>
- #include <boost/log/sinks.hpp>
- #include <boost/log/sources/logger.hpp>
- namespace logging = boost::log;
- namespace attrs = boost::log::attributes;
- namespace src = boost::log::sources;
- namespace sinks = boost::log::sinks;
- namespace expr = boost::log::expressions;
- namespace keywords = boost::log::keywords;
- /*
- 1-first date with 404
- 2-first date with 200
- 3-dates with zero size after first date with 200
- 4-dates of saturday and sunday after first date with 200
- 5-dates not saturday or sunday after first date with 200 and having zero size
- 6-dates not saturday or sunday after first date with 200 and having 400
- 7-last date recieved and written to file
- */
- //make attribute argument
- BOOST_LOG_ATTRIBUTE_KEYWORD(a_channel, "Channel", std::string)//????????????
- // Complete sink type
- typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
- //[ example_sinks_xml_file_collecting
- void init_file_collecting(boost::shared_ptr< file_sink > sink)
- {
- sink->locked_backend()->set_file_collector(sinks::file::make_collector(
- keywords::target = "logs", /*< the target directory >*/
- keywords::max_size = 16 * 1024 * 1024, /*< maximum total size of the stored files, in bytes >*/
- keywords::min_free_space = 100 * 1024 * 1024, /*< minimum free space on the drive, in bytes >*/
- keywords::max_files = 7 /*< maximum number of stored files >*/
- ));
- }
- //]
- #if 0
- //[ example_sinks_xml_file
- // Complete file sink type
- typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
- void write_header(sinks::text_file_backend::stream_type& file)
- {
- file << "<?xml version="1.0"?>n<log>n";
- }
- void write_footer(sinks::text_file_backend::stream_type& file)
- {
- file << "</log>n";
- }
- void init_logging()
- {
- // Create a text file sink
- boost::shared_ptr< file_sink > sink(new file_sink(
- keywords::file_name = "%Y%m%d_%H%M%S_%5N.xml", /*< the resulting file name pattern >*/
- keywords::rotation_size = 16384 /*< rotation size, in characters >*/
- ));
- sink->set_formatter
- (
- expr::format("t<record id="%1%" timestamp="%2%">%3%</record>")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::xml_decor[expr::stream << expr::smessage] /*< the log message has to be decorated, if it contains special characters >*/
- );
- // Set header and footer writing functors
- sink->locked_backend()->set_open_handler(&write_header);
- sink->locked_backend()->set_close_handler(&write_footer);
- // Add the sink to the core
- logging::core::get()->add_sink(sink);
- }
- //]
- #endif
- //[ example_sinks_xml_file_final
- void init_logging()
- {
- boost::shared_ptr< logging::core > core = logging::core::get();
- /*
- src::channel_logger<std::string> lg_chan_0(keywords::channel = "0");
- src::channel_logger<std::string> lg_chan_1(keywords::channel = "1");
- src::channel_logger<std::string> lg_chan_2(keywords::channel = "2");
- src::channel_logger<std::string> lg_chan_3(keywords::channel = "3");
- src::channel_logger<std::string> lg_chan_4(keywords::channel = "4");
- src::channel_logger<std::string> lg_chan_5(keywords::channel = "5");
- src::channel_logger<std::string> lg_chan_6(keywords::channel = "6");
- */
- core->add_global_attribute("ThreadID", boost::log::attributes::current_thread_id());
- core->add_global_attribute("TimeStamp",attrs::local_clock());
- core->add_global_attribute("RecordID", attrs::counter< unsigned int >(1));
- logging::add_common_attributes();
- //lg_chan_0(keywords::channel = "net");
- // Create a text file sink
- boost::shared_ptr< file_sink > sink0(new file_sink(
- keywords::file_name = "first_date_with_404.log",
- keywords::rotation_size = 16384
- ));
- // Create a text file sink
- boost::shared_ptr< file_sink > sink1(new file_sink(
- keywords::file_name = "first_date_with_200.log",
- keywords::rotation_size = 16384
- ));
- // Create a text file sink
- boost::shared_ptr< file_sink > sink2(new file_sink(
- keywords::file_name = "dates_with_zero_size_after_first_date_with_200.log",
- keywords::rotation_size = 16384
- ));
- // Create a text file sink
- boost::shared_ptr< file_sink > sink3(new file_sink(
- keywords::file_name = "dates_of_saturday_and_sunday_after_first_date_with_200.log",
- keywords::rotation_size = 16384
- ));
- // Create a text file sink
- boost::shared_ptr< file_sink > sink4(new file_sink(
- keywords::file_name = "dates_not_saturday_or_sunday_after_first_date_with_200_having_zero_size.log",
- keywords::rotation_size = 16384
- ));
- // Create a text file sink
- boost::shared_ptr< file_sink > sink5(new file_sink(
- keywords::file_name = "dates_not_saturday_or_sunday_after_first_date_with_200_having_400.log",
- keywords::rotation_size = 16384
- ));
- // Create a text file sink
- boost::shared_ptr< file_sink > sink6(new file_sink(
- keywords::file_name = "last_date_recieved_and_written_to_file.log",
- keywords::rotation_size = 16384
- ));
- /*
- // Create a text file sink
- boost::shared_ptr< file_sink > sink(new file_sink(
- keywords::file_name = "%Y%m%d_%H%M%S_%5N.xml",
- keywords::rotation_size = 16384
- ));
- */
- sink0->set_filter(expr::attr< std::string >("Channel") == "0");
- sink1->set_filter(expr::attr< std::string >("Channel") == "1");
- sink2->set_filter(expr::attr< std::string >("Channel") == "2");
- sink3->set_filter(expr::attr< std::string >("Channel") == "3");
- sink4->set_filter(expr::attr< std::string >("Channel") == "4");
- sink5->set_filter(expr::attr< std::string >("Channel") == "5");
- sink6->set_filter(expr::attr< std::string >("Channel") == "6");
- // Set up where the rotated files will be stored
- init_file_collecting(sink0);
- init_file_collecting(sink1);
- init_file_collecting(sink2);
- init_file_collecting(sink3);
- init_file_collecting(sink4);
- init_file_collecting(sink5);
- init_file_collecting(sink6);
- // Upon restart, scan the directory for files matching the file_name pattern
- sink0->locked_backend()->scan_for_files();
- sink1->locked_backend()->scan_for_files();
- sink2->locked_backend()->scan_for_files();
- sink3->locked_backend()->scan_for_files();
- sink4->locked_backend()->scan_for_files();
- sink5->locked_backend()->scan_for_files();
- sink6->locked_backend()->scan_for_files();
- sink0->set_formatter
- (
- expr::format("record id="%1%" ["%2%"] thread_id= %3% %4%")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
- % expr::message
- );
- sink1->set_formatter
- (
- expr::format("record id="%1%" ["%2%"] thread_id= %3% %4%")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
- % expr::message
- );
- sink2->set_formatter
- (
- expr::format("record id="%1%" ["%2%"] thread_id= %3% %4%")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
- % expr::message
- );
- sink3->set_formatter
- (
- expr::format("record id="%1%" ["%2%"] thread_id= %3% %4%")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
- % expr::message
- );
- sink4->set_formatter
- (
- expr::format("record id="%1%" ["%2%"] thread_id= %3% %4%")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
- % expr::message
- );
- sink5->set_formatter
- (
- expr::format("record id="%1%" ["%2%"] thread_id= %3% %4%")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
- % expr::message
- );
- sink6->set_formatter
- (
- expr::format("record id="%1%" ["%2%"] thread_id= %3% %4%")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
- % expr::message
- );
- /*
- // Set header and footer writing functors
- namespace bll = boost::lambda;
- sink->locked_backend()->set_open_handler
- (
- bll::_1 << "<?xml version="1.0"?>n<log>n"
- );
- sink->locked_backend()->set_close_handler
- (
- bll::_1 << "</log>n"
- );
- */
- // Add the sink to the core
- //logging::core::get()->add_sink(sink);
- core->add_sink(sink0);
- core->add_sink(sink1);
- core->add_sink(sink2);
- core->add_sink(sink3);
- core->add_sink(sink4);
- core->add_sink(sink5);
- core->add_sink(sink6);
- }
- //]
- //enum { LOG_RECORDS_TO_WRITE = 2000 };
- /*
- int main(int argc, char* argv[])
- {
- try
- {
- // Initialize logging library
- init_logging();
- // And also add some attributes
- logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock());
- logging::core::get()->add_global_attribute("RecordID", attrs::counter< unsigned int >());
- // Do some logging
- src::logger lg;
- for (unsigned int i = 0; i < LOG_RECORDS_TO_WRITE; ++i)
- {
- BOOST_LOG(lg) << "XML log record " << i;
- }
- // Test that XML character decoration works
- BOOST_LOG(lg) << "Special XML characters: &, <, >, ", '";
- return 0;
- }
- catch (std::exception& e)
- {
- std::cout << "FAILURE: " << e.what() << std::endl;
- return 1;
- }
- }
- */
- /*
- * Copyright Andrey Semashev 2007 - 2015.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
- /*
- #include <boost/log/core.hpp>
- #include <boost/log/trivial.hpp>
- #include <boost/log/expressions.hpp>
- #include <boost/log/sinks/text_file_backend.hpp>
- #include <boost/log/utility/setup/file.hpp>
- #include <boost/log/utility/setup/common_attributes.hpp>
- #include <boost/log/sources/severity_logger.hpp>
- #include <boost/log/sources/record_ostream.hpp>
- namespace logging = boost::log;
- namespace src = boost::log::sources;
- namespace sinks = boost::log::sinks;
- namespace keywords = boost::log::keywords;
- namespace expr = boost::log::expressions;
- namespace attrs = boost::log::attributes;
- #if 0
- //[ example_tutorial_file_simple
- void init()
- {
- logging::add_file_log("sample.log");
- logging::core::get()->set_filter
- (
- logging::trivial::severity >= logging::trivial::info
- );
- }
- //]
- // We need this due to this bug: https://svn.boost.org/trac/boost/ticket/4416
- //[ example_tutorial_file_advanced_no_callouts
- void init()
- {
- logging::add_file_log
- (
- keywords::file_name = "sample_%N.log",
- keywords::rotation_size = 10 * 1024 * 1024,
- keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
- keywords::format = "[%TimeStamp%]: %Message%"
- );
- logging::core::get()->set_filter
- (
- logging::trivial::severity >= logging::trivial::info
- );
- }
- //]
- #else
- //[ example_tutorial_file_advanced
- void init()
- {
- logging::add_file_log
- (
- keywords::file_name = "sample_%N.log", //*< file name pattern >
- keywords::rotation_size = 10 * 1024 * 1024, //*< rotate files every 10 MiB... >
- keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), //*< ...or at midnight >
- keywords::format = "[%TimeStamp%]: %Message%" //*< log record format >
- );
- logging::core::get()->set_filter
- (
- logging::trivial::severity >= logging::trivial::info
- );
- }
- //]
- #endif
- void init_logging()
- {
- // Create a text file sink
- boost::shared_ptr< file_sink > sink(new file_sink(
- keywords::file_name = "%Y%m%d_%H%M%S_%5N.xml",
- keywords::rotation_size = 16384
- ));
- // Set up where the rotated files will be stored
- init_file_collecting(sink);
- // Upon restart, scan the directory for files matching the file_name pattern
- sink->locked_backend()->scan_for_files();
- sink->set_formatter
- (
- expr::format("t<record id="%1%" timestamp="%2%">%3%</record>")
- % expr::attr< unsigned int >("RecordID")
- % expr::attr< boost::posix_time::ptime >("TimeStamp")
- % expr::xml_decor[expr::stream << expr::smessage]
- );
- // Set header and footer writing functors
- namespace bll = boost::lambda;
- sink->locked_backend()->set_open_handler
- (
- bll::_1 << "<?xml version="1.0"?>n<log>n"
- );
- sink->locked_backend()->set_close_handler
- (
- bll::_1 << "</log>n"
- );
- // Add the sink to the core
- logging::core::get()->add_sink(sink);
- }
- */
- #pragma once
- //#include "stdafx.h"
- #include "boost/date_time/posix_time/posix_time.hpp"
- #include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
- #include <boost/program_options.hpp>
- #include <boost/any.hpp>
- #include <iostream>
- #include <iterator>
- #include <string>
- #include <vector>
- #include "utils.h"
- namespace po = boost::program_options;
- using namespace std;
- using namespace boost::posix_time;
- using namespace boost::gregorian;
- po::variables_map init_program_options(int argc, char* argv[])
- {
- const string VERSION = "0.2.1";
- try {
- date_duration single_day(1);
- auto facet = new date_input_facet();
- facet->set_iso_extended_format();
- //facet->format("%Y-%m-%d");
- std::locale::global(std::locale(std::locale(), facet));
- std::vector<symbols_enum> symbols_default = { symbols_enum::GBPJPY};
- string prog = "DUKA";
- po::options_description desc(prog + " Allowed options");
- desc.add_options()
- ("help", "produce help message")
- ("version,v", "outputs Version of program")
- ("day,d", po::value<date>()->default_value(day_clock::universal_day()), "specific day format YYYY-MM-DD (default today)")
- ("startdate,s", po::value<date>()->default_value(day_clock::universal_day() - single_day), "start date format YYYY-MM-DD (default today)")
- ("enddate,e", po::value<date>()->default_value(day_clock::universal_day()), "end date format YYYY-MM-DD (default today)")
- ("thread,t", po::value<int>()->default_value(20), "number of threads (default 20)")
- ("folder,f", po::value<string>()->default_value("."), "destination folder (default .)")
- ("candle,c", po::value<timeframe_enum>()->default_value(timeframe_enum::TICK, "TICK"), "use candles instead of ticks. Accepted values TICK M1 M2 M5 M10 M15 M30 H1 H4")
- ("header", po::value<bool>()->default_value(false), "include CSV header (default false)")
- ("symbols", po::value<std::vector<symbols_enum>>()->multitoken()->composing()->default_value(symbols_default, "GBPJPY"), "symbol list using format EURUSD EURGBP")
- ;
- po::positional_options_description pd;
- pd.add("symbols", -1);
- command_line_parser parser{ argc, argv };
- parser.options(desc).positional(pd);
- parsed_options parsed_options = parser.run();
- po::variables_map vm;
- po::store(parsed_options, vm);
- po::notify(vm);
- if (vm.count("help")) {
- cout << desc << "n";
- exit(0);
- }
- if (vm.count("version")) {
- cout << VERSION << "n";
- exit(0);
- }
- if (vm.count("day")) {
- cout << "day set to "
- << vm["day"].as<date>() << ".n";
- }
- else {
- cout << "day was not set.n";
- }
- if (vm.count("startdate")) {
- cout << "startdate set to "
- << vm["startdate"].as<date>() << ".n";
- }
- else {
- cout << "startdate was not set.n";
- }
- if (vm.count("enddate")) {
- cout << "enddate set to "
- << vm["enddate"].as<date>() << ".n";
- }
- else {
- cout << "enddate was not set.n";
- }
- if (vm.count("thread")) {
- cout << "thread set to "
- << vm["thread"].as<int>() << ".n";
- }
- else {
- cout << "thread was not set.n";
- }
- if (vm.count("folder")) {
- cout << "folder set to "
- << vm["folder"].as<string>() << ".n";
- }
- else {
- cout << "folder was not set.n";
- }
- if (vm.count("candle")) {
- cout << "candle set to "
- << vm["candle"].as<timeframe_enum>() << ".n";
- }
- else {
- cout << "candle level was not set.n";
- }
- if (vm.count("header")) {
- cout << "header set to "
- << vm["header"].as<bool>() << ".n";
- }
- else {
- cout << "header was not set.n";
- }
- if (vm.count("symbols")) {
- cout << "symbols set to "
- << vm["symbols"].as<std::vector<symbols_enum>>() << ".n";
- }
- else {
- cout << "symbols was not set.n";
- }
- return vm;
- }
- catch (exception& e) {
- cerr << "error: " << e.what() << "n";
- exit(1);
- }
- catch (...) {
- cerr << "Exception of unknown type!n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement