| 98 | pretty_file->set_help("Write output to a text file"); |
| 99 | } |
| 100 | std::vector<std::unique_ptr<Printer>> CommonOptions::create_printers() |
| 101 | { |
| 102 | std::vector<std::unique_ptr<Printer>> printers; |
| 103 | |
| 104 | if (pretty_console->value() && (log_file->is_set() || log_format->value() != LogFormat::PRETTY)) |
| 105 | { |
| 106 | auto pretty_printer = std::make_unique<PrettyPrinter>(); |
| 107 | pretty_printer->set_color_output(color_output->value()); |
| 108 | printers.push_back(std::move(pretty_printer)); |
| 109 | } |
| 110 | |
| 111 | std::unique_ptr<Printer> printer; |
| 112 | switch (log_format->value()) |
| 113 | { |
| 114 | case LogFormat::JSON: |
| 115 | printer = std::make_unique<JSONPrinter>(); |
| 116 | break; |
| 117 | case LogFormat::NONE: |
| 118 | break; |
| 119 | case LogFormat::PRETTY: |
| 120 | default: |
| 121 | auto pretty_printer = std::make_unique<PrettyPrinter>(); |
| 122 | // Don't use colours if we print to a file: |
| 123 | pretty_printer->set_color_output((!log_file->is_set()) && color_output->value()); |
| 124 | printer = std::move(pretty_printer); |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | if (log_file->is_set()) |
| 129 | { |
| 130 | log_streams.push_back(std::make_shared<std::ofstream>(log_file->value())); |
| 131 | if (printer != nullptr) |
| 132 | { |
| 133 | printer->set_stream(*log_streams.back().get()); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (printer != nullptr) |
| 138 | { |
| 139 | printers.push_back(std::move(printer)); |
| 140 | } |
| 141 | |
| 142 | if (json_file->is_set()) |
| 143 | { |
| 144 | printers.push_back(std::make_unique<JSONPrinter>()); |
| 145 | log_streams.push_back(std::make_shared<std::ofstream>(json_file->value())); |
| 146 | printers.back()->set_stream(*log_streams.back().get()); |
| 147 | } |
| 148 | |
| 149 | if (pretty_file->is_set()) |
| 150 | { |
| 151 | printers.push_back(std::make_unique<PrettyPrinter>()); |
| 152 | log_streams.push_back(std::make_shared<std::ofstream>(pretty_file->value())); |
| 153 | printers.back()->set_stream(*log_streams.back().get()); |
| 154 | } |
| 155 | |
| 156 | return printers; |
| 157 | } |
no test coverage detected