55#include " aiges/wrapper.h"
66#include " pyWrapper.h"
77#include " fswatch.h" // 支持 wrapper.py 热加载
8+ #include < stdlib.h>
9+ #include < stdio.h>
810
911__attribute__ ((constructor)) static void so_init(void );
1012
@@ -17,8 +19,8 @@ py::gil_scoped_release release; // 主线程中先释放release锁
1719PyWrapper *pyWrapper;
1820//
1921
20- const char *logDir = " ./log" ;
21- const char *wrapperLogFile = " ./log/wrapper.log" ;
22+ // const char *logDir = "./log";
23+ // const char *wrapperLogFile = "./log/wrapper.log";
2224
2325
2426void so_init (void ) {
@@ -38,7 +40,7 @@ static void init_threads() {
3840 }
3941}
4042
41- void initlog () {
43+ void initlog (std::string logDir, std::string logpath ) {
4244 // change log pattern
4345 spdlog::set_pattern (" [%l] [%Y-%m-%d %H:%M:%S.%f] [%t] %v" );
4446
@@ -48,12 +50,12 @@ void initlog() {
4850 SPDLOG_DEBUG (" Some debug message" );
4951
5052 // Creating a directory
51- if (mkdir (logDir, 0777 ) == -1 ) {
52- printf (" log目录创建失败或已存在,无需创建 \n " );
53+ if (mkdir (logDir. c_str () , 0777 ) == -1 ) {
54+ printf (" log目录创建失败或已存在 %s \n " , logpath );
5355 } else {
54- printf (" log目录已创建\n " );
56+ printf (" log目录已创建, %s \n " , logpath );
5557 }
56- auto file_logger = spdlog::rotating_logger_mt (" mspper" , wrapperLogFile , 1048576 * 10 , 50 );
58+ auto file_logger = spdlog::rotating_logger_mt (" mspper" , logpath. c_str () , 1048576 * 10 , 50 );
5759 // Console logger
5860 auto console_logger = spdlog::stdout_color_mt (" stdout_console" );
5961 auto err_logger = spdlog::stderr_color_mt (" stderr_console" );
@@ -83,9 +85,8 @@ int WrapperAPI wrapperInit(pConfig cfg) {
8385 int ret = 0 ;
8486 init_threads ();
8587 pyWrapper = new PyWrapper ();
86-
87- initlog ();
88-
88+ std::string logDir = std::string (" ./log/server" )
89+ std::string logPath = std::string (" ./log/server/wrapper.log" )
8990 std::string loglvl = " debug" ;
9091 std::map <std::string, std::string> config;
9192
@@ -96,9 +97,16 @@ int WrapperAPI wrapperInit(pConfig cfg) {
9697 loglvl = p->value ;
9798 continue ;
9899 }
100+ if (std::string (" log.dir" ) == std::string (p->key )) {
101+ logDir = p->value ;
102+ logPath = p->value + " /wrapper.log" ;
103+ continue ;
104+ }
99105 }
100106 }
101107
108+ initlog (logDir, logPath);
109+
102110 setLog (loglvl);
103111 printf (" WrapperInit: 当前线程ID: %d \n " , gettid ());
104112 ret = pyWrapper->wrapperInit (config);
@@ -132,7 +140,7 @@ WrapperAPI wrapperCreate(const char *usrTag, pParamList params, wrapperCallback
132140 int *errNum) {
133141 std::string sid = " " ;
134142 if (cb == NULL ) {
135- printf (" cb is null\n " );
143+ printf (" callback function is null\n " );
136144 }
137145 for (pParamList sidP = params; sidP != NULL ; sidP = sidP->next ) {
138146 if (NULL == sidP->key ) {
0 commit comments