Skip to content

Commit 7620b87

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 07fe655 commit 7620b87

24 files changed

+834
-397
lines changed

Android.bp

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ cc_binary {
9797
"src/gateway/dlt_gateway.c",
9898
"src/lib/dlt_client.c",
9999
"src/shared/dlt_common.c",
100+
"src/shared/dlt_log.c",
100101
"src/shared/dlt_config_file_parser.c",
101102
"src/shared/dlt_multiple_files.c",
102103
"src/shared/dlt_offline_trace.c",
@@ -140,6 +141,7 @@ cc_library_shared {
140141
"src/lib/dlt_user.c",
141142
"src/shared/dlt_common.c",
142143
"src/shared/dlt_multiple_files.c",
144+
"src/shared/dlt_log.c",
143145
"src/shared/dlt_protocol.c",
144146
"src/shared/dlt_user_shared.c",
145147
],
@@ -196,6 +198,9 @@ cc_binary {
196198
"libdlt",
197199
"liblog",
198200
],
201+
include_dirs: [
202+
"system/core/include",
203+
],
199204
}
200205

201206
// vim: ft=python

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

+2-85
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
# include <netinet/in.h>
7777
# include <stdio.h>
7878
# include <stdbool.h>
79+
# include <stdarg.h>
7980
# ifdef __linux__
8081
# include <linux/limits.h>
8182
# include <sys/socket.h>
@@ -102,6 +103,7 @@
102103

103104
# include "dlt_types.h"
104105
# include "dlt_protocol.h"
106+
# include "dlt_log.h"
105107

106108
# define DLT_PACKED __attribute__((aligned(1), packed))
107109

@@ -191,13 +193,6 @@
191193
# define LOG_DAEMON (3 << 3)
192194
# endif
193195

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;
201196

202197
/**
203198
* The standard TCP Port used for DLT daemon, can be overwritten via -p \<port\> when starting dlt-daemon
@@ -1179,56 +1174,13 @@ void dlt_log_set_filename(const char *filename);
11791174
*/
11801175
void dlt_log_set_fifo_basedir(const char *pipe_dir);
11811176
#endif
1182-
/**
1183-
* Set internal logging level
1184-
* @param level the level
1185-
*/
1186-
void dlt_log_set_level(int level);
11871177

11881178
/**
11891179
* Set whether to print "name" and "unit" attributes in console output
11901180
* @param state true = with attributes, false = without attributes
11911181
*/
11921182
void dlt_print_with_attributes(bool state);
11931183

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-
12321184
/**
12331185
* Initialising a dlt receiver structure
12341186
* @param receiver pointer to dlt receiver structure
@@ -1686,41 +1638,6 @@ char *get_filename_ext(const char *filename);
16861638
*/
16871639
bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* base_name, long base_name_len);
16881640

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-
17241641
# ifdef __cplusplus
17251642
}
17261643
# endif

include/dlt/dlt_log.h

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

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "dlt_daemon_offline_logstorage.h"
7777
#include "dlt_gateway.h"
7878

79+
7980
#ifdef UDP_CONNECTION_SUPPORT
8081
# include "dlt_daemon_udp_socket.h"
8182
#endif
@@ -954,6 +955,7 @@ int main(int argc, char *argv[])
954955
return -1;
955956
}
956957

958+
957959
/* Initialize internal logging facility */
958960
dlt_log_set_filename(daemon_local.flags.loggingFilename);
959961
dlt_log_set_level(daemon_local.flags.loggingLevel);

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"

0 commit comments

Comments
 (0)