15using std::string_view;
47 inline static const std::map< const string, const string > plugin_file_config_defaults =
49 {
"FILE",
"adc.file_plugin.log" },
53 inline static const char *plugin_file_prefix =
"ADC_FILE_PLUGIN_";
55 const std::vector<string> tags;
65 int config(
const string dir,
const string file,
bool append,
const string& sdebug) {
66 if (mode != pi_config)
72 std::stringstream ss(sdebug);
78 std::cout<<
"file plugin configured" <<std::endl;
84 const string get(
const std::map< string, string >& m,
87 auto it = m.find(
field);
92 char *ec = getenv(en.c_str());
94 return plugin_file_config_defaults.at(
field);
102 file_plugin() : vers(
"1.0.0") , tags({
"none"}), fappend(
false), debug(0),
103 state(ok), paused(
false), mode(pi_config) { }
110 if (mode != pi_pub_or_final)
114 out <<
"<adct-json>" << b->serialize() <<
"</adct-json>" << std::endl;
116 std::cout <<
"'file' wrote" << std::endl;
121 std::cout <<
"plugin 'file' failed out.good" << std::endl;
126 int config(
const std::map< std::string, std::string >& m) {
127 return config(m, plugin_file_prefix);
131 bool app = ( get(m,
"APPEND", env_prefix) ==
"true");
132 string d = get(m,
"DIRECTORY", env_prefix);
133 string f = get(m,
"FILE", env_prefix);
134 string sdebug = get(m,
"DEBUG", env_prefix);
135 return config(d, std::move(f), app, sdebug);
139 return plugin_file_config_defaults;
143 std::map <string, string >m;
147 if (mode != pi_init) {
150 if ( state == err ) {
151 std::cout <<
"file plugin initialize found pre-existing error" << std::endl;
155 std::filesystem::create_directories(fdir, ec);
156 if (ec.value() != 0 && ec.value() != EEXIST ) {
158 std::cout <<
"unable to create output directory for plugin 'file'; "
159 << fdir <<
" : " << ec.message() << std::endl;
162 string fpath = fdir +
"/" + fname;
164 out.open(fpath, std::ofstream::out |
165 (fappend ? std::ofstream::app : std::ofstream::trunc));
167 mode = pi_pub_or_final;
175 if (mode == pi_pub_or_final) {
182 std::cout <<
"file plugin finalize on non-running plugin" << std::endl;
205 std::cout <<
"Destructing file_plugin" << std::endl;
File output publisher_api implementation. This plugin generates writes each message to the configured...
void resume()
Resume publishing Duplicate calls are allowed.
void pause()
Pause publishing until a call to resume. Duplicate calls are allowed.
int initialize()
Ready the plugin to publish following the configuration options set or defaulted.
string_view version() const
void finalize()
Stop publishing and release any resources held for managing publication.
int config(const std::map< std::string, std::string > &m)
Configure the plugin with the options given.
int publish(std::shared_ptr< builder_api > b)
Publish the content of the builder.
const std::map< const std::string, const std::string > & get_option_defaults()
Look up the settable options and their defaults.
int config(const std::map< std::string, std::string > &m, string_view env_prefix)
Configure the plugin with the options given and the corresponding environment variables.
Publisher plugin interface.
std::string_view string_view