aboutsummaryrefslogtreecommitdiffstats
path: root/src/framework/log/nstack_log.c
blob: 66789961ab601a5dfd47223246db9a9d1a2667f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*==============================================*
 *      include header files                    *
 *----------------------------------------------*/

#include "nstack_log.h"
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#include <errno.h>
#include <execinfo.h>
#include <fcntl.h>
#include "nstack_securec.h"
#include <pthread.h>

/*==============================================*
 *      constants or macros define              *
 *----------------------------------------------*/

#define FILE_NAME_LEN 256
#define MAX_PRE_INIT_LOG_COUNT 256
#define MAX_LOCK_RETRY_COUNT 50000      /* changed MAX_LOCK_RETRY_COUNT to 50000 to avoid function being blocked for too long */
/* *INDENT-OFF* */
int g_l4_dump_enable = 0;
static int pre_init_log_count = 0;
static struct pre_init_info pre_init_log[MAX_PRE_INIT_LOG_COUNT] = {{0, ""}};
/* *INDENT-ON* */
__thread unsigned int nstack_log_nonreentry = 0;
int ctrl_log_switch = 0;

/*==============================================*
 *      project-wide global variables           *
 *----------------------------------------------*/
struct nstack_logs g_nstack_logs[MAX_LOG_MODULE] = { {0, 0, 0, 0}, {0xFFFF, 0, 0, 0} }; /* Clear compile warning */
struct log_init_para g_log_init_para =
  { 50, 10, NSTACK_LOG_NAME, 10, 10, NSTACK_LOG_NAME };
static int g_my_pro_type = LOG_PRO_INVALID;

#define DEFAULT_LOG_CTR_TIME 5
static struct log_ctrl_info g_log_ctrl_info[LOG_CTRL_ID_MAX];

/*==============================================*
 *      routines' or functions' implementations *
 *----------------------------------------------*/

/* change the print level, not only has err, Begin.*/
void
save_pre_init_log (uint32_t level, char *fmt, ...)
{
  va_list ap;
  int ret = 0;
  /* add pre_init_log_count rang check */
  if (level > NSLOG_DBG || pre_init_log_count >= MAX_PRE_INIT_LOG_COUNT
      || pre_init_log_count < 0)

    {
      return;
    }
  pre_init_log[pre_init_log_count].log_buffer[PRE_INIT_LOG_LENGTH - 1] = '\0';
  (void) va_start (ap, fmt);
  ret =
    VSNPRINTF_S (pre_init_log[pre_init_log_count].log_buffer,
                 PRE_INIT_LOG_LENGTH, PRE_INIT_LOG_LENGTH - 1, fmt, ap);
  if (-1 == ret)
    {
      va_end (ap);
      return;
    }
  va_end (ap);
  pre_init_log[pre_init_log_count].level = level;
  pre_init_log_count++;
}

void
write_pre_init_log ()
{
  int i = 0;
  for (; i < pre_init_log_count; i++)
    {
      if (NSLOG_ERR == pre_init_log[i].level)
        {
          NSPOL_LOGERR ("pre init log: %s", pre_init_log[i].log_buffer);
        }
      else if (NSLOG_WAR == pre_init_log[i].level)
        {
          NSPOL_LOGWAR (NS_LOG_STACKX_ON, "pre init log: %s",
                        pre_init_log[i].log_buffer);
        }
      else if (NSLOG_INF == pre_init_log[i].level)
        {
          NSPOL_LOGINF (NS_LOG_STACKX_ON, "pre init log: %s",
                        pre_init_log[i].log_buffer);
        }
    }
}

int
cmp_log_path (const char *path)
{
  if (NULL == path)
    {
      return 1;
    }

  /* remove struct log_info g_nstack_log_info */
  if (NULL != g_log_init_para.mon_log_path)
    {
      if (strcmp (g_log_init_para.mon_log_path, path) == 0)
        {
          return 0;
        }
    }
  return 1;
}

void
get_current_time (char *buf, const int len)
{
  int retVal;
  time_t cur_tick;
  struct tm cur_time;
  (void) time (&cur_tick);
  /* add return value check, */
  if (NULL == localtime_r (&cur_tick, &cur_time))
    {
      return;
    }

  // from man page of localtime_r:
  // tm_year   The number of years since 1900.
  // tm_mon    The number of months since January, in the range 0 to 11.
  retVal =
    SNPRINTF_S (buf, len, len - 1, "%04d%02d%02d%02d%02d%02d",
                cur_time.tm_year + 1900, cur_time.tm_mon + 1,
                cur_time.tm_mday, cur_time.tm_hour, cur_time.tm_min,
                cur_time.tm_sec);
  if (-1 == retVal)
    {
      return;
    }
  buf[len - 1] = 0;
}

/*****************************************************************************
*   Prototype    : nstack_setlog_level
*   Description  : Set global log level
*   Input        : int module
*                  uint32_t level
*   Output       : None
*   Return Value : void
*   Calls        :
*   Called By    :
*****************************************************************************/
void
nstack_setlog_level (int module, uint32_t level)
{
  if (MAX_LOG_MODULE <= module || module < 0)
    {
      return;
    }
  g_nstack_logs[module].level = level;
}

/*****************************************************************************
*   Prototype    : nstack_log_info_check
*   Description  : log info check
*   Input        : uint32_t module
*                  uint32_t level
*                  ...
*   Output       : None
*   Return Value : bool
*   Calls        :
*   Called By    :
*****************************************************************************/
bool
nstack_log_info_check (uint32_t module, uint32_t level)
{
  if (MAX_LOG_MODULE <= module)
    {
      return false;
    }

  /* no need compare module ,which is done ahead */
  if (LOG_PRO_INVALID == g_my_pro_type)
    {
      return false;
    }
  return true;
}

/* *INDENT-OFF* */
NSTACK_STATIC inline void init_operation_log_para()
{
    g_nstack_logs[OPERATION].file_type = LOG_TYPE_OPERATION;
}

NSTACK_STATIC inline void init_nstack_log_para()
{
    int i = 0;

    (void)glogLevelSet(GLOG_LEVEL_DEBUG);
    glogBufLevelSet(GLOG_LEVEL_WARNING);
    for(; i<GLOG_LEVEL_BUTT; i++)
        glogSetLogSymlink(i,"");
    glogDir(g_log_init_para.run_log_path);
    nstack_log_count_set(g_log_init_para.run_log_count);
    glogMaxLogSizeSet(g_log_init_para.run_log_size);
    glogSetLogFilenameExtension(STACKX_LOG_NAME);
    glogFlushLogSecsSet(FLUSH_TIME);

    for (i = 0; i < MAX_LOG_MODULE ; i++ )
    {
        if (i == OPERATION)
        {
            continue;
        }
        g_nstack_logs[i].file_type = LOG_TYPE_NSTACK;
    }
    init_operation_log_para();
}

NSTACK_STATIC inline void init_ctrl_log_para()
{
    int i = 0;

    (void)glogLevelSet(GLOG_LEVEL_DEBUG);
    glogBufLevelSet(GLOG_LEVEL_WARNING);
    for(; i<GLOG_LEVEL_BUTT; i++)
        glogSetLogSymlink(i,"");
    glogDir(g_log_init_para.mon_log_path);
    nstack_log_count_set(g_log_init_para.mon_log_count);
    glogMaxLogSizeSet(g_log_init_para.mon_log_size);
    glogSetLogFilenameExtension(OMC_CTRL_LOG_NAME);
    glogFlushLogSecsSet(FLUSH_TIME);
}

NSTACK_STATIC inline void init_master_log_para()
{
    int i = 0;

    (void)glogLevelSet(GLOG_LEVEL_DEBUG);
    glogBufLevelSet(GLOG_LEVEL_WARNING);
    for(; i<GLOG_LEVEL_BUTT; i++)
        glogSetLogSymlink(i,"");
    glogDir(g_log_init_para.mon_log_path);
    nstack_log_count_set(g_log_init_para.mon_log_count);
    glogMaxLogSizeSet(g_log_init_para.mon_log_size);
    glogSetLogFilenameExtension(MASTER_LOG_NAME);
    glogFlushLogSecsSet(FLUSH_TIME);
    for (i = 0; i < MAX_LOG_MODULE ; i++ )
    {
        g_nstack_logs[i].file_type = LOG_TYPE_MASTER;
    }
}
/* *INDENT-OFF* */

/*****************************************************************************
*   Prototype    : nstack_log_init
*   Description  : called by environment-specific log init function
*   Input        : None
*   Output       : None
*   Return Value : int
*   Calls        :
*   Called By    :
*****************************************************************************/
int nstack_log_init()
{
  char *pst_temp = NULL;
  int log_level = NSLOG_INF;
       pst_temp = getenv("NSTACK_LOG_ON");
   if (pst_temp)
    {
      if (strcmp (pst_temp, "INF") == 0)
    {
      log_level = NSLOG_INF;
    }
      else if (strcmp (pst_temp, "DBG") == 0)
    {
      log_level = NSLOG_DBG;
    }
      else if (strcmp (pst_temp, "WAR") == 0)
    {
      log_level = NSLOG_WAR;
    }
      else if (strcmp (pst_temp, "ERR") == 0)
    {
      log_level = NSLOG_ERR;
    }
      else if (strcmp (pst_temp, "EMG") == 0)
    {
      log_level = NSLOG_EMG;
    }
      else
    {
      log_level = NSLOG_ERR;
    }
     }
  else
    {
      log_level = NSLOG_INF;
    }
   int i = 0;
  for (i = 0; i < MAX_LOG_MODULE; i++)
    {
      nstack_setlog_level (i, log_level);
    }
   if (log_level <= NSLOG_WAR)
    {
    /*MONITOR log level must set to larger than warning */
    nstack_setlog_level (MASTER, NSLOG_WAR);
    }

    /* monitor and nstack write the same file, it will cause synchronize problem */
    switch (g_my_pro_type)
    {
    case LOG_PRO_NSTACK:
      glogInit ("NSTACK");
      init_nstack_log_para ();
      break;
    case LOG_PRO_OMC_CTRL:
      glogInit ("CTRL");
      init_ctrl_log_para ();
      break;
    case LOG_PRO_MASTER:
      glogInit ("MASTER");
      init_master_log_para ();
      break;
    default:
      return 0;
    }

    init_log_ctrl_info();

    // this is for monitr to check whether log has beed inited
    g_nstack_logs[NSOCKET].inited = 1;
   NSPOL_LOGERR ("nStackMain_version=%s", NSTACK_VERSION);
    write_pre_init_log();
   return 0;
}

/*****************************************************************************
*   Prototype    : get_str_value
*   Description  : get int value
*   Input        : const char *arg
*   Output       : None
*   Return Value : int
*   Calls        :
*   Called By    :
*****************************************************************************/
int
get_str_value (const char *arg)
{
  char *parsing_end;
  int iValue = 0;
  int oldErrno = errno;
   if (arg == NULL)
    {
      return -1;
    }
  errno = 0;
    iValue = (int) strtol (arg, &parsing_end, 0);
  if (errno || (!parsing_end) || parsing_end[0] != 0)
    {
      iValue = -1;
    }
    errno = oldErrno;
  return iValue;
}


/*****************************************************************************
*   Prototype    : setlog_level_value
*   Description  : proc log level config
*   Input        : const char *param
*                  const char *value
*   Output       : None
*   Return Value : int
*   Calls        :
*   Called By    :
*****************************************************************************/
int
setlog_level_value (const char *param, const char *value)
{
  int i = 0;
  int module = 0;
  int logLevel = 0;
  module = get_str_value (param);
  if ((module < 0) || (MAX_LOG_MODULE <= module))
    {
      NSOPR_LOGERR ("input module error]param=%s,module=%d", param, module);
      return 1;
    }

    if (strcmp (value, LOG_LEVEL_ERR) == 0)
    {
      logLevel = NSLOG_ERR;
    }
  else if (strcmp (value, LOG_LEVEL_WAR) == 0)
    {
      logLevel = NSLOG_WAR;
    }
  else if (strcmp (value, LOG_LEVEL_DBG) == 0)
    {
      logLevel = NSLOG_DBG;
    }
  else if (strcmp (value, LOG_LEVEL_INF) == 0)
    {
      logLevel = NSLOG_INF;
    }
  else if (strcmp (value, LOG_LEVEL_EMG) == 0)
    {
      logLevel = NSLOG_EMG;
    }
  else
    {
      NSOPR_LOGERR ("input log level error!");
      return 1;
    }
   NSOPR_LOGINF ("set module log with level]module=%d,logLevel=0x%x",
           module, logLevel);
   if (module > 0)
    {
      nstack_setlog_level (module, logLevel);
      return 0;
    }
   if (0 == module)
    {
        for ( i = 0; i < MAX_LOG_MODULE ; i++ )
        {
             nstack_setlog_level(i,logLevel);
        }
    }
   return 0;
}


/*****************************************************************************
*   Prototype    : check_log_dir_valid
*   Description  : check the log dir valid or not
*   Input        : const char *arg
*   Output       : None
*   Return Value : int
*   Calls        :
*   Called By    :
*****************************************************************************/
int
check_log_dir_valid (const char *path)
{
  size_t length;
  struct stat statbuf;
  if (NULL == path)
    {
      return -1;
    }
   length = strlen (path) + 1;
  if ((length <= 1) || (length > FILE_NAME_LEN))
    {
      return -1;
    }

    /* only write permission is allowed */
    if ((0 != access (path, W_OK)))
    {
    /* if path can access, use env path */
    return -1;
    }

    if ((0 == lstat (path, &statbuf)) && S_ISDIR (statbuf.st_mode))
    {
      return 0;
     }
  else
    {
      return -1;
    }
}


/*****************************************************************************
*   Prototype    : get_app_env_log_path
*   Description  : called by environment-specific log init function
*   Input        : app_file_path, a char pointer to store the log path
*   Input        : app_file_size, the app_file_path size
*   Output       : None
*   Return Value : int
*   Calls        :
*   Called By    :
*****************************************************************************/
int
get_app_env_log_path (char *app_file_path, unsigned int app_file_size)
{
  char *pst_app_log_path_flag = NULL;
  char *pst_app_log_path_string = NULL;
  int log_to_file = 0;
  int ret = -1;
  char *app_dir = NULL;

   if ((NULL == app_file_path) || (0 == app_file_size))
    {
      return 0;
    }
   pst_app_log_path_flag = getenv ("NSTACK_LOG_FILE_FLAG");
   if (pst_app_log_path_flag && strcmp (pst_app_log_path_flag, "1") == 0)
    {
        /* if set environment variable to 1,then output to file*/
        log_to_file = 1;
    }
  else
    {
        /*  if environment variable is not equal 1 or
         don't set this environment variable ,output to STDOUT */
        return 0;
    }

    /* add the realpath and dir check */
    /* APP LOG can be set by user */
    pst_app_log_path_string = getenv("NSTACK_APP_LOG_PATH");

    if ((NULL == pst_app_log_path_string)
    ||(strlen (pst_app_log_path_string) > FILE_NAME_LEN - 1))
    {
      goto app_default;
    }

    app_dir = realpath (pst_app_log_path_string, NULL);
    if (check_log_dir_valid (pst_app_log_path_string) < 0)
    {
      goto app_default;
    }
    ret = STRCPY_S (app_file_path, app_file_size, app_dir);
    if(EOK != ret)
    {
        log_to_file = 0;
    }

    free(app_dir);
    return log_to_file;

app_default:

  if ((0 == access (APP_LOG_PATH, W_OK)))
    {
      ret = STRCPY_S (app_file_path, app_file_size, APP_LOG_PATH);
      if (EOK != ret)
        {
          log_to_file = 0;
        }
    }
  else
    {
      log_to_file = 0;
    }

  if (NULL != app_dir)
    {
      free (app_dir);
    }

  return log_to_file;

}

/*****************************************************************************
*   Prototype    : nstack_get_app_logname
*   Description  : get the name of app's log
*   Input        : None
*   Output       : None
*   Return Value : int
*   Calls        :
*   Called By    :
*****************************************************************************/
int
nstack_get_app_logname (char* log_name)
{
  int pid = getpid ();
  char processname[FILE_NAME_LEN] = {0};

  if (log_name == NULL)
    return 1;

  strncpy (processname, program_invocation_short_name, 10);

  snprintf (log_name, FILE_NAME_LEN, "app_%s_%d.log", processname, pid);

  return 0;
}

/*****************************************************************************
*   Prototype    : nstack_log_init_app
*   Description  : called by environment-specific log init function
*   Input        : None
*   Output       : None
*   Return Value : int
*   Calls        :
*   Called By    :
*****************************************************************************/
void
nstack_log_init_app ()
{
  char *pc_temp = NULL;
  int log_level = NSLOG_ERR;
  int i = 0;
  int file_flag = 0;
  char app_log_path[FILE_NAME_LEN] = { 0 };
  int ret = 0;
  char app_log_name[FILE_NAME_LEN] = { 0 };

  /* log already initialized, just return */
  if (LOG_PRO_INVALID != g_my_pro_type)
    {
      return;
    }
  /* Add app log hook module init */
  nstack_log_hook_init ();

  if (0 != g_nstack_logs[NSOCKET].inited)
    {
      return;
    }
  glogInit ("APP");

  pc_temp = getenv ("NSTACK_LOG_ON");
  if (pc_temp)
    {
      if (strcmp (pc_temp, "INF") == 0)
        {
          log_level = NSLOG_INF;
        }
      else if (strcmp (pc_temp, "DBG") == 0)
        {
          log_level = NSLOG_DBG;
        }
      else if (strcmp (pc_temp, "WAR") == 0)
        {
          log_level = NSLOG_WAR;
        }
      else if (strcmp (pc_temp, "ERR") == 0)
        {
          log_level = NSLOG_ERR;
        }
      else if (strcmp (pc_temp, "EMG") == 0)
        {
          log_level = NSLOG_EMG;
        }
      else
        {
          log_level = NSLOG_ERR;
        }

    }
  else
    {
      log_level = NSLOG_ERR;
    }

  /* socket interface APP called include both stack-x and nstack module! */
  nstack_setlog_level (STACKX, log_level);
  nstack_setlog_level (NSOCKET, log_level);
  nstack_setlog_level (LOGRTE, log_level);
  nstack_setlog_level (LOGDFX, log_level);
  nstack_setlog_level (LOGFW, log_level);
  nstack_setlog_level (LOGHAL, log_level);
  nstack_setlog_level (LOGSBR, log_level);

  /* package the app env handle function, Begin */
  file_flag = get_app_env_log_path (app_log_path, FILE_NAME_LEN);
  if ((1 == file_flag) && (strlen (app_log_path) > 0))
    {
      glogDir (app_log_path);
      glogBufLevelSet (GLOG_LEVEL_WARNING);
      (void) glogLevelSet (GLOG_LEVEL_DEBUG);
      for (i = 0; i < GLOG_LEVEL_BUTT; i++)
        glogSetLogSymlink (i, "");
      nstack_log_count_set (APP_LOG_COUNT);
      glogMaxLogSizeSet (APP_LOG_SIZE);
      ret = nstack_get_app_logname (app_log_name);
      if (ret == 0)
        {
          glogSetLogFilenameExtension (app_log_name);
        }
      else
        {
          glogSetLogFilenameExtension (APP_LOG_NAME);
        }
      glogFlushLogSecsSet (FLUSH_TIME);
    }
  else
    {
      glogToStderrSet (1);
    }

  for (i = 0; i < MAX_LOG_MODULE; i++)
    {
      g_nstack_logs[i].file_type = LOG_TYPE_APP;
    }
  init_log_ctrl_info ();
  g_my_pro_type = LOG_PRO_APP;
  SetGlogCtrlOpt (TRUE);
  NSPOL_LOGERR ("app_nStack_version=%s", NSTACK_VERSION);
  return;
}

void
nstack_segment_error (int s)
{

#define BACKTRACE_SIZ 20
  void *array[BACKTRACE_SIZ];
  int size;
  int i;
  char **strings = NULL;

  /*if set, flush the log immediately */
  glogFlushLogFiles (GLOG_LEVEL_DEBUG);

  size = backtrace (array, BACKTRACE_SIZ);
  NSPOL_LOGEMG
    ("------------------DUMP_BACKTRACE[%d]--------------------------------\n",
     size);

  /* easy to view signal in  separate log file */
  NSPOL_LOGEMG ("Received signal s=%d", s);

  for (i = 0; i < size; i++)
    {
      NSPOL_LOGEMG ("[%d]:%p\n", i, array[i]);
    }
  strings = backtrace_symbols (array, size);
  if (NULL == strings)
    {
      return;
    }
  for (i = 0; i < size; i++)
    {
      NSPOL_LOGEMG ("[%d]:%s\n", i, strings[i]);
    }
  NSPOL_LOGEMG
    ("-------------------------------------------------------------------\n");
  free (strings);
}

void
set_log_init_para (struct log_init_para *para)
{
  if (NULL == para)

    {
      return;
    }
  if (EOK !=
      MEMCPY_S (&g_log_init_para, sizeof (struct log_init_para), para,
                sizeof (struct log_init_para)))

    {
      return;
    }
}

/* control log printed counts */
static inline void
update_log_prt_time (struct timespec *cur_time, struct timespec *log_prt_time)
{
  log_prt_time->tv_sec = cur_time->tv_sec;
  log_prt_time->tv_nsec = cur_time->tv_nsec;
}

int
check_log_prt_time (int id)
{
  struct timespec cur_time;
  struct timespec *log_prt_time = NULL;
  if (id >= LOG_CTRL_ID_MAX || id < 0)

    {
      return 0;
    }
  (void) clock_gettime (CLOCK_MONOTONIC, &cur_time);
  log_prt_time = &g_log_ctrl_info[id].last_log_time;
  if (cur_time.tv_sec - log_prt_time->tv_sec >=
      g_log_ctrl_info[id].expire_time)
    {
      /* first log need print */
      set_log_ctrl_time (id, DEFAULT_LOG_CTR_TIME);
      update_log_prt_time (&cur_time, log_prt_time);
      return 1;
    }
  g_log_ctrl_info[id].unprint_count++;
  return 0;
}

int
get_unprt_log_count (int id)
{
  return g_log_ctrl_info[id].unprint_count;
}

void
clr_unprt_log_count (int id)
{
  g_log_ctrl_info[id].unprint_count = 0;
}

void
set_log_ctrl_time (int id, int ctrl_time)
{
  if (id >= LOG_CTRL_ID_MAX || id < 0)
    {
      return;
    }

  if (ctrl_time <= 0)
    {
      return;
    }

  g_log_ctrl_info[id].expire_time = ctrl_time;
}

void
init_log_ctrl_info ()
{
  int i = 0;
  for (; i < LOG_CTRL_ID_MAX; i++)
    {
      /* first log need print */
      g_log_ctrl_info[i].expire_time = 0;
      g_log_ctrl_info[i].unprint_count = 0;
      g_log_ctrl_info[i].last_log_time.tv_sec = 0;
      g_log_ctrl_info[i].last_log_time.tv_nsec = 0;
    }

  // for every socket api, need different log id

  // for nstack inner
}

void
set_log_proc_type (int log_proc_type)
{
  g_my_pro_type = log_proc_type;
}