45 inline static const std::map< const string, const string > plugin_file_config_defaults =
47 {
"FILE",
"adc.file_plugin.log" },
51 inline static const char *plugin_file_prefix =
"ADC_FILE_PLUGIN_";
53 const std::vector<string> tags;
63 int config(
const string dir,
const string file,
bool append,
const string& sdebug) {
64 if (mode != pi_config)
70 std::stringstream ss(sdebug);
76 std::cout<<
"file plugin configured" <<std::endl;
82 const string get(
const std::map< string, string >& m,
85 auto it = m.find(
field);
90 char *ec = getenv(en.c_str());
92 return plugin_file_config_defaults.at(
field);
100 file_plugin() : vers(
"1.0.0") , tags({
"none"}), fappend(
false), debug(0),
101 state(ok), paused(
false), mode(pi_config) { }
108 if (mode != pi_pub_or_final)
112 out <<
"<json>" << b->serialize() <<
"</json>" << std::endl;
114 std::cout <<
"'file' wrote" << std::endl;
119 std::cout <<
"plugin 'file' failed out.good" << std::endl;
124 int config(
const std::map< std::string, std::string >& m) {
125 return config(m, plugin_file_prefix);
129 bool app = ( get(m,
"APPEND", env_prefix) ==
"true");
130 string d = get(m,
"DIRECTORY", env_prefix);
131 string f = get(m,
"FILE", env_prefix);
132 string sdebug = get(m,
"DEBUG", env_prefix);
133 return config(d, std::move(f), app, sdebug);
137 return plugin_file_config_defaults;
141 std::map <string, string >m;
145 if (mode != pi_init) {
148 if ( state == err ) {
149 std::cout <<
"file plugin initialize found pre-existing error" << std::endl;
153 std::filesystem::create_directories(fdir, ec);
154 if (ec.value() != 0 && ec.value() != EEXIST ) {
156 std::cout <<
"unable to create output directory for plugin 'file'; "
157 << fdir <<
" : " << ec.message() << std::endl;
160 string fpath = fdir +
"/" + fname;
162 out.open(fpath, std::ofstream::out |
163 (fappend ? std::ofstream::app : std::ofstream::trunc));
165 mode = pi_pub_or_final;
173 if (mode == pi_pub_or_final) {
180 std::cout <<
"file plugin finalize on non-running plugin" << std::endl;
203 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