xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 1 | #include "json/json.h" |
b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 2 | #include "liblog.h" |
| 3 | #include "mbtk_type.h" |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 4 | |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 5 | #define LOG_CONFIG_PATH "/etc/mbtk/mbtk_log.json" |
| 6 | #define SYSLOG_PATCH "syslog" |
| 7 | #define SYSLOG_NAME "syslog" |
| 8 | #define SYSLOG_INDEX 0 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 9 | |
| 10 | void lynq_log_configuration_init(const char *log_name) |
| 11 | { |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 12 | //UNUSED(log_name); |
| 13 | mbtk_log_init(SYSLOG_PATCH, log_name); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | void lynq_log_global_output(log_level_enum Level,const char *format,...) |
| 17 | { |
| 18 | UNUSED(Level); |
| 19 | UNUSED(format); |
| 20 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | int lynq_syslog_set_file_size(int value) |
| 24 | { |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 25 | // UNUSED(value); |
| 26 | json_object* jsonobj = NULL; |
| 27 | json_object* tmpjson = NULL; |
| 28 | json_object* datajson = NULL; |
| 29 | json_object* listjson = NULL; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 30 | |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 31 | int tmp_int; |
| 32 | char* tmp_string = NULL; |
| 33 | |
| 34 | if(value < 1) |
| 35 | { |
| 36 | value = 1; |
| 37 | } |
| 38 | else if(value > 100) |
| 39 | { |
| 40 | value = 100; |
| 41 | } |
| 42 | // value = value*1024; |
| 43 | |
| 44 | jsonobj = json_object_from_file(LOG_CONFIG_PATH); |
| 45 | if (NULL == jsonobj) { |
| 46 | printf("Can't open config file: %s\n", LOG_CONFIG_PATH); |
| 47 | system("echo Can't open config file > /dev/console"); |
| 48 | return -1; |
| 49 | } |
| 50 | /***获取data***/ |
| 51 | json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson); |
| 52 | datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX); |
| 53 | if (NULL == datajson) { |
| 54 | json_object_to_file(LOG_CONFIG_PATH, jsonobj); |
| 55 | json_object_put(jsonobj); |
| 56 | printf("NULL == datajson\n"); |
| 57 | system("echo NULL == datajson > /dev/console"); |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | json_object_object_get_ex(datajson, "name", &listjson); |
| 62 | tmp_string = json_object_get_string(listjson); |
| 63 | |
| 64 | json_object_object_get_ex(datajson, "enable", &listjson); |
| 65 | tmp_int = json_object_get_int(listjson); |
| 66 | |
| 67 | if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1) |
| 68 | { |
| 69 | json_object_to_file(LOG_CONFIG_PATH, jsonobj); |
| 70 | json_object_put(jsonobj); |
| 71 | printf("SYSLOG_NAME error, tmp_int != 1\n"); |
| 72 | system("echo SYSLOG_NAME error, tmp_int != 1 > /dev/console"); |
| 73 | return -1; |
| 74 | } |
| 75 | |
| 76 | json_object_object_add(datajson, "rotate_file_size", json_object_new_int(value)); |
| 77 | |
| 78 | /***释放json对象***/ |
| 79 | json_object_to_file(LOG_CONFIG_PATH, jsonobj); |
| 80 | json_object_put(jsonobj); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | int lynq_syslog_get_file_size(void) |
| 85 | { |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 86 | json_object* jsonobj = NULL; |
| 87 | json_object* tmpjson = NULL; |
| 88 | json_object* datajson = NULL; |
| 89 | json_object* listjson = NULL; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 90 | |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 91 | int tmp_int; |
| 92 | char* tmp_string = NULL; |
| 93 | |
| 94 | jsonobj = json_object_from_file(LOG_CONFIG_PATH); |
| 95 | if (NULL == jsonobj) { |
| 96 | printf("Can't open config file: %s\n", LOG_CONFIG_PATH); |
| 97 | return -1; |
| 98 | } |
| 99 | /***获取data***/ |
| 100 | json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson); |
| 101 | datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX); |
| 102 | if (NULL == datajson) { |
| 103 | json_object_put(jsonobj); |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | json_object_object_get_ex(datajson, "name", &listjson); |
| 108 | tmp_string = json_object_get_string(listjson); |
| 109 | |
| 110 | json_object_object_get_ex(datajson, "enable", &listjson); |
| 111 | tmp_int = json_object_get_int(listjson); |
| 112 | |
| 113 | if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1) |
| 114 | { |
| 115 | json_object_put(jsonobj); |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | json_object_object_get_ex(datajson, "rotate_file_size", &listjson); |
| 120 | tmp_int = json_object_get_int(listjson); |
| 121 | |
| 122 | /***释放json对象***/ |
| 123 | json_object_put(jsonobj); |
| 124 | |
| 125 | // return tmp_int/1024; |
| 126 | return tmp_int; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | int lynq_syslog_set_file_rotate(int value) |
| 130 | { |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 131 | //UNUSED(value); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 132 | |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 133 | json_object* jsonobj = NULL; |
| 134 | json_object* tmpjson = NULL; |
| 135 | json_object* datajson = NULL; |
| 136 | json_object* listjson = NULL; |
| 137 | |
| 138 | int tmp_int; |
| 139 | char* tmp_string = NULL; |
| 140 | |
| 141 | if(value < 0) |
| 142 | { |
| 143 | value = 0; |
| 144 | } |
| 145 | else if(value > 99) |
| 146 | { |
| 147 | value = 99; |
| 148 | } |
| 149 | |
| 150 | jsonobj = json_object_from_file(LOG_CONFIG_PATH); |
| 151 | if (NULL == jsonobj) { |
| 152 | printf("Can't open config file: %s\n", LOG_CONFIG_PATH); |
| 153 | return -1; |
| 154 | } |
| 155 | /***获取data***/ |
| 156 | json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson); |
| 157 | datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX); |
| 158 | if (NULL == datajson) { |
| 159 | json_object_to_file(LOG_CONFIG_PATH, jsonobj); |
| 160 | json_object_put(jsonobj); |
| 161 | return -1; |
| 162 | } |
| 163 | |
| 164 | json_object_object_get_ex(datajson, "name", &listjson); |
| 165 | tmp_string = json_object_get_string(listjson); |
| 166 | |
| 167 | json_object_object_get_ex(datajson, "enable", &listjson); |
| 168 | tmp_int = json_object_get_int(listjson); |
| 169 | |
| 170 | if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1) |
| 171 | { |
| 172 | json_object_to_file(LOG_CONFIG_PATH, jsonobj); |
| 173 | json_object_put(jsonobj); |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | json_object_object_add(datajson, "rotate_file_count", json_object_new_int(value)); |
| 178 | |
| 179 | /***释放json对象***/ |
| 180 | json_object_to_file(LOG_CONFIG_PATH, jsonobj); |
| 181 | json_object_put(jsonobj); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | int lynq_syslog_get_file_rotate(void) |
| 186 | { |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 187 | json_object* jsonobj = NULL; |
| 188 | json_object* tmpjson = NULL; |
| 189 | json_object* datajson = NULL; |
| 190 | json_object* listjson = NULL; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 191 | |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 192 | int tmp_int; |
| 193 | char* tmp_string = NULL; |
| 194 | |
| 195 | jsonobj = json_object_from_file(LOG_CONFIG_PATH); |
| 196 | if (NULL == jsonobj) { |
| 197 | printf("Can't open config file: %s\n", LOG_CONFIG_PATH); |
| 198 | return -1; |
| 199 | } |
| 200 | /***获取data***/ |
| 201 | json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson); |
| 202 | datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX); |
| 203 | if (NULL == datajson) { |
| 204 | json_object_put(jsonobj); |
| 205 | return -1; |
| 206 | } |
| 207 | |
| 208 | json_object_object_get_ex(datajson, "name", &listjson); |
| 209 | tmp_string = json_object_get_string(listjson); |
| 210 | |
| 211 | json_object_object_get_ex(datajson, "enable", &listjson); |
| 212 | tmp_int = json_object_get_int(listjson); |
| 213 | |
| 214 | if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1) |
| 215 | { |
| 216 | json_object_put(jsonobj); |
| 217 | return -1; |
| 218 | } |
| 219 | |
| 220 | json_object_object_get_ex(datajson, "rotate_file_count", &listjson); |
| 221 | tmp_int = json_object_get_int(listjson); |
| 222 | |
| 223 | /***释放json对象***/ |
| 224 | json_object_put(jsonobj); |
| 225 | |
| 226 | return tmp_int; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | int lynq_set_log_level(const char * module_name, log_level_enum level) |
| 230 | { |
| 231 | UNUSED(module_name); |
| 232 | UNUSED(level); |
| 233 | |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | int lynq_get_log_level(const char * module_name, log_level_enum *level) |
| 239 | { |
| 240 | UNUSED(module_name); |
| 241 | UNUSED(level); |
| 242 | |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | int lynq_set_special_log_level(const char * exe_name, const char * module_name, log_level_enum level) |
| 248 | { |
| 249 | UNUSED(exe_name); |
| 250 | UNUSED(module_name); |
| 251 | UNUSED(level); |
| 252 | |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | int lynq_get_special_log_level(const char * exe_name, const char * module_name, log_level_enum *level) |
| 258 | { |
| 259 | UNUSED(exe_name); |
| 260 | UNUSED(module_name); |
| 261 | UNUSED(level); |
| 262 | |
| 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | int lynq_notify_recalc_log_level(pid_t pid) |
| 268 | { |
| 269 | UNUSED(pid); |
| 270 | |
| 271 | return 0; |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame^] | 272 | } |