summaryrefslogtreecommitdiffstats
path: root/logger_service/server/src/ss_logger_cfg.cpp
blob: b353bbedaa5a6aa24915b8197e3163f6cfc55ca0 (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
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * 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.
 */

///////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_SS_LoggerService
/// \brief    Provide support for CPU high load monitor configuration.
///
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// INCLUDES
///////////////////////////////////////////////////////////////////////////////
#include "ss_logger_cfg.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <boost/bind.hpp>
#include <native_service/nslogutil_cmd_if.h>
#include <native_service/ns_np_service_protocol.h>
#include <system_service/ss_logger_service_notifications.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>

const static UI_32 cMAX_EMMC_COUNTER_VALUE = 100000u;  // NOLINT (build/storage_class)
///////////////////////////////////////////////////////////////////////////////
// CLASS METHODS
///////////////////////////////////////////////////////////////////////////////

CLoggerCfg::CLoggerCfg()
  : m_logMaxFileSize(0),
    m_performanceLogMaxFileSize(0),
    m_emmcOutputMax(0),
    m_emmcOutputErrMax(0),
    m_emmcOutputGrpRelaunchMax(0),
    m_emmcOutputNaviLogMax(0),
    m_emmcOutputNaviLogNmlMax(0),
    m_emmcOutputNaviLogErrMax(0),
    m_emmcOutputPath(""),
    m_emmcOutputNaviLogPath(""),
    m_usb0MountPath(""),
    m_usb1MountPath(""),
    m_sdMountPath(""),
    m_eDevType(eDevUSB1),
    m_UserInvokedLoggingNumber(1u),
    m_EmmcCounter(0u),
    m_eLoggerUDPLoggingStatus(eDeactivate),
    m_eLoggerStatus(SS_LOGGER_DEFAULT_VALUE) {
      m_udpEnvFlag = FALSE;
      std::memset(m_logMask, 0, sizeof(m_logMask));
      std::memset(&m_ExternalLogList, 0, sizeof(&m_ExternalLogList));
    }

CLoggerCfg::~CLoggerCfg(void) {  // LCOV_EXCL_START 14:global instance
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert

  if (m_ExternalLogList.p_info != NULL) {
    delete[] m_ExternalLogList.p_info;
    m_ExternalLogList.p_info = NULL;
  }
}
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CLoggerCfg::Initialize(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  char* l_udp_env = getenv("UDPLOGS_ON");
  m_udpEnvFlag = (
      l_udp_env == NULL ?
          FALSE : (strcmp("TRUE", l_udp_env) == 0 ? TRUE : FALSE));

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return eFrameworkunifiedStatusOK;
}
EFrameworkunifiedStatus CLoggerCfg::SetandPersistLoggingParams(HANDLE f_hApp,
                                                  STLoggerSetAllParams f_Params,
                                                  BOOL f_InitCall) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  BOOL l_paramChanged = f_InitCall;
  BOOL l_updateLoggerState = f_InitCall;

  if ((TRUE == l_paramChanged)  // LCOV_EXCL_BR_LINE 200:l_paramChanged is never TRUE
      ||
      (m_eLoggerStatus != f_Params.Logger_State)
      ||  // LCOV_EXCL_BR_LINE 200:Because m_UserInvokedLoggingNumber != f_Params.Log_FolderCnt is never false
      (m_UserInvokedLoggingNumber != f_Params.Log_FolderCnt)
      || (m_eLoggerUDPLoggingStatus != f_Params.Logger_UDPState)
      || (m_eDevType != f_Params.Device_Type)) {
    l_paramChanged = TRUE;
  } else {
    l_paramChanged = FALSE;
  }

  l_updateLoggerState =
      ((l_updateLoggerState == TRUE)
          || (m_eLoggerStatus != f_Params.Logger_State)) ? TRUE : FALSE;

  // After startup Logging will be set to default value
  if (TRUE == f_InitCall) {  // LCOV_EXCL_BR_LINE 200:f_InitCall is never TRUE
    // LCOV_EXCL_START 200:f_InitCall is never TRUE
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    m_eLoggerStatus = SS_LOGGER_DEFAULT_VALUE;
    // LCOV_EXCL_STOP
  } else {
    m_eLoggerStatus = f_Params.Logger_State;
  }
  m_eLoggerUDPLoggingStatus = f_Params.Logger_UDPState;
  m_UserInvokedLoggingNumber = f_Params.Log_FolderCnt;
  m_eDevType = f_Params.Device_Type;

  if (TRUE == l_paramChanged) {
    l_eStatus = PersistLoggingParam(f_hApp);
    LOG_STATUS_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: macro
                          "PersistLoggingParam()");
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::SetLoggingParams(HANDLE f_hApp,
                                        const STLoggerSetParams f_stLoggerSetParams) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  STLoggerSetAllParams l_Params;

  l_Params.Logger_UDPState = m_eLoggerUDPLoggingStatus;
  l_Params.Log_FolderCnt = m_UserInvokedLoggingNumber;
  l_Params.Logger_State = f_stLoggerSetParams.Logger_State;
  l_Params.Device_Type = f_stLoggerSetParams.Device_Type;

  l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE);
  LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()");  // LCOV_EXCL_BR_LINE 15: macro

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::SetUDPLogging(HANDLE f_hApp,
                                     const ELOGGER_STAT f_eUDPLoggingStatus) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  STLoggerSetAllParams l_Params;

  l_Params.Logger_UDPState = f_eUDPLoggingStatus;
  l_Params.Log_FolderCnt = m_UserInvokedLoggingNumber;
  l_Params.Logger_State = m_eLoggerStatus;
  l_Params.Device_Type = m_eDevType;

  l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE);
  LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()");  // LCOV_EXCL_BR_LINE 15: macro

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::PersistLoggingParam(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  FRAMEWORKUNIFIEDLOG(
      ZONE_INFO, __FUNCTION__,
      "LoggerState = %d, Device_Type = %d,UDPLogging = %d, TriggerNumber = %d",
      m_eLoggerStatus, m_eDevType, m_eLoggerUDPLoggingStatus,
      m_UserInvokedLoggingNumber);  // LCOV_EXCL_BR_LINE 11:Unexpected branch

  this->UpdateLoggingStatus();
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return eFrameworkunifiedStatusOK;
}

void CLoggerCfg::RemoveCarriageReturn(std::string &f_str) {
  if (f_str.empty()) {  // LCOV_EXCL_BR_LINE 8: Because there is no empty string case
    return;
  }

  if ('\r' == f_str.at(f_str.size() - 1)) {
    f_str.erase(f_str.size() - 1, 1);
  }
}
EFrameworkunifiedStatus CLoggerCfg::Load(const std::string &f_filePathAndName) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusDbRecNotFound;

  if ("" == f_filePathAndName) {  // LCOV_EXCL_BR_LINE 200: Because there is no empty string case
    // LCOV_EXCL_START 200: Because there is no empty string case
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Invalid configuration file name detected.");
    l_eStatus = eFrameworkunifiedStatusInvldParam;
    // LCOV_EXCL_STOP
  } else {
    // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Reading Configuration Data from %s", f_filePathAndName.c_str());

    CNSConfigReader *l_pReaderCfg = new CNSConfigReader();  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    if (NULL == l_pReaderCfg) {  // LCOV_EXCL_BR_LINE 5:new error
      // LCOV_EXCL_START 5:new error
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
             " Error. Unable to allocate CNSConfigReader object.");
      l_eStatus = eFrameworkunifiedStatusFileLoadError;
      // LCOV_EXCL_STOP
    } else {
      if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->Parse(f_filePathAndName))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               " Error. l_pReaderCfg->Parse(%s) returned: 0x%X",
               f_filePathAndName.c_str(), l_eStatus);
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.LogMaxFileSize", m_logMaxFileSize))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(LOGGING.LogMaxFileSize)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.PerformanceLogSize", m_performanceLogMaxFileSize))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(LOGGING.LogMaxFileSize)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.EmmcOutputPath", m_emmcOutputPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.EmmcOutputPath)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.EmmcOutputNaviLogPath", m_emmcOutputNaviLogPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus,
                   "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogPath)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.Usb0MountPath", m_usb0MountPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.Usb0MountPath)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.Usb1MountPath", m_usb1MountPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.Usb1MountPath)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.SdMountPath", m_sdMountPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.SdMountPath)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputMax", m_emmcOutputMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.EmmcOutputMax)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputErrMax", m_emmcOutputErrMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus,
                   "l_pReaderCfg->GetString(LOGGING.EmmcOutputErrMax)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputGrpRelaunchMax", m_emmcOutputGrpRelaunchMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus,
                   "l_pReaderCfg->GetString(LOGGING.EmmcOutputGrpRelaunchMax)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogMax", m_emmcOutputNaviLogMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus,
                   "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogMax)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogNmlMax", m_emmcOutputNaviLogNmlMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus,
                   "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogNmlMax)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogErrMax", m_emmcOutputNaviLogErrMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus,
                   "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogErrMax)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("STORAGE.ThreadName", m_loggerStorageInfo.Name))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(STORAGE.ThreadName)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.Priority", m_loggerStorageInfo.Priority))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.Priority)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.Timeout", m_loggerStorageInfo.Timeout))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.Timeout)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.TimeoutAfter", m_loggerStorageInfo.TimeoutAfter))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        // LCOV_EXCL_START 200:To ensure success
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.TimeoutAfter)");
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.ExternalLogNum", m_ExternalLogList.num))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.ExternalLogNum)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.ExternalLogMax", m_ExternalLogList.max))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
        LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.ExternalLogMax)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
      } else {
        RemoveCarriageReturn(m_emmcOutputPath);
        RemoveCarriageReturn(m_emmcOutputNaviLogPath);
        RemoveCarriageReturn(m_usb0MountPath);
        RemoveCarriageReturn(m_usb1MountPath);
        RemoveCarriageReturn(m_sdMountPath);
        RemoveCarriageReturn(m_loggerStorageInfo.Name);

        for (UI_32 i = 0; i < ZONE_MASK_ARRAY_ELTS; i++) {
          SI_32 l_logMaskTemp;
          std::stringstream l_cfgParamName;

          l_cfgParamName << "SETLOGMASK.MASK" << i;
          if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt(l_cfgParamName.str(), l_logMaskTemp))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
            // LCOV_EXCL_START 200:To ensure success
            AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
                   " Error. l_pReaderCfg->GetInt(%s) failed with error: %d.",
                   l_cfgParamName.str().c_str(), l_eStatus);

            break;
            // LCOV_EXCL_STOP
          } else {
            m_logMask[i] = (UI_32) l_logMaskTemp;
          }
        }

        m_EELStorageRelPath = "/EEL_export";
        m_EELActivateRelPath = "/EEL_activate";
        m_LoggerserviceEmmcLogsRelPath = "/LOGGERSERVICE_EMMC_LOGS";

        if (m_ExternalLogList.num > 0) {
          std::string str = "EXTERNAL_";  // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
          UI_32 num = 0;

          if (m_ExternalLogList.num <= m_ExternalLogList.max) {
            num = m_ExternalLogList.num;
          } else {
            num = m_ExternalLogList.max;
          }

          // LCOV_EXCL_BR_START 11:Excluded due to gcov constraints (others)
          m_ExternalLogList.p_info = new ExternalLogInfo[num];

          // Load external log info
          for (UI_32 i = 0; i < num; i++) {
            std::string query = str + std::to_string(i+1);
            if (eFrameworkunifiedStatusOK !=
                (l_eStatus = l_pReaderCfg->GetString((query+".OutputPath"), m_ExternalLogList.p_info[i].dirname))) {
              LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(EXTERNAL.OutputPath)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
            } else if (eFrameworkunifiedStatusOK !=
                (l_eStatus = l_pReaderCfg->GetString((query+".ExtLogPath"), m_ExternalLogList.p_info[i].path))) {
              LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(EXTERNAL.ExtLogPath)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
            } else if (eFrameworkunifiedStatusOK !=
                (l_eStatus = l_pReaderCfg->GetBool((query+".Remove"), m_ExternalLogList.p_info[i].remove))) {
              LOG_STATUS(l_eStatus, "l_pReaderCfg->GetBool(EXTERNAL.Remove)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
            } else {
              RemoveCarriageReturn(m_ExternalLogList.p_info[i].dirname);
              RemoveCarriageReturn(m_ExternalLogList.p_info[i].path);
            }
          }
          // LCOV_EXCL_BR_STOP 11:Excluded due to gcov constraints (others)
        } else {
          // None external log
        }

        if (eFrameworkunifiedStatusOK == l_eStatus) {  // LCOV_EXCL_BR_LINE 200:To ensure success
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
                 " Info. Configuration successfully loaded.");  // LCOV_EXCL_BR_LINE 15: macro
        }
      }

      delete l_pReaderCfg;  // LCOV_EXCL_BR_LINE 11:Unexpected branch
    }
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::Validate(void) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam;

  if (m_logMaxFileSize == 0) {  // LCOV_EXCL_BR_LINE 200:Because the size is never 0
    // LCOV_EXCL_START 200:Because the size is never 0
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. Invalid configuration detected. LogMaxFileSize: %d Must be > 0.",
        m_logMaxFileSize);
    // LCOV_EXCL_STOP
  } else if (m_emmcOutputPath == "") {
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. Invalid configuration detected."
        " EmmcOutputPath: %s Must be a valid path containing a trailing backslash.",
        m_emmcOutputPath.c_str());
  } else if (m_emmcOutputNaviLogPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
    // LCOV_EXCL_START 200:Because it is not always an empty string
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. Invalid configuration detected."
        " EmmcOutputNaviLogPath: %s Must be a valid path containing a trailing backslash.",
        m_emmcOutputNaviLogPath.c_str());
    // LCOV_EXCL_STOP
  } else if (m_usb0MountPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
    // LCOV_EXCL_START 200:Because it is not always an empty string
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. Invalid configuration detected."
        " Usb0MountPath: %s Must be a valid path containing a trailing backslash.",
        m_usb0MountPath.c_str());
    // LCOV_EXCL_STOP
  } else if (m_usb1MountPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
    // LCOV_EXCL_START 200:Because it is not always an empty string
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. Invalid configuration detected."
        " Usb1MountPath: %s Must be a valid path containing a trailing backslash.",
        m_usb1MountPath.c_str());
    // LCOV_EXCL_STOP
  } else if (m_sdMountPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
    // LCOV_EXCL_START 200:Because it is not always an empty string
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. Invalid configuration detected. SdMountPath: %s Must be a valid path containing a trailing backslash.",
        m_sdMountPath.c_str());
    // LCOV_EXCL_STOP
  } else {
    l_eStatus = eFrameworkunifiedStatusOK;
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

void CLoggerCfg::Print(void) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}

std::string CLoggerCfg::getEmmcOutputPath(void) {
  return (m_emmcOutputPath);
}

std::string CLoggerCfg::getEmmcOutputNaviLogPath(void) {
  return (m_emmcOutputNaviLogPath);
}

std::string CLoggerCfg::getUsb0MountPath(void) {
  return (m_usb0MountPath);
}
void CLoggerCfg::setUsb0MountPath(std::string& f_deviceMountpath) {
  m_usb0MountPath = f_deviceMountpath;
}

EFrameworkunifiedStatus CLoggerCfg::GetUserInvokedDestination(std::string& f_dest) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  f_dest = "";
  switch (m_eDevType) {
    case eDevUSB1:
      f_dest = m_usb0MountPath;
      break;

    case eDevUSB2:
      f_dest = m_usb1MountPath;
      break;

    case eDevSD:
      f_dest = m_sdMountPath;
      break;

    case eTotalDevicesTypes:
    case eInvalid_DevType:
    default:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Unknown device type: %d",
             m_eDevType);
      l_eStatus = eFrameworkunifiedStatusFail;
      break;
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::GetEmmcDestination(std::string& f_dest) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  f_dest = m_emmcOutputPath;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::GetEmmcNaviLogDestination(std::string& f_dest) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  f_dest = m_emmcOutputNaviLogPath;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

UI_32 CLoggerCfg::GetUserInvokedCounter(void) {
  return m_UserInvokedLoggingNumber;
}

EFrameworkunifiedStatus CLoggerCfg::GetIncrementAndPersistUserInvokedCounter(
    HANDLE f_hApp, UI_32 &f_counter) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  f_counter = m_UserInvokedLoggingNumber;
  m_UserInvokedLoggingNumber++;
  l_eStatus = PersistLoggingParam(f_hApp);

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::GetAndIncrementEmmcCounter(UI_32 &f_counter) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  std::string l_checkFileName;
  std::vector<UI_32> l_vector;
  DIR *l_dirp;
  struct dirent l_dirent;
  struct dirent* next = NULL;
  size_t l_pos;
  UI_32 l_count;
  UI_32 l_maxCount;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  if (m_EmmcCounter == 0u) {
    l_maxCount = 0;
    l_dirp = opendir(m_emmcOutputPath.c_str());
    if (l_dirp != NULL) {  // LCOV_EXCL_BR_LINE 5: m_emmcOutputPath is not null, opendir is C code, always ok
      for (;;) {
        int l_ret = readdir_r(l_dirp, &l_dirent, &next);
        if (((l_ret == 0) && (next == NULL))
            || (l_ret > 0)) {
          break;
        }
        l_checkFileName = l_dirent.d_name;
        l_pos = l_checkFileName.find(".tar.gz");
        if (std::string::npos != l_pos) {
          l_pos = l_checkFileName.find("_");
          if (std::string::npos != l_pos) {  // LCOV_EXCL_BR_LINE 200: tar.gz file is aways has "_"
            std::string l_numberString = l_checkFileName.substr(0, l_pos);
            l_count = static_cast<UI_32>(strtoul(l_numberString.c_str(), NULL, 10));
            l_vector.push_back(l_count);
            l_maxCount = std::max(l_count, l_maxCount);
          }
        }
      }
      closedir(l_dirp);
    } else {
      // LCOV_EXCL_START 5: m_emmcOutputPath is not null, opendir is C code, always ok
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      f_counter = 1;
      return eFrameworkunifiedStatusOK;
      // LCOV_EXCL_STOP
    }

    // reach at max number
    if (l_maxCount >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) {
      RefreshEmmcCounter(m_EmmcCounter);
    } else {
      m_EmmcCounter = l_maxCount + 1;
    }
  } else if (m_EmmcCounter >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) {
    // reach at max number
    RefreshEmmcCounter(m_EmmcCounter);
  } else {
    m_EmmcCounter++;
  }

  f_counter = m_EmmcCounter;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CLoggerCfg::RefreshEmmcCounter(UI_32& f_counter) const {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  std::string l_checkFileName;
  std::vector<std::string> l_vector;
  DIR *l_dirp;
  struct dirent l_dirent;
  struct dirent* next = NULL;
  size_t l_pos;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  // get filename saved frameworkunifiedlog on eMMC Device
  l_dirp = opendir(m_emmcOutputPath.c_str());
  if (l_dirp != NULL) {  // LCOV_EXCL_BR_LINE 5: m_emmcOutputPath is not null, opendir is C code, always ok
    for (;;) {
      int l_ret = readdir_r(l_dirp, &l_dirent, &next);
      if (((l_ret == 0) && (next == NULL)) || (l_ret > 0)) {
        break;
      }
      l_checkFileName = l_dirent.d_name;
      l_pos = l_checkFileName.find(".tar.gz");
      if (std::string::npos != l_pos) {
        l_pos = l_checkFileName.find("_");
        if (std::string::npos != l_pos) {
          l_vector.push_back(l_checkFileName);
        }
      }
    }
    closedir(l_dirp);
  } else {
    // LCOV_EXCL_START 5: m_emmcOutputPath is not null, opendir is C code, always ok
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    // ignore opendir failure. this means saved frameworkunifiedlog is nothing on eMMC Device
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open dir error path=%s errno=%s.",
           m_emmcOutputPath.c_str(), strerror(errno));
    f_counter = 1;
    return eFrameworkunifiedStatusOK;
    // LCOV_EXCL_STOP
  }

  // sort at log count
  std::sort(l_vector.begin(), l_vector.end());

  std::vector<std::string>::iterator it;
  std::string l_orgFilePath;
  std::string l_renameFilePath;
  UI_32 l_wpt = 0;
  UI_32 l_count;

  it = l_vector.begin();
  while (it != l_vector.end()) {
    std::stringstream l_nameStream;
    // get log counter parts
    l_wpt++;
    l_checkFileName = *it;
    l_pos = l_checkFileName.find("_");
    std::string l_numberString = l_checkFileName.substr(0, l_pos);
    l_count = static_cast<UI_32>(strtoul(l_numberString.c_str(), NULL, 10));

    // rename file if necessary
    if (l_count != l_wpt) {
      l_renameFilePath = l_orgFilePath = m_emmcOutputPath.c_str();
      l_renameFilePath.append("/");
      l_orgFilePath.append("/");
      l_orgFilePath.append(l_checkFileName);

      l_nameStream << std::setw(5) << std::setfill('0') << std::right
                   << std::dec << l_wpt;
      l_checkFileName.replace(0, l_pos, l_nameStream.str());

      l_renameFilePath.append(l_checkFileName);

      if (rename(l_orgFilePath.c_str(), l_renameFilePath.c_str()) != 0) {  // LCOV_EXCL_BR_LINE 5: rename is C code
        // LCOV_EXCL_START 5: rename is C code
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        // rename failed but continue reamin log rename because new log need to be saved.
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "log file[%s]->[%s] rename failed: err=%s.",
               l_orgFilePath.c_str(), l_renameFilePath.c_str(), strerror(errno));
        // LCOV_EXCL_STOP
      }
    }
    it++;
  }

  f_counter = l_wpt + 1;

  // set return value as next log counter
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

BOOL CLoggerCfg::IsUDPLoggingEnabled(void) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  BOOL l_ret =
      ((this->m_eLoggerUDPLoggingStatus == eActivate)
          || (this->m_udpEnvFlag == TRUE)) ? TRUE : FALSE;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %s", (TRUE == l_ret)?"TRUE":"FALSE");
  return (l_ret);
}

void CLoggerCfg::AddLoggingParamCB(CbFuncPtr f_fp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  if (f_fp != NULL) {  // LCOV_EXCL_BR_LINE 6: it aways not be null
    this->m_LoggingCallBack.push_back(f_fp);
    (void) f_fp(NULL);
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}

void CLoggerCfg::UpdateLoggingStatus(void) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  std::vector<CbFuncPtr>::iterator l_iter;
  for (l_iter = m_LoggingCallBack.begin(); l_iter != m_LoggingCallBack.end(); l_iter++) {  // LCOV_EXCL_BR_LINE 11:Unexpected branch  // NOLINT[whitespace/line_length]
    (void) (*l_iter)(NULL);
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}

EFrameworkunifiedStatus CLoggerCfg::GetLoggerStorageInfo(SLoggerStorageInfo &f_info) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  f_info = m_loggerStorageInfo;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

BOOL CLoggerCfg::IsLoggingEnabled(void) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  return (this->m_eLoggerStatus == eActivate) ? TRUE : FALSE;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}

ExternalLogList CLoggerCfg::GetExternalLogList(void) {
  return (m_ExternalLogList);
}  // LCOV_EXCL_BR_LINE 10:the last line