2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NSLogger
21 /// Frameworkunified Framework Handlers Logging to log services.
22 ///////////////////////////////////////////////////////////////////////////////
28 #include <sys/timeb.h>
30 #include <sys/syscall.h>
31 #include <sys/prctl.h>
33 #include <boost/algorithm/string.hpp>
34 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/ip.h>
41 #include <arpa/inet.h>
43 #include <native_service/ns_message_center_if.h>
44 #include <native_service/ns_plogger_if.h>
45 #include <native_service/ns_ringbuffer.h>
46 #include <native_service/ns_config_parser_if.h>
47 #include <native_service/ns_logger_if.h>
48 #include <native_service/ns_eventlogger.h>
49 #include <native_service/cl_lockid.h>
52 #include <other_service/strlcat.h>
53 #include <other_service/strlcpy.h>
54 #include <other_service/PosixBasedOS001ClockCycleApi.h>
55 #include "frameworkunified_stub.h"
57 #include <sys/neutrino.h>
58 #include <sys/trace.h> // trace_nlogf
60 #include <sys/slogcodes.h>
61 #include <sys/syspage.h>
70 #include "ns_logger_internal.h"
71 #include "ns_msg_queue.h"
74 static HANDLE g_hSSEventLogQ = INVALID_HANDLE;
76 static HANDLE g_hNSplogMsgQ = INVALID_HANDLE;
78 static HANDLE g_hNSSysEventLogQ = INVALID_HANDLE;
79 static __thread CHAR tls_strProcessName[MAX_NAME_SIZE_APP];
80 static __thread pid_t tid = 0;
81 static UI_32 g_msgcounter = 0;
82 static FRAMEWORKUNIFIEDLOGPARAM g_LocalFrameworkunifiedLogParams;
83 static UI_32 syslogopened;
84 static int shm_fd = -1;
85 static const unsigned int default_log_cfgtbl[] = {
87 FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF,
91 FRAMEWORKUNIFIEDLOG_FLAG_MODE_RELEASE,
93 static void *shm_pmap = reinterpret_cast<void *>(const_cast<unsigned int*>(default_log_cfgtbl));
94 #define EXE_STR_LEN 64
95 static char exe_link_path[EXE_STR_LEN] = {0};
98 #define PLOG_GAP_FILE "/dev/shmem/Plog.gap"
99 #define MAX_GAP_BUFFER_LEN 80
100 #define MAX_PLOG_STRING_SIZE 1024
101 #define MAX_TIME_FORMATSTR_LEN 3
102 #define RETRY_COUNT 5
103 FRAMEWORKUNIFIEDLOGPPARAM g_FrameworkunifiedLogPParams = {FALSE, EPLOG_TIME_FORMAT_USEC, 0, EPLOG_MSGQ}; // default values for PLog
104 FRAMEWORKUNIFIEDLOGSYSEVENTPARAM g_FrameworkunifiedLogSysEventParams = {FALSE}; // default values for System event log
106 #define ZONEMASK_MAX BITS_IN_TZONE // ((UI_32)(BITS_IN_TZONE * TZONE_COUNT))
108 #define FRAMEWORKUNIFIEDLOG_DEFAULT_FLAG_ID (0)
109 #define FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__FN "/etc/basesystem/BS/ns/framework_unified/rodata/ns_logger_frameworkunifiedlog__CWORD84_.cfg"
110 #define FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__TMP "ns_logger_frameworkunifiedlog__CWORD84_.tmp"
111 #define FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV "ns_logger_frameworkunifiedlog__CWORD84_.cfg"
113 #define FRAMEWORKUNIFIEDLOG_CONFIG_NV "/nv/BS/ns/framework_unified/rwdata/"
115 #define FRAMEWORKUNIFIEDLOG_CONFIG_TMP_NV "ns_logger_frameworkunifiedlog_tmp.cfg"
116 #ifndef TN_LOGGERRTIME
117 #define TN_LOGGERRTIME "LoggerRtime"
118 #define PR_LOGGERRTIME_S PR_TSS_S
119 #define PR_LOGGERRTIME PR_TSS
120 #endif // TN_LOGGERRTIME
121 #define USB_REALTIME_MSGMAX 256
122 #define USB_REALTIME_SIZMAX 4096
123 #define USB_REALTIME_QNAME "/PlRtLogger"
124 #define USB_REALTIME_RTRYMAX 10
125 static mqd_t g_qid = (mqd_t)(-1);
127 unsigned int g_FlagIdNum;
128 std::vector<std::string> g_flag_name;
131 CNSRingBuffer *ring_buffer;
132 std::string file_name;
137 } FrameworkunifiedLogMapTbl;
140 TFrameworkunifiedZone zone;
141 FrameworkunifiedLogMapTbl info;
142 } FrameworkunifiedLogTbl;
144 typedef std::map<TFrameworkunifiedZone, FrameworkunifiedLogMapTbl> TFrameworkunifiedLogMap;
145 static TFrameworkunifiedLogMap g_FrameworkunifiedLogMap;
146 static TFrameworkunifiedLogMap g_FrameworkunifiedLogFlagMap;
147 static UI_32 g_FrameworkunifiedLogFlagId = FRAMEWORKUNIFIEDLOG_DEFAULT_FLAG_ID;
149 static bool g_FrameworkunifiedLogFlagRealTimeLog = TRUE;
150 pthread_mutex_t FrameworkunifiedLogMtx = PTHREAD_MUTEX_INITIALIZER;
152 #ifdef ENABLE_DEBUG_SYSLOG // for FRAMEWORKUNIFIED_SET_ZONES() error
153 #define DEB_SYSLOG(fmt, ...) {openlog(0, LOG_PID, LOG_USER); \
154 syslog(LOG_ERR, "[FRAMEWORKUNIFIEDLOG][ERR]EXE_LINK_PATH(%s)[%s:L%d] " fmt, exe_link_path, \
155 __FUNCTION__, __LINE__, ## __VA_ARGS__); \
158 #define DEB_SYSLOG(fmt, ...)
162 GetFrameworkunifiedLogRealtimeUartOutput(CNSConfigReader *cfg_reader) {
163 if (cfg_reader == NULL) {
167 std::string output_str = cfg_reader->GetString("REALTIME_LOG.Output"); // LCOV_EXCL_BR_LINE 11:expect branch
169 if (output_str.compare("UART") == 0) {
170 return FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_UART;
171 } else if (output_str.compare("USB") == 0) {
172 return FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_USB;
174 return FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
178 static EFrameworkunifiedStatus
179 GetFrameworkunifiedLogZoneFileInfo(CNSConfigReader *cfg_reader, std::string &name, // NOLINT (readability/nolint)
180 FrameworkunifiedLogMapTbl &tbl, UI_32 &zone) { // NOLINT (readability/nolint)
181 std::string zone_key = name;
182 zone_key.append(".Zone");
183 std::string zone_filename_key = name; // LCOV_EXCL_BR_LINE 11:expect branch
184 zone_filename_key.append(".FileName");
185 std::string zone_filesize_key = name; // LCOV_EXCL_BR_LINE 11:expect branch
186 zone_filesize_key.append(".FileSizeMax");
187 std::string zone_force_output_key = name; // LCOV_EXCL_BR_LINE 11:expect branch
188 zone_force_output_key.append(".ForceOutput");
190 if (cfg_reader == NULL) {
191 return eFrameworkunifiedStatusNullPointer;
194 tbl.ring_buffer = NULL;
195 tbl.file_name = cfg_reader->GetString(zone_filename_key);
196 tbl.size = static_cast<UI_32>(cfg_reader->GetInt(zone_filesize_key));
198 = (cfg_reader->GetString(zone_force_output_key) == "True") ? TRUE : FALSE;
200 tbl.real_time_log = TRUE;
201 zone = ZONEMASK(static_cast<UI_32>(cfg_reader->GetInt(zone_key)));
202 return eFrameworkunifiedStatusOK;
205 static EFrameworkunifiedStatus
206 GetFrameworkunifiedLogFlagFileInfo(CNSConfigReader *cfg_reader, std::string &name, // NOLINT (readability/nolint)
207 FrameworkunifiedLogMapTbl &tbl, UI_32 &loglevel) { // NOLINT (readability/nolint)
208 std::string flag_loglevel_key = name;
209 flag_loglevel_key.append(".LogLevel");
210 std::string flag_filename_key = name; // LCOV_EXCL_BR_LINE 11:expect branch
211 flag_filename_key.append(".FileName");
212 std::string flag_filesize_key = name; // LCOV_EXCL_BR_LINE 11:expect branch
213 flag_filesize_key.append(".FileSizeMax");
215 std::string flag_real_time_log_key = name;
216 flag_real_time_log_key.append(".Realtimelog");
218 if (cfg_reader == NULL) {
219 return eFrameworkunifiedStatusNullPointer;
222 tbl.ring_buffer = NULL;
223 tbl.file_name = cfg_reader->GetString(flag_filename_key); // LCOV_EXCL_BR_LINE 11:expect branch
224 tbl.size = static_cast<UI_32>(cfg_reader->GetInt(flag_filesize_key)); // LCOV_EXCL_BR_LINE 11:expect branch
225 tbl.force_output = FALSE;
228 = (cfg_reader->GetString(flag_real_time_log_key) == "False") ? FALSE : TRUE;
231 std::string loglevel_str = cfg_reader->GetString(flag_loglevel_key); // LCOV_EXCL_BR_LINE 11:expect branch
233 if (loglevel_str.compare("Debug") == 0) {
234 loglevel = FRAMEWORKUNIFIEDLOG_FLAG_MODE_DEBUG;
236 loglevel = FRAMEWORKUNIFIEDLOG_FLAG_MODE_RELEASE;
239 if ((tbl.file_name.empty()) || (tbl.size == 0)) {
240 return eFrameworkunifiedStatusFail;
242 return eFrameworkunifiedStatusOK;
246 GetFrameworkunifiedLogList(CNSConfigReader *cfg_reader, std::vector<std::string> &list, // NOLINT (readability/nolint)
247 std::string req_list) {
248 if (cfg_reader == NULL) {
252 std::string list_str = cfg_reader->GetString(req_list);
253 if (!list_str.empty()) {
255 boost::algorithm::split(list, list_str, boost::is_any_of(", "));
259 * Even if throw is executed by the process called by 'try', it cannot be captured by catch().
262 fprintf(stderr, "occured exception handling by boost::algorithm::split in ns_logger\n");
268 CheckMatchFrameworkunifiedLogFlagMap(TFrameworkunifiedLogMap &map, FrameworkunifiedLogMapTbl &check_tbl, // NOLINT (readability/nolint)
269 FrameworkunifiedLogMapTbl &out_tbl) { // NOLINT (readability/nolint)
270 TFrameworkunifiedLogMap::iterator itr;
271 for (itr = map.begin(); itr != map.end(); itr++) {
272 if (itr->second.file_name.compare(check_tbl.file_name) == 0) {
273 out_tbl = itr->second;
281 IsDefinedFrameworkunifiedLogFlag(CNSConfigReader *cfg_reader, std::string &flag_name, // NOLINT (readability/nolint)
282 std::string &exe_name) { // NOLINT (readability/nolint)
286 if (cfg_reader == NULL) {
291 std::string service_key = flag_name;
292 std::ostringstream service_num; // LCOV_EXCL_BR_LINE 11:expect branch
293 service_num << ".Service" << cnt;
294 service_key.append(service_num.str());
295 std::string service_name = cfg_reader->GetString(service_key);
296 if (service_name.empty()) {
299 pos1 = exe_name.find(service_name);
300 if ((pos1 != std::string::npos)
301 && (exe_name.length() - pos1) == service_name.length()) {
310 CreateFrameworkunifiedLogFileTbl(CNSConfigReader *cfg_reader, std::string &exe_str, // NOLINT (readability/nolint)
311 int *realTimeLog, int **logLevelArray) {
314 std::vector<std::string> zone_vector;
315 GetFrameworkunifiedLogList(cfg_reader, zone_vector, "ZONE_LIST.List");
316 for (UI_32 i = 0; i < zone_vector.size(); i++) {
317 FrameworkunifiedLogMapTbl zone_tbl;
319 if (GetFrameworkunifiedLogZoneFileInfo(cfg_reader, zone_vector.at(i), zone_tbl, zone)
320 == eFrameworkunifiedStatusOK) {
321 g_FrameworkunifiedLogMap.insert(std::make_pair(zone, zone_tbl));
325 *realTimeLog = static_cast<int>(GetFrameworkunifiedLogRealtimeUartOutput(cfg_reader));
327 FrameworkunifiedLogMapTbl default_tbl;
328 UI_32 default_id = FRAMEWORKUNIFIEDLOG_DEFAULT_FLAG_ID;
329 std::string default_flag = "FLAG_DEFAULT"; // LCOV_EXCL_BR_LINE 11:expect branch
330 UI_32 default_loglevel;
331 if (GetFrameworkunifiedLogFlagFileInfo(cfg_reader, default_flag, default_tbl, default_loglevel)
332 != eFrameworkunifiedStatusOK) {
333 fprintf(stderr, "<WARNING>FRAMEWORKUNIFIEDLOG[%s:L%d]FLAG_DEFAULT is not definition into ns_logger_frameworkunifiedlog.cfg.\n",
334 __FUNCTION__, __LINE__);
336 DEB_SYSLOG("<WARNING>FLAG_DEFAULT is not definition into ns_logger_frameworkunifiedlog.cfg.)");
337 default_tbl.ring_buffer = NULL;
338 default_tbl.file_name = "frameworkunified_debug.log";
339 default_tbl.size = 100; // 100bytes
341 default_tbl.real_time_log = TRUE;
343 std::vector<std::string> flag_vector;
344 UI_32 flag_id = FRAMEWORKUNIFIEDLOG_DEFAULT_FLAG_ID + 1;
345 GetFrameworkunifiedLogList(cfg_reader, flag_vector, "FLAG_LIST.List"); // LCOV_EXCL_BR_LINE 11:expect branch
346 if (g_FlagIdNum != (flag_vector.size() + 1)) {
347 if (!g_FrameworkunifiedLogFlagMap.empty()) {
348 TFrameworkunifiedLogMap::iterator delitr;
349 unsigned int delflag_id;
350 for (delflag_id = 0; delflag_id < g_FlagIdNum; delflag_id++) {
351 delitr = g_FrameworkunifiedLogFlagMap.find(delflag_id);
352 if (delitr->second.ring_buffer != NULL) {
353 delete delitr->second.ring_buffer;
354 delitr->second.ring_buffer = NULL;
357 g_FrameworkunifiedLogFlagMap.clear();
358 if (!g_flag_name.empty()) {
362 g_FlagIdNum = static_cast<unsigned int>(flag_vector.size() + 1); // +1: [Add Default Flag]
363 g_flag_name.push_back(default_flag); // LCOV_EXCL_BR_LINE 11:expect branch
364 g_FrameworkunifiedLogFlagMap.insert(std::make_pair(default_id, default_tbl)); // LCOV_EXCL_BR_LINE 11:expect branch
366 logLevel = reinterpret_cast<int *>(malloc(sizeof(int) * g_FlagIdNum));
367 logLevel[0] = default_loglevel;
369 for (UI_32 i = 0; i < flag_vector.size(); i++) {
370 FrameworkunifiedLogMapTbl flag_tbl;
372 if (GetFrameworkunifiedLogFlagFileInfo(cfg_reader, flag_vector.at(i), flag_tbl, loglevel)
373 == eFrameworkunifiedStatusOK) {
374 FrameworkunifiedLogMapTbl check_result_tbl;
375 if (CheckMatchFrameworkunifiedLogFlagMap(g_FrameworkunifiedLogFlagMap, flag_tbl, check_result_tbl)
377 flag_tbl.file_name = check_result_tbl.file_name;
378 flag_tbl.size = check_result_tbl.size;
380 if (g_FrameworkunifiedLogFlagMap.find(flag_id) == g_FrameworkunifiedLogFlagMap.end()) {
381 if (IsDefinedFrameworkunifiedLogFlag(cfg_reader, flag_vector.at(i), exe_str)
383 g_FrameworkunifiedLogFlagId = flag_id;
385 g_FrameworkunifiedLogFlagRealTimeLog = flag_tbl.real_time_log;
387 g_flag_name.push_back(flag_vector.at(i));
388 g_FrameworkunifiedLogFlagMap.insert(std::make_pair(flag_id, flag_tbl));
391 logLevel[flag_id] = loglevel;
394 *logLevelArray = logLevel;
398 GetFrameworkunifiedLogRingBuffer(const UI_16 zone, CNSRingBuffer **ring_buf) {
399 TFrameworkunifiedLogMap::iterator itr = g_FrameworkunifiedLogMap.find(zone);
401 if (ring_buf == NULL) {
405 if (itr == g_FrameworkunifiedLogMap.end()) {
406 itr = g_FrameworkunifiedLogFlagMap.find(g_FrameworkunifiedLogFlagId);
407 if (itr == g_FrameworkunifiedLogFlagMap.end()) {
414 pthread_mutex_lock(&FrameworkunifiedLogMtx);
416 if (itr->second.ring_buffer == NULL) {
417 std::string file_path;
420 file_path = FRAMEWORKUNIFIEDLOG_RAMDISC_PATH;
421 file_path.append("/"); // LCOV_EXCL_BR_LINE 11:expect branch
422 file_path.append(itr->second.file_name);
424 index = NSLogGetFrameworkunifiedlogIndex(file_path.c_str());
425 itr->second.ring_buffer = new(std::nothrow) CNSRingBuffer(file_path, itr->second.size,
426 index + LOCK_NSLOG_ACCES_IF_1); // LCOV_EXCL_BR_LINE 11:expect branch
427 if (itr->second.ring_buffer != NULL) {
428 itr->second.ring_buffer->Open();
431 pthread_mutex_unlock(&FrameworkunifiedLogMtx);
433 *ring_buf = itr->second.ring_buffer;
437 MapShmInfo(int flagId) {
444 shm_fd = shm_open(FRAMEWORKUNIFIEDLOG_SHARED_MEM_NAME, O_RDONLY, S_IRWXU | S_IRWXO);
447 DEB_SYSLOG("shm_open error errno:%d", errno);
450 size = static_cast<int>(sizeof(int) * 2); // realTimeLog + flagIdNum
451 size += static_cast<int>(sizeof(int) * (flagId + 1)); // g_FrameworkunifiedLogFlagId + DefaultFlagId
453 pmap = reinterpret_cast<int *>(mmap(NULL, size, PROT_READ, MAP_SHARED, shm_fd, 0));
454 if (pmap == MAP_FAILED) {
456 DEB_SYSLOG("mmap error errno:%d", errno);
467 GetShmInfo(int flagId, int *realTimeLog, int *logLevel) {
470 if ((realTimeLog == NULL) || (logLevel == NULL)) {
474 p = static_cast<ssize_t *>(shm_pmap);
475 *realTimeLog = static_cast<int>(p[0]);
477 *logLevel = static_cast<int>(p[flagId]);
481 IsExistFrameworkunifiedLogCfgShmem(void) {
482 if (shm_pmap == reinterpret_cast<void *>(const_cast<unsigned int*>(default_log_cfgtbl))) {
489 NsLogIsZonePrintEnable(const UI_16 zone, UI_8 *mode) {
490 int l_realTimeLog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
491 int l_loglevel = FRAMEWORKUNIFIEDLOG_FLAG_MODE_RELEASE;
497 GetShmInfo(g_FrameworkunifiedLogFlagId, &l_realTimeLog, &l_loglevel);
498 *mode = static_cast<UI_8>(l_realTimeLog);
499 if (l_realTimeLog == FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF) {
503 if ((ZONEMASK(96) <= (TFrameworkunifiedZone)zone)
504 && ((TFrameworkunifiedZone)zone <= ZONEMASK(127))) {
509 if (g_FrameworkunifiedLogFlagRealTimeLog == FALSE) {
518 copyFrameworkunifiedLogCfgFile(const char *l_cSrcPath, const char *l_cDestPath) {
522 ssize_t l_nrd, l_nwr;
524 fd_in = open(l_cSrcPath, O_RDONLY | O_CLOEXEC);
529 fd_ot = open(l_cDestPath, O_WRONLY | O_CREAT | O_CLOEXEC, 0640);
536 l_nrd = read(fd_in, l_buf, sizeof(l_buf));
546 l_nwr = write(fd_ot, l_buf, l_nrd);
554 if (fsync(fd_ot) != 0) {
568 copyFrameworkunifiedLogCfgFileToNv(void) {
575 // LCOV_EXCL_BR_START 11:Excluded due to gcov constraints (others)
576 std::string config_dirpath = FRAMEWORKUNIFIEDLOG_CONFIG_NV;
577 std::string config_tempname = FRAMEWORKUNIFIEDLOG_CONFIG_NV;
578 std::string config_filename = FRAMEWORKUNIFIEDLOG_CONFIG_NV;
579 fd_in = open(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__FN, O_RDONLY);
580 config_tempname.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__TMP);
581 config_filename.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV);
582 // LCOV_EXCL_BR_STOP 11:Excluded due to gcov constraints (others)
588 unlink(config_tempname.c_str());
590 fd_ot = open(config_tempname.c_str(), O_WRONLY | O_CREAT, 0640); // LCOV_EXCL_BR_LINE 11:expect branch
592 DEB_SYSLOG("open error errno:%d", errno);
593 close(fd_in); // LCOV_EXCL_BR_LINE 11:expect branch
598 len = read(fd_in, c, sizeof(c));
607 len = write(fd_ot, c, sizeof(c));
615 if (fsync(fd_ot) != 0) {
624 if (rename(config_tempname.c_str(), config_filename.c_str()) != 0) {
626 DEB_SYSLOG("rename error errno:%d", errno);
630 fd_dr = open(config_dirpath.c_str(), O_RDONLY);
633 DEB_SYSLOG("mmap error errno:%d", errno);
642 #define WTYPE_NORMAL 0
643 #define WTYPE_RTIMELOG 1
645 WriteSharedMem(int flag, int realTimeLog, unsigned int flagIdNum, int *logLevelArray) {
651 if ((flag == WTYPE_NORMAL)
652 && (logLevelArray == NULL)) {
656 size = static_cast<int>(sizeof(int) * 2); // realTimeLog + flagIdNum
657 size += static_cast<int>(sizeof(int) * flagIdNum);
659 fd = shm_open(FRAMEWORKUNIFIEDLOG_SHARED_MEM_NAME, O_RDWR | O_CREAT, S_IRWXU | S_IRWXO);
662 DEB_SYSLOG("shm_open error errno:%d", errno);
666 if (ftruncate(fd, size) == -1) {
668 DEB_SYSLOG("ftruncate error errno:%d", errno);
673 // pp = (int *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
674 pp = static_cast<ssize_t *>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
675 if (pp == MAP_FAILED) {
677 DEB_SYSLOG("mmap error errno:%d", errno);
685 if (flag == WTYPE_NORMAL) {
691 for (unsigned int i = 0; i < flagIdNum; i++) {
692 *p = logLevelArray[i];
703 WriteSharedMemForFlagId(int realTimeLog, unsigned int flagIdNum, int flagId,
710 size = static_cast<int>(sizeof(int) * 2); // realTimeLog + flagIdNum
711 size += static_cast<int>(sizeof(int) * flagIdNum);
713 fd = shm_open(FRAMEWORKUNIFIEDLOG_SHARED_MEM_NAME, O_RDWR | O_CREAT, S_IRWXU | S_IRWXO);
716 DEB_SYSLOG("shm_open error errno:%d", errno);
720 if (ftruncate(fd, size) == -1) {
722 DEB_SYSLOG("ftruncate error errno:%d", errno);
727 pp = static_cast<ssize_t *>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
728 if (pp == MAP_FAILED) {
730 DEB_SYSLOG("mmap error errno:%d", errno);
743 p[flagId] = logLevel;
752 IsExistFrameworkunifiedLogCfgNv(void) {
754 // LCOV_EXCL_BR_START 11:Excluded due to gcov constraints (others)
755 std::string config_filename = FRAMEWORKUNIFIEDLOG_CONFIG_NV;
756 config_filename.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV);
757 // LCOV_EXCL_BR_STOP 11:Excluded due to gcov constraints (others)
759 fp = fopen(config_filename.c_str(), "re");
769 get_readlink_path(char *path) {
770 CHAR exe_path[EXE_STR_LEN];
771 CHAR buf[EXE_STR_LEN];
779 if (exe_link_path[0] == 0) {
780 pid_t pid = static_cast<pid_t>(syscall(__NR_getpid));
781 sprintf(exe_path, "/proc/%d/exe", pid); // NOLINT (readability/nolint)
782 memset(buf, 0, sizeof(buf));
783 len = readlink(exe_path, buf, (sizeof(buf) - 1));
784 if (len != -1) { // LCOV_EXCL_BR_LINE 200: exe_path can not non-existent
785 strcpy(exe_link_path, buf); // NOLINT (readability/nolint)
787 // LCOV_EXCL_START 200
788 AGL_ASSERT_NOT_TESTED();
789 fprintf(stderr, "<WARNING>FRAMEWORKUNIFIEDLOG[%s:L%d]Can't get readlink path(%s). errno(%d)\n", __FUNCTION__, __LINE__,
791 DEB_SYSLOG("<WARNING>Can't get readlink path(%s)(errno:%d)", exe_path, errno);
793 // LCOV_EXCL_STOP 200
796 strcpy(path, exe_link_path); // NOLINT (readability/nolint)
801 readConfig(int *realTimeLog, int **logLevelArray) {
802 CHAR buf[EXE_STR_LEN];
804 if (get_readlink_path(buf)) { // LCOV_EXCL_BR_LINE 200:get_readlink_path can not return false
805 std::string config_filename;
806 std::string exe_str = buf; // LCOV_EXCL_BR_LINE 11:expect branch
808 // LCOV_EXCL_BR_START 11:Excluded due to gcov constraints (others)
809 if (IsExistFrameworkunifiedLogCfgNv()) {
810 config_filename = FRAMEWORKUNIFIEDLOG_CONFIG_NV;
811 config_filename.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV);
813 config_filename = FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__FN;
815 // LCOV_EXCL_BR_STOP 11:Excluded due to gcov constraints (others)
816 CNSConfigReader *config_reader = new CNSConfigReader(); // LCOV_EXCL_BR_LINE 11:expect branch
817 if (config_reader != NULL) { // LCOV_EXCL_BR_LINE 5: new's error case
818 if (config_reader->Parse(config_filename)
819 == eFrameworkunifiedStatusOK) {
820 CreateFrameworkunifiedLogFileTbl(config_reader, exe_str, realTimeLog, logLevelArray); // LCOV_EXCL_BR_LINE 11:expect branch
821 MapShmInfo(g_FrameworkunifiedLogFlagId); // LCOV_EXCL_BR_LINE 11:expect branch
823 DEB_SYSLOG("Parseg error %s", config_filename.c_str());
826 // LCOV_EXCL_START 5: new's error case
827 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
828 DEB_SYSLOG("new CNSConfigReader error");
831 delete config_reader; // LCOV_EXCL_BR_LINE 11:expect branch1
833 // LCOV_EXCL_START 5: get_readlink_path can not return false
834 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
835 DEB_SYSLOG("get_readlink_path error");
840 //////////////////////////////////////////
841 // NSLogGetFrameworkunifiedlogFileTotalNum
842 //////////////////////////////////////////
844 NSLogGetFrameworkunifiedlogFileTotalNum(void) {
845 return static_cast<UI_32>((g_FrameworkunifiedLogMap.size() + g_FrameworkunifiedLogFlagMap.size()));
848 //////////////////////////////////////////
849 // NSLogGetFrameworkunifiedlogFileName
850 //////////////////////////////////////////
852 NSLogGetFrameworkunifiedlogFileName(UI_32 index) {
855 if ((g_FrameworkunifiedLogMap.size() + g_FrameworkunifiedLogFlagMap.size()) <= index) {
859 TFrameworkunifiedLogMap::iterator itr;
860 TFrameworkunifiedLogMap::iterator itr_end;
863 if (index < g_FrameworkunifiedLogMap.size()) {
865 itr = g_FrameworkunifiedLogMap.begin();
866 itr_end = g_FrameworkunifiedLogMap.end();
868 cnt = static_cast<UI_32>(g_FrameworkunifiedLogMap.size());
869 itr = g_FrameworkunifiedLogFlagMap.begin();
870 itr_end = g_FrameworkunifiedLogFlagMap.end();
873 for (; itr != itr_end; itr++, cnt++) {
875 name = itr->second.file_name.c_str();
882 //////////////////////////////////////////
883 // NSLogGetFrameworkunifiedlogIndex
884 //////////////////////////////////////////
886 NSLogGetFrameworkunifiedlogIndex(PCSTR filename) {
887 TFrameworkunifiedLogMap::iterator itr;
888 TFrameworkunifiedLogMap::iterator itr_end;
892 * Defining a NULL for arguments results in exceptions.
894 std::string fname = filename;
896 itr = g_FrameworkunifiedLogFlagMap.begin();
897 itr_end = g_FrameworkunifiedLogFlagMap.end();
898 for (; itr != itr_end; itr++, i++) {
899 if (fname.find(itr->second.file_name) != std::string::npos) {
904 itr = g_FrameworkunifiedLogMap.begin();
905 itr_end = g_FrameworkunifiedLogMap.end();
906 for (; itr != itr_end; itr++, i++) {
907 if (fname.find(itr->second.file_name) != std::string::npos) {
915 ConvertEndian(UI_32 *pvar) {
916 UI_32 retVal = (UI_32)0;
923 retVal = (((var & 0xFF000000) >> 24) |
924 ((var & 0x00FF0000) >> 8) |
925 ((var & 0x0000FF00) << 8) |
926 ((var & 0x000000FF) << 24));
931 check_syslog_opened(void) {
933 openlog(0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_USER);
939 tick_msec_get(void) {
942 if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) { // LCOV_EXCL_BR_LINE 5: clock_gettime's error case
943 // LCOV_EXCL_START 5: clock_gettime's error case
944 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
948 return tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
952 num2string(PSTR buf, int digits, UI_32 num) {
967 c = static_cast<char>(num / 10000);
968 *p++ = static_cast<char>(c + '0');
969 num = num - (c * 10000);
970 c = static_cast<char>(num / 1000);
971 *p++ = static_cast<char>(c + '0');
972 num = num - (c * 1000);
983 c = static_cast<char>(num / 100);
984 *p++ = static_cast<char>(c + '0');
985 num = num - (c * 100);
995 c = static_cast<char>(num / 10);
996 *p++ = static_cast<char>(c + '0');
997 *p = static_cast<char>(num - (c * 10) + '0');
1008 c = static_cast<char>(num / dig);
1009 *p++ = static_cast<char>(c + '0');
1010 num = num - (c * dig);
1013 *p = static_cast<char>(num + '0');
1017 return static_cast<int>(p - buf + 1);
1021 _GetTimeString2(PSTR format) {
1023 UI_32 hh, mm, ss, ms;
1025 // "%02d:%02d:%02d.%03d/"
1026 tick = tick_msec_get();
1028 ms = static_cast<UI_32>(tick % 1000);
1030 num2string(&format[9], 3, ms);
1034 ss = static_cast<UI_32>(tick % 60);
1036 num2string(&format[6], 2, ss);
1039 mm = static_cast<UI_32>(tick % 60);
1041 num2string(&format[3], 2, mm);
1044 hh = static_cast<UI_32>(tick);
1045 num2string(&format[0], 2, hh);
1048 // LCOV_EXCL_START 8: dead code
1050 _GetTimeString(PSTR format, UI_16 length) {
1051 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 8: dead code
1053 UI_32 hh, mm, ss, ms;
1055 tick = tick_msec_get();
1056 ms = static_cast<UI_32>(tick % 1000);
1058 ss = static_cast<UI_32>(tick % 60);
1060 mm = static_cast<UI_32>(tick % 60);
1062 hh = static_cast<UI_32>(tick);
1064 snprintf(format, (length - 1), "%02d:%02d:%02d.%03d/", hh, mm, ss, ms);
1069 ClockCyclesToMs(void) {
1070 return ClockCycle() / 1000;
1074 _in_NsLog_part1(const UI_16 p_lLine_i, const UI_16 f_uiZoneIndex,
1075 PCSTR p_pstrClassName_i, CHAR *format) {
1076 CHAR t_name[16]; // thread name (not more than 15 characters)
1080 if (format == NULL) {
1084 // fixed format : "%s%ld/%d/%s/%05d/%s/%d/=%s\r\n"
1091 len = num2string(p, 0, g_msgcounter);
1096 len = num2string(p, 0, f_uiZoneIndex);
1100 // Check whether thread name has previously been set
1102 if (tls_strProcessName[0] != 0) {
1103 tls_strProcessName[sizeof(t_name) - 1] = '\0';
1104 strcpy(t_name, tls_strProcessName); // NOLINT (readability/nolint)
1106 if (prctl(PR_GET_NAME, t_name) != 0) {
1107 strcpy(t_name, "UNKNOWN"); // NOLINT (readability/nolint)
1109 NsLogSetProcessName(t_name);
1113 strcpy(p, t_name); // NOLINT (readability/nolint)
1114 p += strlen(t_name);
1119 tid = static_cast<pid_t>(syscall(__NR_gettid));
1121 len = num2string(p, 5, tid);
1125 // p_pstrClassName_i
1126 if (p_pstrClassName_i) {
1127 strcpy(p, p_pstrClassName_i); // NOLINT (readability/nolint)
1129 strcpy(p, "(null)"); // NOLINT (readability/nolint)
1135 len = num2string(p, 0, p_lLine_i);
1144 _in_NsLog_part2(const UI_16 f_uiZoneIndex, CHAR *p, CHAR *format) {
1155 if (format == NULL) {
1159 l_uiLength = static_cast<UI_32>(p - format);
1161 // Write log message
1162 if (l_uiLength > 0) {
1163 UI_8 l_realTimeLog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
1164 BOOL IsZonePrintEnable = NsLogIsZonePrintEnable(f_uiZoneIndex, &l_realTimeLog);
1165 if (l_realTimeLog == FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_FREEZE) {
1166 if (g_qid != (mqd_t)(-1)) {
1168 g_qid = (mqd_t)(-1);
1172 if (g_LocalFrameworkunifiedLogParams.uiLogOptions & LPRINT) {
1173 ssize_t l_writtenbyte;
1174 std::string usb_realtime_filename;
1175 std::string ownAdrr;
1176 std::string writeAdrr;
1177 if (IsZonePrintEnable == TRUE) {
1178 switch (l_realTimeLog) {
1179 case FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF:
1182 case FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_UART:
1184 fwrite(format, 1, l_uiLength, stdout);
1186 case FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_USB:
1187 if (g_qid == (mqd_t)(-1)) {
1188 struct mq_attr qattr;
1191 qattr.mq_maxmsg = USB_REALTIME_MSGMAX;
1192 qattr.mq_msgsize = USB_REALTIME_SIZMAX;
1193 qattr.mq_curmsgs = 0;
1194 if ((g_qid = mq_open(USB_REALTIME_QNAME, O_WRONLY | O_CREAT, 0666, &qattr)) == (mqd_t)(-1)) {
1195 fprintf(stderr, "Failed to create Message Queue %s, errno=%d\n", USB_REALTIME_QNAME, errno);
1199 l_writtenbyte = mq_send(g_qid, format, l_uiLength, 1);
1200 if (l_writtenbyte == -1) {
1201 fprintf(stderr, "mq_send ERROR, errno=%d\n", errno);
1203 g_qid = (mqd_t)(-1);
1206 case FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_USB_DISABLE:
1207 if (g_qid != (mqd_t)(-1)) {
1209 g_qid = (mqd_t)(-1);
1217 if (g_LocalFrameworkunifiedLogParams.uiLogOptions & LSLOGGER) {
1218 check_syslog_opened();
1219 syslog(LOG_ERR, "%s", format);
1223 CNSRingBuffer *ring_buffer = NULL;
1224 GetFrameworkunifiedLogRingBuffer(f_uiZoneIndex, &ring_buffer);
1226 if (ring_buffer != NULL) {
1227 if (ring_buffer->IsOpen()) {
1228 ring_buffer->Write(format, l_uiLength);
1236 NsLogTime(const UI_16 f_uiZoneIndex, PCSTR lpszFormat) {
1237 CHAR format[MAX_QUEUE_MSG_SIZE];
1239 CHAR *q = reinterpret_cast<CHAR *>(const_cast<char *>(lpszFormat));
1242 // fixed format : "%s/=%s\r\n"
1250 * Defining a NULL for the lpszFormat causes a segmentation fault.
1252 for (i = 0; *q && i < MAX_QUEUE_MSG_SIZE - (p - format) - 3; i++) { // '3': '\r''\n''\0'
1255 _in_NsLog_part2(f_uiZoneIndex, p, format);
1259 NsLogData(const UI_16 f_uiZoneIndex, PCSTR data, UI_32 size) {
1263 GetShmInfo(g_FrameworkunifiedLogFlagId, &l_realTimeLog, &l_logLevel);
1264 if (l_realTimeLog == FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_FREEZE) {
1269 CNSRingBuffer *ring_buffer = NULL;
1270 GetFrameworkunifiedLogRingBuffer(f_uiZoneIndex, &ring_buffer); // LCOV_EXCL_BR_LINE 11:expect branch
1271 if (ring_buffer != NULL) {
1272 if (ring_buffer->IsOpen()) {
1273 ring_buffer->Write(data, size);
1280 NsLog0(const UI_16 p_lLine_i, // Line number where message was generated
1281 const UI_16 f_uiZoneIndex,
1282 PCSTR p_pstrClassName_i,
1284 CHAR format[MAX_QUEUE_MSG_SIZE];
1286 CHAR *q = reinterpret_cast<CHAR *>(const_cast<char *>(lpszFormat));
1289 p = _in_NsLog_part1(p_lLine_i, f_uiZoneIndex, p_pstrClassName_i, format);
1292 * Setting p_pstrClassName_i to NULL results in a segmentation fault.
1294 for (i = 0; *q && i < MAX_QUEUE_MSG_SIZE - (p - format) - 3; i++) { // '3': '\r''\n''\0'
1297 _in_NsLog_part2(f_uiZoneIndex, p, format);
1301 NsLog(const UI_16 p_lLine_i, // Line number where message was generated
1302 const UI_16 f_uiZoneIndex,
1303 PCSTR p_pstrClassName_i,
1307 CHAR format[MAX_QUEUE_MSG_SIZE];
1312 va_start(argList, lpszFormat);
1314 p = _in_NsLog_part1(p_lLine_i, f_uiZoneIndex, p_pstrClassName_i, format);
1315 size = static_cast<int>(MAX_QUEUE_MSG_SIZE - (p - format) - 3);
1316 num = vsnprintf(p, size, lpszFormat, argList);
1319 } else if (num < 0) {
1323 _in_NsLog_part2(f_uiZoneIndex, p, format);
1329 NsLogSetFrameworkunifiedLogParams(FRAMEWORKUNIFIEDLOGPARAM *p_FrameworkunifiedLogParams) {
1330 int l_realTimeLog = 0;
1331 int *l_logLevelArray = NULL;
1332 CHAR buf[EXE_STR_LEN];
1334 if (p_FrameworkunifiedLogParams == NULL) {
1338 get_readlink_path(buf);
1339 if (g_flag_name.empty()) { // LCOV_EXCL_BR_LINE 200:get_readlink_path can not return false
1340 std::string config_filename;
1341 CHAR buf[EXE_STR_LEN];
1343 if (IsExistFrameworkunifiedLogCfgNv()) { // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1344 config_filename = FRAMEWORKUNIFIEDLOG_CONFIG_NV; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1345 config_filename.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV); // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1347 config_filename = FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__FN; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1349 if (get_readlink_path(buf)) {
1350 std::string exe_str = buf; // LCOV_EXCL_BR_LINE 11:expect branch
1351 CNSConfigReader *config_reader = new CNSConfigReader(); // LCOV_EXCL_BR_LINE 11:expect branch
1352 if (config_reader != NULL) { // LCOV_EXCL_BR_LINE 5: new's error case
1353 if (config_reader->Parse(config_filename)
1354 == eFrameworkunifiedStatusOK) {
1355 CreateFrameworkunifiedLogFileTbl(config_reader, exe_str, &l_realTimeLog, &l_logLevelArray); // LCOV_EXCL_BR_LINE 11:expect branch
1356 MapShmInfo(g_FrameworkunifiedLogFlagId); // LCOV_EXCL_BR_LINE 11:expect branch
1358 DEB_SYSLOG("Parse error %s", config_filename.c_str());
1361 // LCOV_EXCL_START 5: new's error case
1362 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1363 DEB_SYSLOG("new CNSConfigReader error");
1366 delete config_reader; // LCOV_EXCL_BR_LINE 11:expect branch
1368 // LCOV_EXCL_START 5: get_readlink_path can not return false
1369 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1370 DEB_SYSLOG("get_readlink_path error");
1378 if (!IsExistFrameworkunifiedLogCfgShmem()) {
1379 if (l_logLevelArray == NULL) {
1380 readConfig(&l_realTimeLog, &l_logLevelArray);
1382 WriteSharedMem(WTYPE_NORMAL, l_realTimeLog, g_FlagIdNum, l_logLevelArray);
1383 MapShmInfo(g_FrameworkunifiedLogFlagId);
1385 if (l_logLevelArray != NULL) {
1386 free(l_logLevelArray);
1391 * Segmentation faults occur when NULL is defined as arguments.
1393 memcpy(&g_LocalFrameworkunifiedLogParams, p_FrameworkunifiedLogParams, sizeof(FRAMEWORKUNIFIEDLOGPARAM));
1395 // Force Output ZONE_NS_WAR(8),ZONE_NS_ERR(9)
1396 TFrameworkunifiedZone l_uiZoneMask = g_LocalFrameworkunifiedLogParams.uiZoneMask[0];
1397 l_uiZoneMask = l_uiZoneMask | GET_ZONE_BIT_MASK(ZONE_NS_WAR) | GET_ZONE_BIT_MASK(ZONE_NS_ERR);
1398 g_LocalFrameworkunifiedLogParams.uiZoneMask[0] = l_uiZoneMask;
1400 // Force Output Zones
1402 TFrameworkunifiedLogMap::iterator itr = g_FrameworkunifiedLogMap.begin();
1403 TFrameworkunifiedLogMap::iterator itr_end = g_FrameworkunifiedLogMap.end();
1404 for (; itr != itr_end; itr++) {
1405 if (itr->second.force_output) {
1406 UI_16 zone = static_cast<UI_16>(itr->first);
1407 TFrameworkunifiedZone *pl_uiZoneMask = &g_LocalFrameworkunifiedLogParams.uiZoneMask[GET_ZONE_INDEX(zone)];
1408 *pl_uiZoneMask |= GET_ZONE_BIT_MASK(zone);
1415 NsLogSetProcessName(PCSTR p_strProcessName_i) {
1416 if ((p_strProcessName_i != NULL) && (strlen(p_strProcessName_i) < _countof(tls_strProcessName))) {
1417 strcpy(tls_strProcessName, p_strProcessName_i); // NOLINT (readability/nolint)
1422 NsLogSetControlMask(TFrameworkunifiedZoneMask p_NSLogControl_i) {
1423 for (UI_32 zoneIndex = 0; zoneIndex < ZONE_MASK_ARRAY_ELTS; zoneIndex++) {
1426 * Setting NULL to arguments terminates abnormally
1428 g_LocalFrameworkunifiedLogParams.uiZoneMask[zoneIndex] = p_NSLogControl_i[zoneIndex];
1433 NsLogGetControlMask(TFrameworkunifiedZoneMask p_Zonemask_i) {
1434 for (UI_32 zoneIndex = 0; zoneIndex < ZONE_MASK_ARRAY_ELTS; zoneIndex++) {
1437 * Setting NULL to arguments terminates abnormally
1439 p_Zonemask_i[zoneIndex] = g_LocalFrameworkunifiedLogParams.uiZoneMask[zoneIndex];
1444 NsLogIsZoneSet(UI_32 set_zone) {
1448 GetShmInfo(g_FrameworkunifiedLogFlagId, &realTimeLog, &logLevel);
1450 if (logLevel == FRAMEWORKUNIFIEDLOG_FLAG_MODE_DEBUG)
1455 if (set_zone >= BITS_IN_ZONE_MASK) {
1459 if (0 != (g_LocalFrameworkunifiedLogParams.uiZoneMask[ GET_ZONE_INDEX(set_zone) ] & GET_ZONE_BIT_MASK(set_zone))) {
1467 NsLogSetLogMethod(UI_8 p_eMethod_i) {
1468 g_LocalFrameworkunifiedLogParams.uiLogOptions = p_eMethod_i;
1472 NsLogGetLogMethod(void) {
1473 return g_LocalFrameworkunifiedLogParams.uiLogOptions;
1477 NsLogSetSeverity(TFrameworkunifiedLoggerSeverity p_eLogSeverity_i) {
1478 g_LocalFrameworkunifiedLogParams.eSeverity = p_eLogSeverity_i;
1481 TFrameworkunifiedLoggerSeverity
1482 NsLogGetSeverity(void) {
1483 return g_LocalFrameworkunifiedLogParams.eSeverity;
1487 NsLogDetermineLogMethod(PCSTR output_type) {
1489 const CHAR delims[] = "|";
1492 PSTR saveptr = NULL;
1494 if (output_type != NULL) {
1495 // since strtok modifies the var. we
1496 // must create a copy of the string.
1497 parse = strdup(output_type);
1498 p = strtok_r (parse, delims, &saveptr); // NOLINT (readability/nolint)
1500 // slogger|msgq|console
1502 if (!strcasecmp(p, "slogger")) {
1504 if (!strcmpi(p, "slogger")) {
1506 outmask |= LSLOGGER;
1508 } else if (!strcasecmp(p, "msgq")) {
1510 } else if (!strcmpi(p, "msgq")) {
1514 } else if (!strcasecmp(p, "console")) {
1516 } else if (!strcmpi(p, "console")) {
1520 } else if (!strcasecmp(p, "shmem")) {
1522 } else if (!strcmpi(p, "shmem")) {
1524 outmask |= LSHAREDMEM;
1529 p = strtok_r (NULL, delims, &saveptr); // NOLINT (readability/nolint)
1532 // since we made dup of the char * passed we need to free it!
1533 if (parse != NULL) {
1542 NsLogSetZones(UI_32 f_uiZoneCount, ...) {
1543 va_list l_tArguments;
1545 // Initialize the variable argument list
1546 va_start(l_tArguments, f_uiZoneCount);
1548 // Iterate the variable argument list
1549 for (UI_32 l_uiArgumentCount = 0; l_uiArgumentCount < f_uiZoneCount; l_uiArgumentCount++) {
1551 UI_32 l_uiZone = va_arg(l_tArguments, UI_32); // LCOV_EXCL_BR_LINE 11:expect branch
1553 if (l_uiZone < BITS_IN_ZONE_MASK) {
1554 // add zone value to existing mask
1555 UI_32 l_uiZoneMask = g_LocalFrameworkunifiedLogParams.uiZoneMask[GET_ZONE_INDEX(l_uiZone)];
1556 l_uiZoneMask = l_uiZoneMask | GET_ZONE_BIT_MASK(l_uiZone);
1557 g_LocalFrameworkunifiedLogParams.uiZoneMask[GET_ZONE_INDEX(l_uiZone)] = l_uiZoneMask;
1561 va_end(l_tArguments);
1565 NsLogParseZones(FRAMEWORKUNIFIEDLOGPARAM *p_FrameworkunifiedLogParams, UI_32 f_uiZoneCount, ...) {
1566 va_list l_tArguments;
1568 if (p_FrameworkunifiedLogParams == NULL) {
1572 // Initialize the variable argument list
1573 va_start(l_tArguments, f_uiZoneCount);
1575 // Iterate the variable argument list
1576 for (UI_32 l_uiArgumentCount = 0; l_uiArgumentCount < f_uiZoneCount; l_uiArgumentCount++) {
1578 UI_32 l_uiZone = va_arg(l_tArguments, UI_32); // LCOV_EXCL_BR_LINE 11:expect branch
1580 if (l_uiZone < BITS_IN_ZONE_MASK) {
1582 UI_32 l_uiZoneMask = p_FrameworkunifiedLogParams->uiZoneMask[GET_ZONE_INDEX(l_uiZone)];
1583 l_uiZoneMask = l_uiZoneMask | GET_ZONE_BIT_MASK(l_uiZone);
1584 p_FrameworkunifiedLogParams->uiZoneMask[GET_ZONE_INDEX(l_uiZone)] = l_uiZoneMask;
1588 va_end(l_tArguments);
1592 NsLog_EvtCnt(UI_16 Cnt_Id, UI_16 Evt_Id, UI_8 nu, ...) {
1595 va_start(EC_list, nu);
1597 UI_32 ts = (UI_32)ClockCyclesToMs();
1599 memset(&log, 0, sizeof(log));
1601 log.ts = ConvertEndian(&ts);
1602 log.event_id = (UI_8)Evt_Id;
1603 log.grp_ID = (UI_8)(Evt_Id >> 8);
1604 log.cnt_ID = Cnt_Id;
1608 log.data[0] = (UI_8)va_arg(EC_list, int);
1610 log.typeofdata = COMMON;
1613 log.data[0] = (UI_8)va_arg(EC_list, int);;
1614 log.phase = (SystemPhase)va_arg(EC_list, int);
1615 log.typeofdata = COMMON;
1618 for (i = 0; i < nu; i++) {
1619 log.data[i] = (UI_8)va_arg(EC_list, int);
1622 log.typeofdata = EVENT_SPECIFIC;
1625 for (i = 0; i < (nu - 1); i++) {
1626 log.data[i] = (UI_8)va_arg(EC_list, int);
1628 log.phase = (SystemPhase)va_arg(EC_list, int);
1629 log.typeofdata = EVENT_SPECIFIC;
1632 memset(&log, 0, sizeof(log));
1636 if (log.cnt_ID != 0 && log.grp_ID != 0) {
1637 if (g_hSSEventLogQ == INVALID_HANDLE) {
1638 g_hSSEventLogQ = McOpenSender(EVENTLOG_MSGQ_NAME);
1640 McSend(g_hSSEventLogQ, tls_strProcessName, SS_MSG_LOGGER_CNT_EVTLOG, sizeof(log), &log);
1647 NsLog_Evt(UI_16 Evt_Id, UI_8 nu, ...) {
1648 st_LogEvent log_Evt;
1650 va_start(E_list, nu);
1651 UI_32 ts = (UI_32)ClockCyclesToMs();
1653 memset(&log_Evt, 0, sizeof(st_LogEvent));
1655 log_Evt.ts = ConvertEndian(&ts);
1656 log_Evt.grp_ID = (UI_8)(Evt_Id >> 8);
1657 log_Evt.event_id = (UI_8)Evt_Id;
1662 log_Evt.data[0] = (UI_8)va_arg(E_list, int); // LCOV_EXCL_BR_LINE 11:expect branch
1663 log_Evt.typeofdata = COMMON;
1666 for (i = 0; i < nu; i++) {
1667 log_Evt.data[i] = (UI_8)va_arg(E_list, int); // LCOV_EXCL_BR_LINE 11:expect branch
1669 log_Evt.typeofdata = EVENT_SPECIFIC;
1672 memset(&log_Evt, 0, sizeof(st_LogEvent));
1675 if (log_Evt.grp_ID != 0) {
1676 if (g_hSSEventLogQ == INVALID_HANDLE) {
1677 g_hSSEventLogQ = McOpenSender(EVENTLOG_MSGQ_NAME);
1680 McSend(g_hSSEventLogQ, tls_strProcessName, SS_MSG_EVTLOG, sizeof(log_Evt), &log_Evt);
1687 NsLog_Cnt(UI_16 Cnt_Id, UI_8 nu, ...) {
1688 st_LogCount log_Cnt;
1690 va_start(C_list, nu);
1692 memset(&log_Cnt, 0, sizeof(st_LogCount));
1693 log_Cnt.cnt_id = Cnt_Id;
1697 log_Cnt.phase = NORMAL;
1700 log_Cnt.phase = (SystemPhase)va_arg(C_list, int); // LCOV_EXCL_BR_LINE 11:expect branch
1703 memset(&log_Cnt, 0, sizeof(st_LogCount));
1706 if (log_Cnt.cnt_id != 0) {
1707 if (g_hSSEventLogQ == INVALID_HANDLE) {
1708 g_hSSEventLogQ = McOpenSender(EVENTLOG_MSGQ_NAME);
1710 McSend(g_hSSEventLogQ, tls_strProcessName, SS_MSG_LOGGERCNT, sizeof(log_Cnt), &log_Cnt);
1715 //////////////////////////////////////////
1716 // NSPrintPerformanceLog
1717 //////////////////////////////////////////
1719 NSLogPrintPerformanceLog(const UI_16 f_ui16Line, PCSTR f_cFuncName, PCSTR __format, ...) {
1722 CHAR l_cFormat[MAX_PLOG_STRING_SIZE] = {};
1723 CHAR l_cTimeFormat[MAX_TIME_FORMATSTR_LEN] = {};
1724 UI_64 l_ui64CurrentTime = 0;
1726 if (g_hNSplogMsgQ == INVALID_HANDLE) {
1727 g_hNSplogMsgQ = OpenSender(NS_PLOGQ);
1730 if (g_FrameworkunifiedLogPParams.ui64GapInuS == 0) {
1731 FILE *l_fpPLogGap = NULL;
1732 l_fpPLogGap = fopen(PLOG_GAP_FILE, "re");
1733 if (l_fpPLogGap != NULL) {
1734 CHAR l_cBuffer[MAX_GAP_BUFFER_LEN] = {};
1735 if (fgets(l_cBuffer, MAX_GAP_BUFFER_LEN, l_fpPLogGap) != NULL) {
1736 g_FrameworkunifiedLogPParams.ui64GapInuS = (unsigned)atoll(l_cBuffer);
1738 fclose(l_fpPLogGap);
1742 if (g_FrameworkunifiedLogPParams.eTimeFormat == EPLOG_TIME_FORMAT_USEC) {
1743 #ifdef AGL_PosixBasedOS001LEGACY_USED
1744 l_ui64CurrentTime = ClockCycle() + g_FrameworkunifiedLogPParams.ui64GapInuS;
1746 snprintf(l_cTimeFormat, MAX_TIME_FORMATSTR_LEN, "%s", "us");
1747 } else if (g_FrameworkunifiedLogPParams.eTimeFormat == EPLOG_TIME_FORMAT_MSEC) {
1748 l_ui64CurrentTime = ClockCyclesToMs() + (g_FrameworkunifiedLogPParams.ui64GapInuS / 1000);
1749 snprintf(l_cTimeFormat, MAX_TIME_FORMATSTR_LEN, "%s", "ms");
1750 } else if (g_FrameworkunifiedLogPParams.eTimeFormat == EPLOG_TIME_FORMAT_SEC) {
1751 #ifdef AGL_PosixBasedOS001LEGACY_USED
1752 l_ui64CurrentTime = (ClockCycle() / 1000000) + (g_FrameworkunifiedLogPParams.ui64GapInuS / 1000000);
1754 snprintf(l_cTimeFormat, MAX_TIME_FORMATSTR_LEN, "%s", "s");
1759 va_start(arg, __format);
1760 vsnprintf(l_cFormat, MAX_PLOG_STRING_SIZE - 1, __format, arg);
1761 l_cFormat[MAX_PLOG_STRING_SIZE - 1] = '\0';
1764 CHAR l_cMsg[MAX_QUEUE_MSG_SIZE] = {};
1765 snprintf(l_cMsg, MAX_QUEUE_MSG_SIZE - 1, "PLog: %12llu[%s]:%s %s: %s: %s",
1766 l_ui64CurrentTime, l_cTimeFormat, (g_FrameworkunifiedLogPParams.ui64GapInuS > 0) ? ("o") : ("x"),
1767 tls_strProcessName, f_cFuncName, l_cFormat);
1769 if (g_FrameworkunifiedLogPParams.uiLogOutputOptions & EPLOG_SLOG) {
1770 // send to system logger
1771 check_syslog_opened();
1772 syslog(LOG_INFO, "%s", l_cMsg);
1775 if (g_FrameworkunifiedLogPParams.uiLogOutputOptions & EPLOG_TRACEEVENT) {
1776 #ifdef AGL_PosixBasedOS001LEGACY_USED
1777 (VOID)trace_nlogf(_NTO_TRACE_USERFIRST, MAX_QUEUE_MSG_SIZE - 1, l_cMsg);
1781 if (g_FrameworkunifiedLogPParams.uiLogOutputOptions & EPLOG_MSGQ) {
1782 // send to message queue /NSplog
1783 if (g_hNSplogMsgQ != INVALID_HANDLE) {
1784 #ifdef AGL_PosixBasedOS001LEGACY_USED
1785 strlcat(l_cMsg, "\n", sizeof(l_cMsg)); // insert new line... user may not have.
1787 if (SendMessage(g_hNSplogMsgQ, strlen(l_cMsg),
1788 reinterpret_cast<void *>(const_cast<char *>(l_cMsg))) != eFrameworkunifiedStatusOK) {
1789 // Note: Nothing will be printed on a failure.
1796 //////////////////////////////////////////
1798 //////////////////////////////////////////
1800 NSLogEnablePLog(BOOL f_bEnable) {
1801 g_FrameworkunifiedLogPParams.bIsPLogEnabled = f_bEnable;
1804 //////////////////////////////////////////
1805 // NsLogIsPLogEnabled
1806 //////////////////////////////////////////
1808 NsLogIsPLogEnabled(void) {
1809 return g_FrameworkunifiedLogPParams.bIsPLogEnabled;
1812 //////////////////////////////////////////
1813 // NSLogSetPlogTimeFormat
1814 //////////////////////////////////////////
1816 NSLogSetPlogTimeFormat(EPLOG_TIME_FORMAT f_ePlogTimeFormat) {
1817 g_FrameworkunifiedLogPParams.eTimeFormat = f_ePlogTimeFormat;
1820 //////////////////////////////////////////
1821 // NSLogSetPlogOutputOptions
1822 //////////////////////////////////////////
1824 NSLogSetPlogOutputOptions(UI_8 f_uiPlogOutputOption) {
1825 g_FrameworkunifiedLogPParams.uiLogOutputOptions = f_uiPlogOutputOption;
1828 //////////////////////////////////////////
1829 // NsLogInitialize for Diag Method
1830 //////////////////////////////////////////
1832 NsLogInitialize(void) {
1833 std::string config_filename = FRAMEWORKUNIFIEDLOG_CONFIG_NV; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1834 config_filename.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV); // LCOV_EXCL_BR_LINE 11:expect branch
1837 int *l_logLevelArray = NULL;
1839 if (unlink(config_filename.c_str()) != 0) {
1840 // error TODO wirte log, bit, not use frameworkunifiedlog
1843 readConfig(&l_realTimelog, &l_logLevelArray); // LCOV_EXCL_BR_LINE 11:expect branch
1844 if (l_logLevelArray == NULL) {
1847 WriteSharedMem(WTYPE_NORMAL, l_realTimelog, g_FlagIdNum, l_logLevelArray); // LCOV_EXCL_BR_LINE 11:expect branch
1848 if (l_logLevelArray != NULL) {
1849 free(l_logLevelArray);
1853 static void writeUpdateConfigForString(std::string &name, // NOLINT (readability/nolint)
1854 std::string set_key,
1855 std::string value) {
1856 std::string flag_loglevel_key = name;
1857 flag_loglevel_key.append(set_key);
1859 std::string config_filename = FRAMEWORKUNIFIEDLOG_CONFIG_NV; // LCOV_EXCL_BR_LINE 11:expect branch
1860 std::string config_tmpfilename = FRAMEWORKUNIFIEDLOG_CONFIG_NV; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1861 config_filename.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV); // LCOV_EXCL_BR_LINE 11:expect branch
1863 config_tmpfilename.append(FRAMEWORKUNIFIEDLOG_CONFIG_TMP_NV);
1865 unlink(config_tmpfilename.c_str());
1866 if (copyFrameworkunifiedLogCfgFile(config_filename.c_str(), config_tmpfilename.c_str()) != 0) {
1867 DEB_SYSLOG("fail to copy file. no update config.");
1871 // CNSConfigWriter *l_pConfigWriter = new(std::nothrow) CNSConfigWriter(config_filename.c_str());
1872 CNSConfigWriter *l_pConfigWriter = new(std::nothrow) CNSConfigWriter(config_tmpfilename.c_str()); // LCOV_EXCL_BR_LINE 11:expect branch
1874 if (l_pConfigWriter != NULL) {
1876 // l_iReturnState = ConfigWriterUpdateValue(l_hHandle, l_sKeyValue.c_str(), actualOutput.c_str());
1877 l_pConfigWriter->Set(flag_loglevel_key, value);
1881 // ConfigWriterClose(l_hHandle);
1882 l_pConfigWriter->Save();
1883 delete l_pConfigWriter;
1884 l_pConfigWriter = NULL;
1886 if (rename(config_tmpfilename.c_str(), config_filename.c_str()) != 0) {
1887 DEB_SYSLOG("rename error errno:%d", errno);
1894 writeUpdateConfig(std::string set_key, std::string value) {
1895 std::string config_filename = FRAMEWORKUNIFIEDLOG_CONFIG_NV; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1896 std::string config_tmpfilename = FRAMEWORKUNIFIEDLOG_CONFIG_NV; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1897 config_filename.append(FRAMEWORKUNIFIEDLOG_CONFIG__CWORD84__NV); // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1898 config_tmpfilename.append(FRAMEWORKUNIFIEDLOG_CONFIG_TMP_NV);
1900 unlink(config_tmpfilename.c_str());
1901 if (copyFrameworkunifiedLogCfgFile(config_filename.c_str(), config_tmpfilename.c_str())) {
1902 DEB_SYSLOG("fail to copy file. no update config.");
1906 // CNSConfigWriter *l_pConfigWriter = new(std::nothrow) CNSConfigWriter(config_filename.c_str());
1907 CNSConfigWriter *l_pConfigWriter = new(std::nothrow) CNSConfigWriter(config_tmpfilename.c_str()); // LCOV_EXCL_BR_LINE 11:expect branch
1910 if (l_pConfigWriter != NULL) {
1911 l_pConfigWriter->Set(set_key.c_str(), value); // LCOV_EXCL_BR_LINE 11:expect branch
1912 l_pConfigWriter->Save(); // LCOV_EXCL_BR_LINE 11:expect branch
1913 delete l_pConfigWriter; // LCOV_EXCL_BR_LINE 11:expect branch
1915 if (rename(config_tmpfilename.c_str(), config_filename.c_str()) != 0) {
1916 DEB_SYSLOG("rename error errno:%d", errno);
1921 //////////////////////////////////////////
1922 // NsLogSetFrameworkunifiedLogFlag for Diag Method
1923 //////////////////////////////////////////
1925 NsLogSetFrameworkunifiedLogFlag(UI_8 flag_id, UI_8 mode) {
1926 std::string l_key = ".LogLevel";
1928 int *l_logLevelArray;
1929 std::string l_value;
1931 if (mode != FRAMEWORKUNIFIEDLOG_FLAG_MODE_DEBUG
1932 && mode != FRAMEWORKUNIFIEDLOG_FLAG_MODE_RELEASE) {
1936 if (!IsExistFrameworkunifiedLogCfgNv()) { // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
1937 copyFrameworkunifiedLogCfgFileToNv(); // LCOV_EXCL_BR_LINE 11:expect branch
1940 l_realTimelog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
1941 l_logLevelArray = NULL;
1943 readConfig(&l_realTimelog, &l_logLevelArray); // for make ramd data
1944 if (l_logLevelArray == NULL) {
1948 if (!IsExistFrameworkunifiedLogCfgShmem()) {
1949 WriteSharedMem(WTYPE_NORMAL, l_realTimelog, g_FlagIdNum, l_logLevelArray);
1950 MapShmInfo(g_FrameworkunifiedLogFlagId);
1953 if (flag_id >= g_FlagIdNum) {
1954 if (l_logLevelArray != NULL) {
1955 free(l_logLevelArray);
1960 if (mode == FRAMEWORKUNIFIEDLOG_FLAG_MODE_DEBUG) {
1962 l_logLevelArray[flag_id] = FRAMEWORKUNIFIEDLOG_FLAG_MODE_DEBUG;
1964 l_value = "Release";
1965 l_logLevelArray[flag_id] = FRAMEWORKUNIFIEDLOG_FLAG_MODE_RELEASE;
1967 writeUpdateConfigForString(g_flag_name[flag_id], l_key, l_value); // LCOV_EXCL_BR_LINE 11:expect branch
1968 WriteSharedMemForFlagId(l_realTimelog, g_FlagIdNum, flag_id, l_logLevelArray[flag_id]); // LCOV_EXCL_BR_LINE 11:expect branch
1970 free(l_logLevelArray);
1973 //////////////////////////////////////////
1974 // NsLogGetFrameworkunifiedLogFlag for Diag Method
1975 //////////////////////////////////////////
1976 EFrameworkunifiedStatus
1977 NsLogGetFrameworkunifiedLogFlag(UI_8 flag_id, UI_8 *mode) {
1980 int *l_logLevelArray;
1983 return eFrameworkunifiedStatusFail;
1986 l_realTimeLog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
1987 l_logLevelArray = NULL;
1989 readConfig(&l_realTimeLog, &l_logLevelArray); // for make ramd data
1990 if (l_logLevelArray == NULL) {
1991 *mode = FRAMEWORKUNIFIEDLOG_FLAG_MODE_RELEASE;
1992 return eFrameworkunifiedStatusFail;
1995 if (!IsExistFrameworkunifiedLogCfgShmem()) {
1996 WriteSharedMem(WTYPE_NORMAL, l_realTimeLog, g_FlagIdNum, l_logLevelArray);
1997 MapShmInfo(g_FrameworkunifiedLogFlagId);
2000 if (l_logLevelArray != NULL) {
2001 free(l_logLevelArray);
2004 if ((flag_id >= g_FlagIdNum)) {
2005 return eFrameworkunifiedStatusFail;
2008 GetShmInfo(flag_id, &l_realTimeLog, &l_logLevel);
2009 *mode = static_cast<UI_8>(l_logLevel);
2011 return eFrameworkunifiedStatusOK;
2014 //////////////////////////////////////////
2015 // NsLogSetRealtimeLog for Diag Method
2016 //////////////////////////////////////////
2018 NsLogSetRealtimeLog(UI_8 mode) {
2019 int l_realTimelog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
2020 int *l_logLevelArray;
2021 std::string l_key = "REALTIME_LOG.Output";
2022 std::string l_value = "OFF"; // LCOV_EXCL_BR_LINE 11:expect branch
2024 if (mode == FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_FREEZE) {
2025 WriteSharedMem(WTYPE_RTIMELOG, FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_FREEZE, g_FlagIdNum, NULL); // LCOV_EXCL_BR_LINE 11:expect branch
2029 if ((mode >= FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_MAX)
2030 && (mode != FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_USB_DISABLE)) {
2034 if (!IsExistFrameworkunifiedLogCfgNv()) { // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
2035 copyFrameworkunifiedLogCfgFileToNv(); // LCOV_EXCL_BR_LINE 11:expect branch
2038 l_logLevelArray = NULL;
2039 readConfig(&l_realTimelog, &l_logLevelArray); // LCOV_EXCL_BR_LINE 11:expect branch
2040 if (l_logLevelArray == NULL) {
2044 if (!IsExistFrameworkunifiedLogCfgShmem()) {
2045 WriteSharedMem(WTYPE_NORMAL, l_realTimelog, g_FlagIdNum, l_logLevelArray);
2046 MapShmInfo(g_FrameworkunifiedLogFlagId);
2049 if (mode == FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_UART) {
2051 l_realTimelog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_UART;
2052 } else if ((mode == FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_USB)
2053 || (mode == FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_USB_DISABLE)) {
2055 l_realTimelog = mode;
2058 l_realTimelog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
2061 writeUpdateConfig(l_key, l_value); // LCOV_EXCL_BR_LINE 11:expect branch
2062 if (l_logLevelArray != NULL) {
2063 WriteSharedMemForFlagId(l_realTimelog, g_FlagIdNum, FRAMEWORKUNIFIEDLOG_DEFAULT_FLAG_ID,
2064 l_logLevelArray[FRAMEWORKUNIFIEDLOG_DEFAULT_FLAG_ID]); // LCOV_EXCL_BR_LINE 11:expect branch
2065 free(l_logLevelArray);
2069 //////////////////////////////////////////
2070 // NsLogGetRealtimeLog for Diag
2071 //////////////////////////////////////////
2073 NsLogGetRealtimeLog(UI_8 *mode) {
2076 int *l_logLevelArray;
2081 l_realTimelog = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
2082 l_logLevelArray = NULL;
2084 readConfig(&l_realTimelog, &l_logLevelArray); // for make ramd data
2085 if (l_logLevelArray == NULL) {
2086 *mode = FRAMEWORKUNIFIEDLOG_REALTIMELOG_MODE_OFF;
2089 if (!IsExistFrameworkunifiedLogCfgShmem()) {
2090 WriteSharedMem(WTYPE_NORMAL, l_realTimelog, g_FlagIdNum, l_logLevelArray);
2091 MapShmInfo(g_FrameworkunifiedLogFlagId);
2093 if (l_logLevelArray != NULL) {
2094 free(l_logLevelArray);
2097 GetShmInfo(g_FrameworkunifiedLogFlagId, &l_realTimelog, &l_logLevel);
2098 *mode = static_cast<UI_8>(l_realTimelog);
2101 //////////////////////////////////////////
2102 // NSLogPrintSysEventLog
2103 //////////////////////////////////////////
2104 VOID NSLogSysEvent(const UI_16 f_ui16Line, PCSTR f_cFuncName, PCSTR __format, ...) {
2106 CHAR l_cFormat[MAX_QUEUE_MSG_SIZE] = {};
2107 CHAR l_cTimeFormat[MAX_TIME_FORMATSTR_LEN] = {};
2108 UI_64 l_ui64CurrentTime = 0;
2109 static UI_64 cps = 0;
2110 static UI_64 l_ui64GapInUS = 0;
2113 cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
2115 if (g_hNSSysEventLogQ == INVALID_HANDLE) {
2116 g_hNSSysEventLogQ = OpenSender(NS_SYSEVENTLOGQ);
2118 if (l_ui64GapInUS == 0) {
2119 FILE *l_fpPLogGap = NULL;
2120 l_fpPLogGap = fopen(PLOG_GAP_FILE, "re");
2121 if (l_fpPLogGap != NULL) {
2122 CHAR l_cBuffer[MAX_GAP_BUFFER_LEN] = {};
2123 if (fgets(l_cBuffer, MAX_GAP_BUFFER_LEN, l_fpPLogGap) != NULL) {
2124 l_ui64GapInUS = static_cast<UI_64>(atoll(l_cBuffer));
2126 fclose(l_fpPLogGap);
2130 if (g_hNSSysEventLogQ != INVALID_HANDLE) {
2131 CHAR l_cMsg[MAX_QUEUE_MSG_SIZE] = {};
2132 // build a format string
2133 #ifdef AGL_PosixBasedOS001LEGACY_USED
2134 l_ui64CurrentTime = (ClockCycle() / (cps / 1000000)) + l_ui64GapInUS;
2136 snprintf(l_cTimeFormat, MAX_TIME_FORMATSTR_LEN, "%s", "us");
2138 va_start(arg, __format);
2139 vsnprintf(l_cFormat, MAX_PLOG_STRING_SIZE - 1, __format, arg);
2140 l_cFormat[MAX_PLOG_STRING_SIZE - 1] = '\0';
2142 UI_32 l_uiCharsWritten =
2143 snprintf(l_cMsg, MAX_QUEUE_MSG_SIZE - 1,
2144 "%12llu[%s]:%s %s: %s: %s\n",
2145 static_cast<long long unsigned int>(l_ui64CurrentTime), // NOLINT (readability/nolint)
2147 (l_ui64GapInUS > 0) ? ("o") : ("x"),
2148 tls_strProcessName != 0 ? tls_strProcessName : NULL,
2149 f_cFuncName != 0 ? f_cFuncName : NULL, l_cFormat);
2151 if (SendMessage(g_hNSSysEventLogQ, l_uiCharsWritten + 1,
2152 reinterpret_cast<void *>(const_cast<char *>(l_cMsg)))
2153 != eFrameworkunifiedStatusOK) {
2154 // Note: Nothing will be printed on a failure.
2159 /////////////////////////////////////////
2160 // NSLogEnableSysEventLog
2161 //////////////////////////////////////////
2163 NSLogEnableSysEventLog(BOOL f_bEnable) {
2164 g_FrameworkunifiedLogSysEventParams.bIsSysEventLogEnabled = f_bEnable;
2167 //////////////////////////////////////////
2168 // NSLogIsSysEventLogEnabled
2169 //////////////////////////////////////////
2171 NSLogIsSysEventLogEnabled(void) {
2172 return g_FrameworkunifiedLogSysEventParams.bIsSysEventLogEnabled;
2175 //////////////////////////////////////////
2176 // NsLogGetZoneTextList
2177 //////////////////////////////////////////
2179 NsLogGetZoneTextList(CHAR f_cZoneList[][ZONE_TEXT_SIZE]) {
2180 if (f_cZoneList != NULL) {
2181 UI_32 l_ui32CharsToWrite = ZONE_TEXT_SIZE - 1;
2182 // first fill ns zone text list
2183 strncpy(f_cZoneList[0], ZONE_TEXT_0, l_ui32CharsToWrite);
2184 strncpy(f_cZoneList[1], ZONE_TEXT_1, l_ui32CharsToWrite);
2185 strncpy(f_cZoneList[2], ZONE_TEXT_2, l_ui32CharsToWrite);
2186 strncpy(f_cZoneList[3], ZONE_TEXT_3, l_ui32CharsToWrite);
2187 strncpy(f_cZoneList[4], ZONE_TEXT_4, l_ui32CharsToWrite);
2188 strncpy(f_cZoneList[5], ZONE_TEXT_5, l_ui32CharsToWrite);
2189 strncpy(f_cZoneList[6], ZONE_TEXT_6, l_ui32CharsToWrite);
2190 strncpy(f_cZoneList[7], ZONE_TEXT_7, l_ui32CharsToWrite);
2191 strncpy(f_cZoneList[8], ZONE_TEXT_8, l_ui32CharsToWrite);
2192 strncpy(f_cZoneList[9], ZONE_TEXT_9, l_ui32CharsToWrite);
2194 // fill user zone text list
2195 UI_32 l_ui32Count = 10; // start of user zones
2196 UI_32 l_ui32ZoneListCount = 0;
2197 for (; l_ui32Count < BITS_IN_ZONE_MASK; l_ui32Count++, l_ui32ZoneListCount++) {
2198 strncpy(f_cZoneList[l_ui32Count], g_LocalFrameworkunifiedLogParams.cZones[l_ui32ZoneListCount], l_ui32CharsToWrite);
2204 NsForceClose(void) {
2205 if (!syslogopened) {
2210 if (shm_pmap != reinterpret_cast<void *>(const_cast<unsigned int*>(default_log_cfgtbl))) {
2212 size = static_cast<int>(sizeof(int) * 2); // realTimeLog + flagIdNum
2213 size += static_cast<int>(sizeof(int) * g_FlagIdNum);
2214 munmap(shm_pmap, size);
2215 shm_pmap = reinterpret_cast<void *>(const_cast<unsigned int*>(default_log_cfgtbl));
2223 if (g_qid != (mqd_t)(-1)) {
2225 g_qid = (mqd_t)(-1);
2228 TFrameworkunifiedLogMap::iterator itr;
2229 TFrameworkunifiedLogMap::iterator itr_end;
2231 unsigned int flag_id;
2232 if (!g_FrameworkunifiedLogMap.empty()) {
2233 itr = g_FrameworkunifiedLogMap.begin();
2234 itr_end = g_FrameworkunifiedLogMap.end();
2235 for (; itr != itr_end; itr++, i++) {
2236 if (itr->second.ring_buffer != NULL) {
2237 delete itr->second.ring_buffer; // LCOV_EXCL_BR_LINE 11:expect branch
2238 itr->second.ring_buffer = NULL;
2241 g_FrameworkunifiedLogMap.clear();
2244 if (!g_FrameworkunifiedLogFlagMap.empty()) {
2245 for (flag_id = 0; flag_id < g_FlagIdNum; flag_id++) {
2246 itr = g_FrameworkunifiedLogFlagMap.find(flag_id);
2247 if (itr->second.ring_buffer != NULL) {
2248 delete itr->second.ring_buffer; // LCOV_EXCL_BR_LINE 11:expect branch
2249 itr->second.ring_buffer = NULL;
2252 g_FrameworkunifiedLogFlagMap.clear();
2255 if (!g_flag_name.empty()) {
2256 g_flag_name.clear();
2258 g_FrameworkunifiedLogFlagId = FRAMEWORKUNIFIEDLOG_DEFAULT_FLAG_ID;
2260 } // LCOV_EXCL_BR_LINE 10:The final line