ThingWorx C SDK
twLogger.h
Go to the documentation of this file.
1 /***************************************
2  * Copyright (C) 2015 ThingWorx Inc. *
3  ***************************************/
4 
12 #ifndef twLogger_H
13 #define twLogger_H
14 
15 #include "twOSPort.h"
16 #include "twErrors.h"
17 
18 #include <stdint.h>
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
26 enum LogLevel {
34 };
35 
45 typedef void (*log_function) ( enum LogLevel level, const char * timestamp, const char * message);
46 
50 typedef struct twLogger {
51  enum LogLevel level;
53  char isVerbose;
54  char * buffer;
56 } twLogger;
57 
65 
72 int twLogger_Delete();
73 
82 int twLogger_SetLevel(enum LogLevel level);
83 
93 
103 int twLogger_SetIsVerbose(char val);
104 
114 void twLog(enum LogLevel level, const char * format, ... );
115 
126 void twLogHexString(const char * msg, char * preamble, int32_t length);
127 
137 void twLogMessage(void * m, char * preamble);
138 
139 /* Helper functions for creating log messages */
140 
150 char * twCodeToString(enum msgCodeEnum m);
151 
161 char * twEntityToString(enum entityTypeEnum m);
162 
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif
char * twCodeToString(enum msgCodeEnum m)
Helper function to convert a msgCodeEnum to a string.
Definition: twLogger.c:111
char isVerbose
Definition: twLogger.h:53
void(* log_function)(enum LogLevel level, const char *timestamp, const char *message)
Signature for logging function to be called when twLog() is invoked.
Definition: twLogger.h:45
TW_MUTEX mtx
Definition: twLogger.h:55
void twLogHexString(const char *msg, char *preamble, int32_t length)
Logs a hex string message.
Definition: twLogger.c:420
ThingWorx C SDK error code definitions.
Definition: twLogger.h:30
char * twCharacteristicToString(enum characteristicEnum m)
Helper function to convert a characteristicEnum to a string.
Definition: twLogger.c:179
#define TW_MUTEX
For Linux builds a TW_MUTEX is a pthread_mutex_t.
Definition: twLinux-openssl.h:81
int twLogger_Delete()
Frees all memory associated with the twLogger singleton.
Definition: twLogger.c:53
Definition: twLogger.h:28
Definition: twLogger.h:31
int twLogger_SetIsVerbose(char val)
Sets the twLogger::isVerbose flag of the twLogger singleton.
Definition: twLogger.c:80
Wrappers for OS-specific functionality.
ThingWorx Logger singleton structure definition.
Definition: twLogger.h:50
log_function f
Definition: twLogger.h:52
int twLogger_SetFunction(log_function f)
Sets the ::twLogger#log_function of the twLogger singleton.
Definition: twLogger.c:72
Definition: twLogger.h:33
LogLevel
Log message level enumeration.
Definition: twLogger.h:26
struct twLogger twLogger
ThingWorx Logger singleton structure definition.
entityTypeEnum
Definition: twDefinitions.h:113
Definition: twLogger.h:27
msgCodeEnum
Enumeration of HTTP message codes.
Definition: twDefinitions.h:74
char * buffer
Definition: twLogger.h:54
characteristicEnum
Definition: twDefinitions.h:146
twLogger * twLogger_Instance()
Gets a pointer to the twLogger singleton and creates a new one if it hasn't been created already...
Definition: twLogger.c:39
int twLogger_SetLevel(enum LogLevel level)
Sets the ::twLogger#LogLevel of the twLogger singleton.
Definition: twLogger.c:64
Definition: twLogger.h:29
enum LogLevel level
Definition: twLogger.h:51
Definition: twLogger.h:32
void twLogMessage(void *m, char *preamble)
Logs a generic string message.
Definition: twLogger.c:388
void twLog(enum LogLevel level, const char *format,...)
Logs a message.
Definition: twLogger.c:88
char * twEntityToString(enum entityTypeEnum m)
Helper function to convert a entityTypeEnum to a string.
Definition: twLogger.c:166