acc_integration_log.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2019-2023
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6
7 #include <stdarg.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <stdio.h>
11
12 #include "acc_definitions_common.h"
13 #include "acc_integration.h"
14 #include "acc_integration_log.h"
15
16 #define LOG_BUFFER_MAX_SIZE 150
17
18 #define LOG_FORMAT "%02u:%02u:%02u.%03u (%c) (%s) %s\n"
19
20
21 void acc_integration_log(acc_log_level_t level, const char *module, const char *format, ...)
22 {
23 char log_buffer[LOG_BUFFER_MAX_SIZE];
24 va_list ap;
25
26 va_start(ap, format);
27
28 int ret = vsnprintf(log_buffer, LOG_BUFFER_MAX_SIZE, format, ap);
29
30 if (ret >= LOG_BUFFER_MAX_SIZE)
31 {
32 log_buffer[LOG_BUFFER_MAX_SIZE - 4] = '.';
33 log_buffer[LOG_BUFFER_MAX_SIZE - 3] = '.';
34 log_buffer[LOG_BUFFER_MAX_SIZE - 2] = '.';
35 log_buffer[LOG_BUFFER_MAX_SIZE - 1] = 0;
36 }
37
38 uint32_t time_ms = acc_integration_get_time();
39 char level_ch;
40
41 unsigned int timestamp = time_ms;
42 unsigned int hours = timestamp / 1000 / 60 / 60;
43 unsigned int minutes = timestamp / 1000 / 60 % 60;
44 unsigned int seconds = timestamp / 1000 % 60;
45 unsigned int milliseconds = timestamp % 1000;
46
47 level_ch = (level <= ACC_LOG_LEVEL_DEBUG) ? "EWIVD"[level] : '?';
48
49 printf(LOG_FORMAT, hours, minutes, seconds, milliseconds, level_ch, module, log_buffer);
50
51 fflush(stdout);
52
53 va_end(ap);
54 }
acc_integration_get_time
uint32_t acc_integration_get_time(void)
Get current time.
Definition: acc_integration_stm32.c:626
acc_integration_log
void acc_integration_log(acc_log_level_t level, const char *module, const char *format,...)
Log function.
Definition: acc_integration_log.c:21
vsnprintf
#define vsnprintf
Definition: printf.h:85
ACC_LOG_LEVEL_DEBUG
@ ACC_LOG_LEVEL_DEBUG
Definition: acc_definitions_common.h:36
LOG_FORMAT
#define LOG_FORMAT
Definition: acc_integration_log.c:18
acc_integration.h
acc_log_level_t
acc_log_level_t
This enum represents the different log levels for RSS.
Definition: acc_definitions_common.h:25
printf
#define printf
Definition: printf.h:60
LOG_BUFFER_MAX_SIZE
#define LOG_BUFFER_MAX_SIZE
Definition: acc_integration_log.c:16
acc_integration_log.h
acc_definitions_common.h