File tree Expand file tree Collapse file tree 2 files changed +125
-0
lines changed
Expand file tree Collapse file tree 2 files changed +125
-0
lines changed Original file line number Diff line number Diff line change 1+ // ibcs/plugins/builtins/logger/logger_plugin.cpp
2+ #include " logger_plugin.h"
3+ #include < iostream>
4+ #include < chrono>
5+ #include < ctime>
6+ using namespace std ;
7+
8+ namespace ibcs ::plugin::builtins
9+ {
10+
11+ LoggerPlugin::LoggerPlugin ()
12+ {
13+
14+ }
15+
16+ LoggerPlugin::~LoggerPlugin ()
17+ {
18+
19+ }
20+
21+ PluginInfo LoggerPlugin::info () const
22+ {
23+ return
24+ {
25+ " builtins.logger" ,
26+ " 1.0.0" ,
27+ " IBCS Core Team"
28+ };
29+ }
30+
31+ bool LoggerPlugin::on_load ()
32+ {
33+ logFile_.open (" ibcs_log.txt" , ios::app);
34+ if (!logFile_)
35+ {
36+ cerr << " [logger] failed to open log file\n " ;
37+ return false ;
38+ }
39+
40+ cout << " [logger] plugin loaded\n " ;
41+ return true ;
42+ }
43+
44+ bool LoggerPlugin::on_unload ()
45+ {
46+ cout << " [logger] plugin unloaded\n " ;
47+ if (logFile_.is_open ()) logFile_.close ();
48+ return true ;
49+ }
50+
51+ vector<string> LoggerPlugin::capabilities () const
52+ {
53+ return
54+ {
55+ " log" ,
56+ " trace_emit" ,
57+ " diagnostics"
58+ };
59+ }
60+
61+ void LoggerPlugin::log (const string &level, const string &msg)
62+ {
63+ if (!logFile_) return ;
64+
65+ // Timestamp
66+ auto now = chrono::system_clock::now ();
67+ time_t t = chrono::system_clock::to_time_t (now);
68+
69+ logFile_ << " [" <<string (ctime (&t)).substr (0 ,24 ) << " ] "
70+ << " [" << level << " ] "
71+ << msg << " \n " ;
72+
73+ logFile_.flush ();
74+ }
75+
76+ } // namespace ibcs::plugin::builtins
77+
78+ // ---------- Dynamic Loading Entry Points -----------
79+
80+ extern " C" ibcs::plugin::IPlugin* create_plugin ()
81+ {
82+ return new ibcs::plugin::builtins::LoggerPlugin ();
83+ }
84+
85+ extern " C" void destroy_plugin (ibcs::plugin::IPlugin* p)
86+ {
87+ delete p;
88+ }
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #include " ../base/plugin_interface.h"
3+
4+ #include < string>
5+ #include < vector>
6+
7+ #include < fstream>
8+ using namespace std ;
9+
10+ namespace ibcs :: plugin :: builtins
11+ {
12+ class LoggerPlugin : public IPlugin
13+ {
14+ public:
15+ LoggerPlugin ();
16+ ~LoggerPlugin () override ;
17+
18+
19+ PluginInfo info () const override ;
20+ bool on_load () override ;
21+
22+ bool on_unload () override ;
23+ vector<string> capabilities () const override ;
24+
25+ // logging API exposed to core or introspection
26+ void log (const string &level, const string &msg);
27+
28+ private:
29+ ofstream logFile_;
30+ };
31+ }
32+
33+ extern " C"
34+ {
35+ ibcs :: plugin :: IPlugin*create_plugin ();
36+ void destroy_plugin (ibcs :: plugin :: IPlugin*p);
37+ }
You can’t perform that action at this time.
0 commit comments