1 /******************************************************************************* 2 * Copyright (c) 2009, 2022 IBM Corp. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License v2.0 6 * and Eclipse Distribution License v1.0 which accompany this distribution. 7 * 8 * The Eclipse Public License is available at 9 * https://www.eclipse.org/legal/epl-2.0/ 10 * and the Eclipse Distribution License is available at 11 * http://www.eclipse.org/org/documents/edl-v10.php. 12 * 13 * Contributors: 14 * Ian Craggs - initial API and implementation and/or initial documentation 15 * Ian Craggs - updates for the async client 16 *******************************************************************************/ 17 18 #if !defined(LOG_H) 19 #define LOG_H 20 21 #if defined(_WIN32) || defined(_WIN64) 22 #include <windows.h> 23 #define thread_id_type DWORD 24 #elif defined(COMPAT_CMSIS) 25 #include <cmsis_os2.h> 26 typedef osThreadId_t thread_id_type; 27 #else 28 #include <pthread.h> 29 #define thread_id_type pthread_t 30 #endif 31 32 /*BE 33 map LOG_LEVELS 34 { 35 "TRACE_MAXIMUM" 1 36 "TRACE_MEDIUM" 2 37 "TRACE_MINIMUM" 3 38 "TRACE_PROTOCOL" 4 39 40 "ERROR" 5 41 "SEVERE" 6 42 "FATAL" 7 43 } 44 BE*/ 45 46 enum LOG_LEVELS { 47 INVALID_LEVEL = -1, 48 TRACE_MAXIMUM = 1, 49 TRACE_MEDIUM, 50 TRACE_MINIMUM, 51 TRACE_PROTOCOL, 52 LOG_ERROR, 53 LOG_SEVERE, 54 LOG_FATAL, 55 }; 56 57 58 /*BE 59 def trace_settings_type 60 { 61 n32 map LOG_LEVELS "trace_level" 62 n32 dec "max_trace_entries" 63 n32 dec "trace_output_level" 64 } 65 BE*/ 66 typedef struct 67 { 68 enum LOG_LEVELS trace_level; /**< trace level */ 69 int max_trace_entries; /**< max no of entries in the trace buffer */ 70 enum LOG_LEVELS trace_output_level; /**< trace level to output to destination */ 71 } trace_settings_type; 72 73 extern trace_settings_type trace_settings; 74 75 #define LOG_PROTOCOL TRACE_PROTOCOL 76 #define TRACE_MAX TRACE_MAXIMUM 77 #define TRACE_MIN TRACE_MINIMUM 78 #define TRACE_MED TRACE_MEDIUM 79 80 typedef struct 81 { 82 const char* name; 83 const char* value; 84 } Log_nameValue; 85 86 int Log_initialize(Log_nameValue*); 87 void Log_terminate(void); 88 89 void Log(enum LOG_LEVELS, int, const char *, ...); 90 void Log_stackTrace(enum LOG_LEVELS, int, thread_id_type, int, const char*, int, int*); 91 92 typedef void Log_traceCallback(enum LOG_LEVELS level, const char *message); 93 void Log_setTraceCallback(Log_traceCallback* callback); 94 void Log_setTraceLevel(enum LOG_LEVELS level); 95 96 #endif 97