Skip to content

Commit da3bde3

Browse files
refactor: split dlt_common and dlt_log
Seperate all internal logging function into an own source file. This reduces the scope of the sprawling dlt_common source file.
1 parent 75f6c95 commit da3bde3

23 files changed

+529
-412
lines changed

Android.bp

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ cc_binary {
9999
"src/gateway/dlt_gateway.c",
100100
"src/lib/dlt_client.c",
101101
"src/shared/dlt_common.c",
102+
"src/shared/dlt_log.c",
102103
"src/shared/dlt_config_file_parser.c",
103104
"src/shared/dlt_multiple_files.c",
104105
"src/shared/dlt_offline_trace.c",
@@ -142,6 +143,7 @@ cc_library_shared {
142143
"src/lib/dlt_user.c",
143144
"src/shared/dlt_common.c",
144145
"src/shared/dlt_multiple_files.c",
146+
"src/shared/dlt_log.c",
145147
"src/shared/dlt_protocol.c",
146148
"src/shared/dlt_user_shared.c",
147149
],

include/dlt/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
configure_file(dlt_user.h.in dlt_user.h)
2121

2222
set(HEADER_LIST dlt.h dlt_user_macros.h dlt_client.h dlt_protocol.h
23-
dlt_common.h dlt_types.h dlt_shm.h dlt_offline_trace.h
23+
dlt_common.h dlt_log.h dlt_types.h dlt_shm.h dlt_offline_trace.h
2424
dlt_filetransfer.h dlt_common_api.h dlt_multiple_files.h
2525
${CMAKE_CURRENT_BINARY_DIR}/dlt_version.h
2626
${CMAKE_CURRENT_BINARY_DIR}/dlt_user.h)

include/dlt/dlt_common.h

+1-90
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102

103103
# include "dlt_types.h"
104104
# include "dlt_protocol.h"
105+
# include "dlt_log.h"
105106

106107
# define DLT_PACKED __attribute__((aligned(1), packed))
107108

@@ -191,13 +192,6 @@
191192
# define LOG_DAEMON (3 << 3)
192193
# endif
193194

194-
typedef enum {
195-
DLT_LOG_TO_CONSOLE = 0,
196-
DLT_LOG_TO_SYSLOG = 1,
197-
DLT_LOG_TO_FILE = 2,
198-
DLT_LOG_TO_STDERR = 3,
199-
DLT_LOG_DROPPED = 4
200-
} DltLoggingMode;
201195

202196
/**
203197
* The standard TCP Port used for DLT daemon, can be overwritten via -p \<port\> when starting dlt-daemon
@@ -1167,68 +1161,20 @@ DltReturnValue dlt_file_message(DltFile *file, int index, int verbose);
11671161
*/
11681162
DltReturnValue dlt_file_free(DltFile *file, int verbose);
11691163

1170-
/**
1171-
* Set internal logging filename if mode 2
1172-
* @param filename the filename
1173-
*/
1174-
void dlt_log_set_filename(const char *filename);
11751164
#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC
11761165
/**
11771166
* Set FIFO base direction
11781167
* @param pipe_dir the pipe direction
11791168
*/
11801169
void dlt_log_set_fifo_basedir(const char *pipe_dir);
11811170
#endif
1182-
/**
1183-
* Set internal logging level
1184-
* @param level the level
1185-
*/
1186-
void dlt_log_set_level(int level);
11871171

11881172
/**
11891173
* Set whether to print "name" and "unit" attributes in console output
11901174
* @param state true = with attributes, false = without attributes
11911175
*/
11921176
void dlt_print_with_attributes(bool state);
11931177

1194-
/**
1195-
* Initialize (external) logging facility
1196-
* @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file, 3 = log to stderr
1197-
*/
1198-
DltReturnValue dlt_log_init(int mode);
1199-
/**
1200-
* Print with variable arguments to specified file descriptor by DLT_LOG_MODE environment variable (like fprintf)
1201-
* @param format format string for message
1202-
* @return negative value if there was an error or the total number of characters written is returned on success
1203-
*/
1204-
int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1, 2);
1205-
/**
1206-
* Log ASCII string with null-termination to (external) logging facility
1207-
* @param prio priority (see syslog() call)
1208-
* @param s Pointer to ASCII string with null-termination
1209-
* @return negative value if there was an error
1210-
*/
1211-
DltReturnValue dlt_log(int prio, char *s);
1212-
/**
1213-
* Log with variable arguments to (external) logging facility (like printf)
1214-
* @param prio priority (see syslog() call)
1215-
* @param format format string for log message
1216-
* @return negative value if there was an error
1217-
*/
1218-
DltReturnValue dlt_vlog(int prio, const char *format, ...) PRINTF_FORMAT(2, 3);
1219-
/**
1220-
* Log size bytes with variable arguments to (external) logging facility (similar to snprintf)
1221-
* @param prio priority (see syslog() call)
1222-
* @param size number of bytes to log
1223-
* @param format format string for log message
1224-
* @return negative value if there was an error
1225-
*/
1226-
DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) PRINTF_FORMAT(3, 4);
1227-
/**
1228-
* De-Initialize (external) logging facility
1229-
*/
1230-
void dlt_log_free(void);
1231-
12321178
/**
12331179
* Initialising a dlt receiver structure
12341180
* @param receiver pointer to dlt receiver structure
@@ -1686,41 +1632,6 @@ char *get_filename_ext(const char *filename);
16861632
*/
16871633
bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* base_name, long base_name_len);
16881634

1689-
/**
1690-
* Initialize (external) logging facility
1691-
* @param mode DltLoggingMode, 0 = log to stdout, 1 = log to syslog, 2 = log to file, 3 = log to stderr
1692-
* @param enable_multiple_logfiles, true if multiple logfiles (incl. size limits) should be use
1693-
* @param logging_file_size, maximum size in bytes of one logging file
1694-
* @param logging_files_max_size, maximum size in bytes of all logging files
1695-
*/
1696-
DltReturnValue dlt_log_init_multiple_logfiles_support(DltLoggingMode mode, bool enable_multiple_logfiles, int logging_file_size, int logging_files_max_size);
1697-
1698-
/**
1699-
* Initialize (external) logging facility for single logfile.
1700-
*/
1701-
DltReturnValue dlt_log_init_single_logfile();
1702-
1703-
/**
1704-
* Initialize (external) logging facility for multiple files logging.
1705-
*/
1706-
DltReturnValue dlt_log_init_multiple_logfiles(int logging_file_size, int logging_files_max_size);
1707-
1708-
/**
1709-
* Logs into log files represented by the multiple files buffer.
1710-
* @param format First element in a specific format that will be logged.
1711-
* @param ... Further elements in a specific format that will be logged.
1712-
*/
1713-
void dlt_log_multiple_files_write(const char* format, ...);
1714-
1715-
void dlt_log_free_single_logfile();
1716-
1717-
void dlt_log_free_multiple_logfiles();
1718-
1719-
/**
1720-
* Checks whether (internal) logging in multiple files is active.
1721-
*/
1722-
bool dlt_is_log_in_multiple_files_active();
1723-
17241635
# ifdef __cplusplus
17251636
}
17261637
# endif

include/dlt/dlt_log.h

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* SPDX license identifier: MPL-2.0
3+
*
4+
* Copyright (C) 2024, Mercedes Benz Tech Innovation GmbH
5+
*
6+
* This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
7+
*
8+
* This Source Code Form is subject to the terms of the
9+
* Mozilla Public License (MPL), v. 2.0.
10+
* If a copy of the MPL was not distributed with this file,
11+
* You can obtain one at http://mozilla.org/MPL/2.0/.
12+
*
13+
* For further information see https://www.covesa.global/.
14+
*/
15+
16+
/*!
17+
* \author
18+
* Daniel Weber <daniel.w.weber@mercedes-benz.com>
19+
*
20+
* \copyright Copyright © 2024 Mercedes Benz Tech Innovation GmbH. \n
21+
* License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
22+
*
23+
* \file dlt_log.h
24+
*/
25+
26+
#ifndef DLT_COMMON_LOG_H
27+
#define DLT_COMMON_LOG_H
28+
29+
#include <stdio.h>
30+
#include <stdbool.h>
31+
#include "dlt_types.h"
32+
33+
# if defined(__GNUC__)
34+
# define PURE_FUNCTION __attribute__((pure))
35+
# define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, a, b)))
36+
# else
37+
# define PURE_FUNCTION /* nothing */
38+
# define PRINTF_FORMAT(a,b) /* nothing */
39+
# endif
40+
41+
typedef enum {
42+
DLT_LOG_TO_CONSOLE = 0,
43+
DLT_LOG_TO_SYSLOG = 1,
44+
DLT_LOG_TO_FILE = 2,
45+
DLT_LOG_TO_STDERR = 3,
46+
DLT_LOG_DROPPED = 4
47+
} DltLoggingMode;
48+
49+
/* initialize this variables in dlt_log.c */
50+
extern DltLoggingMode logging_mode;
51+
extern FILE *logging_handle;
52+
53+
# ifdef __cplusplus
54+
extern "C"
55+
{
56+
# endif
57+
58+
/**
59+
* Set internal logging filename if mode 2
60+
* @param filename the filename
61+
*/
62+
void dlt_log_set_filename(const char *filename);
63+
64+
/**
65+
* Set internal logging level
66+
* @param level the level
67+
*/
68+
void dlt_log_set_level(int level);
69+
70+
/**
71+
* Initialize (external) logging facility
72+
* @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file, 3 = log to stderr
73+
*/
74+
void dlt_log_init(int mode);
75+
76+
/**
77+
* Initialize (external) logging facility
78+
* @param mode DltLoggingMode, 0 = log to stdout, 1 = log to syslog, 2 = log to file, 3 = log to stderr
79+
* @param enable_multiple_logfiles, true if multiple logfiles (incl. size limits) should be use
80+
* @param logging_file_size, maximum size in bytes of one logging file
81+
* @param logging_files_max_size, maximum size in bytes of all logging files
82+
*/
83+
DltReturnValue dlt_log_init_multiple_logfiles_support(DltLoggingMode mode, bool enable_multiple_logfiles, int logging_file_size, int logging_files_max_size);
84+
85+
/**
86+
* Initialize (external) logging facility for single logfile.
87+
*/
88+
DltReturnValue dlt_log_init_single_logfile();
89+
90+
/**
91+
* Initialize (external) logging facility for multiple files logging.
92+
*/
93+
DltReturnValue dlt_log_init_multiple_logfiles(int logging_file_size, int logging_files_max_size);
94+
95+
/**
96+
* Print with variable arguments to specified file descriptor by DLT_LOG_MODE environment variable (like fprintf)
97+
* @param format format string for message
98+
* @return negative value if there was an error or the total number of characters written is returned on success
99+
*/
100+
int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1, 2);
101+
102+
/**
103+
* Log ASCII string with null-termination to (external) logging facility
104+
* @param prio priority (see syslog() call)
105+
* @param s Pointer to ASCII string with null-termination
106+
* @return negative value if there was an error
107+
*/
108+
DltReturnValue dlt_log(int prio, const char *s);
109+
110+
/**
111+
* Log with variable arguments to (external) logging facility (like printf)
112+
* @param prio priority (see syslog() call)
113+
* @param format format string for log message
114+
* @return negative value if there was an error
115+
*/
116+
DltReturnValue dlt_vlog(int prio, const char *format, ...) PRINTF_FORMAT(2, 3);
117+
118+
/**
119+
* Log size bytes with variable arguments to (external) logging facility (similar to snprintf)
120+
* @param prio priority (see syslog() call)
121+
* @param size number of bytes to log
122+
* @param format format string for log message
123+
* @return negative value if there was an error
124+
*/
125+
DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) PRINTF_FORMAT(3, 4);
126+
127+
/**
128+
* Logs into log files represented by the multiple files buffer.
129+
* @param format First element in a specific format that will be logged.
130+
* @param ... Further elements in a specific format that will be logged.
131+
*/
132+
void dlt_log_multiple_files_write(const char* format, ...);
133+
134+
/**
135+
* De-Initialize (external) logging facility
136+
*/
137+
void dlt_log_free(void);
138+
139+
void dlt_log_free_single_logfile();
140+
141+
void dlt_log_free_multiple_logfiles();
142+
143+
/**
144+
* Checks whether (internal) logging in multiple files is active.
145+
*/
146+
bool dlt_is_log_in_multiple_files_active();
147+
148+
# ifdef __cplusplus
149+
}
150+
# endif
151+
152+
#endif /* DLT_COMMON_LOG_H */

src/console/dlt-receive.c

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
#endif
8585
#include <inttypes.h>
8686

87+
#include "dlt_log.h"
8788
#include "dlt_client.h"
8889
#include "dlt-control-common.h"
8990

src/daemon/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(dlt_daemon_SRCS
3232
${PROJECT_SOURCE_DIR}/src/lib/dlt_client.c
3333
${PROJECT_SOURCE_DIR}/src/shared/dlt_common.c
3434
${PROJECT_SOURCE_DIR}/src/shared/dlt_config_file_parser.c
35+
${PROJECT_SOURCE_DIR}/src/shared/dlt_log.c
3536
${PROJECT_SOURCE_DIR}/src/shared/dlt_multiple_files.c
3637
${PROJECT_SOURCE_DIR}/src/shared/dlt_offline_trace.c
3738
${PROJECT_SOURCE_DIR}/src/shared/dlt_protocol.c

src/daemon/dlt_daemon_client.c

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#endif
5353

5454
#include "dlt_types.h"
55+
#include "dlt_log.h"
5556
#include "dlt-daemon.h"
5657
#include "dlt-daemon_cfg.h"
5758
#include "dlt_daemon_common_cfg.h"

src/daemon/dlt_daemon_common.c

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include <sys/socket.h> /* send() */
7878

7979
#include "dlt_types.h"
80+
#include "dlt_log.h"
8081
#include "dlt_daemon_common.h"
8182
#include "dlt_daemon_common_cfg.h"
8283
#include "dlt_user_shared.h"

src/daemon/dlt_daemon_common.h

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
# include <semaphore.h>
8080
# include <stdbool.h>
8181
# include "dlt_common.h"
82+
# include "dlt_log.h"
8283
# include "dlt_user.h"
8384
# include "dlt_offline_logstorage.h"
8485
# include "dlt_gateway_types.h"

src/daemon/dlt_daemon_connection.c

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "dlt-daemon_cfg.h"
4545
#include "dlt_daemon_common.h"
4646
#include "dlt_common.h"
47+
#include "dlt_log.h"
4748
#include "dlt_gateway.h"
4849
#include "dlt_daemon_socket.h"
4950

src/daemon/dlt_daemon_event_handler.c

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <syslog.h>
3535

3636
#include "dlt_common.h"
37+
#include "dlt_log.h"
3738

3839
#include "dlt-daemon.h"
3940
#include "dlt-daemon_cfg.h"

src/daemon/dlt_daemon_socket.c

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#endif
5454

5555
#include "dlt_types.h"
56+
#include "dlt_log.h"
5657
#include "dlt-daemon.h"
5758
#include "dlt-daemon_cfg.h"
5859
#include "dlt_daemon_common_cfg.h"

src/gateway/dlt_gateway.c

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "dlt_gateway_internal.h"
4141
#include "dlt_config_file_parser.h"
4242
#include "dlt_common.h"
43+
#include "dlt_log.h"
4344
#include "dlt-daemon_cfg.h"
4445
#include "dlt_daemon_common_cfg.h"
4546
#include "dlt_daemon_event_handler.h"

src/lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set(dlt_LIB_SRCS
1919
dlt_filetransfer.c
2020
dlt_env_ll.c
2121
${PROJECT_SOURCE_DIR}/src/shared/dlt_common.c
22+
${PROJECT_SOURCE_DIR}/src/shared/dlt_log.c
2223
${PROJECT_SOURCE_DIR}/src/shared/dlt_multiple_files.c
2324
${PROJECT_SOURCE_DIR}/src/shared/dlt_protocol.c
2425
${PROJECT_SOURCE_DIR}/src/shared/dlt_user_shared.c

src/lib/dlt_client.c

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include <poll.h>
9595

9696
#include "dlt_types.h"
97+
#include "dlt_log.h"
9798
#include "dlt_client.h"
9899
#include "dlt_client_cfg.h"
99100

0 commit comments

Comments
 (0)