|
| 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 */ |
0 commit comments