libadc-cxx 1.0.0
Structured logging for scientific computing
Loading...
Searching...
No Matches
stdout.ipp
Go to the documentation of this file.
3#include <cstdlib>
4#include <iostream>
5#include <fstream>
6#include <filesystem>
7
8namespace adc {
9
10std::map< const std::string, const std::string> stdout_defaults;
11
12/*! \brief Terminal output publisher_api implementation.
13 This plugin sends messages to stdout synchronously.
14 Multiple independent instances of this plugin may be used simultaneously,
15 but message integrity depends on the behavior of stdout.
16 */
18 enum state {
19 ok,
20 err
21 };
22
23private:
24 const std::string vers;
25 const std::vector<std::string> tags;
26 enum state state;
27 bool paused;
28
29public:
30 stdout_plugin() : vers("1.0.0") , tags({"none"}), state(ok), paused(false) { }
31
32 int publish(std::shared_ptr<builder_api> b) {
33 if (paused)
34 return 0;
35 if (state != ok)
36 return 1;
37 std::cout << b->serialize() << std::endl;
38 return 0;
39 }
40
41 int config(const std::map< std::string, std::string >& /* m */) {
42 return 0;
43 }
44
45 int config(const std::map< std::string, std::string >& /* m */, std::string_view /* env_prefix */) {
46 return 0;
47 }
48
49 const std::map< const std::string, const std::string> & get_option_defaults() {
50 return stdout_defaults;
51 }
52
53 int initialize() {
54 return 0;
55 }
56
57 void finalize() {
58 }
59
60 void pause() {
61 paused = true;
62 }
63
64 void resume() {
65 paused = false;
66 }
67
68 std::string_view name() const {
69 return "stdout";
70 }
71
72 std::string_view version() const {
73 return vers;
74 }
75
77};
78
79
80} // adc
Publisher plugin interface.
Definition publisher.hpp:44
Terminal output publisher_api implementation. This plugin sends messages to stdout synchronously....
Definition stdout.ipp:17
int publish(std::shared_ptr< builder_api > b)
Publish the content of the builder.
Definition stdout.ipp:32
const std::map< const std::string, const std::string > & get_option_defaults()
Look up the settable options and their defaults.
Definition stdout.ipp:49
int config(const std::map< std::string, std::string > &, std::string_view)
Configure the plugin with the options given and the corresponding environment variables.
Definition stdout.ipp:45
int config(const std::map< std::string, std::string > &)
Configure the plugin with the options given.
Definition stdout.ipp:41
void pause()
Pause publishing until a call to resume. Duplicate calls are allowed.
Definition stdout.ipp:60
int initialize()
Ready the plugin to publish following the configuration options set or defaulted.
Definition stdout.ipp:53
void resume()
Resume publishing Duplicate calls are allowed.
Definition stdout.ipp:64
std::string_view name() const
Definition stdout.ipp:68
void finalize()
Stop publishing and release any resources held for managing publication.
Definition stdout.ipp:57
std::string_view version() const
Definition stdout.ipp:72
Definition adc.hpp:75
std::map< const std::string, const std::string > stdout_defaults
Definition stdout.ipp:10