MQTT C Client Libraries Internals: Log.c File Reference

| MQTT C Client Libraries Internals

Data Structures | Macros | Functions | Variables
Log.c File Reference

Logging and tracing module. More...

`#include "Log.h"`
`#include "MQTTPacket.h"`
`#include "MQTTProtocol.h"`
`#include "MQTTProtocolClient.h"`
`#include "Messages.h"`
`#include "LinkedList.h"`
`#include "StackTrace.h"`
`#include "Thread.h"`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <stdarg.h>`
`#include <time.h>`
`#include <string.h>`
`#include <syslog.h>`
`#include <sys/stat.h>`
`#include <sys/time.h>`
Include dependency graph for Log.c:

## Data Structures
struct | traceEntry

## Macros
#define | GETTIMEOFDAY 1
#define | _unlink unlink
| _unlink mapping for linux
#define | min(A, B) ( (A) < (B) ? (A):(B))
#define | MAX_FUNCTION_NAME_LENGTH 256

## Functions
static traceEntry * | Log_pretrace (void)
static char * | Log_formatTraceEntry (traceEntry *cur_entry)
static void | Log_output (enum LOG_LEVELS log_level, const char *msg)
static void | Log_posttrace (enum LOG_LEVELS log_level, traceEntry *cur_entry)
static void | Log_trace (enum LOG_LEVELS log_level, const char *buf)
int | Log_initialize (Log_nameValue *info)
void | Log_setTraceCallback (Log_traceCallback *callback)
void | Log_setTraceLevel (enum LOG_LEVELS level)
void | Log_terminate (void)
void | Log (enum LOG_LEVELS log_level, int msgno, const char *format,...)
| Log a message. More...
void | Log_stackTrace (enum LOG_LEVELS log_level, int msgno, thread_id_type thread_id, int current_depth, const char *name, int line, int *rc)
| The reason for this function is to make trace logging as fast as possible so that the function exit/entry history can be captured by default without unduly impacting performance. More...

## Variables
trace_settings_type | trace_settings
static int | start_index = -1
static int | next_index = 0
static traceEntry * | trace_queue = NULL
static int | trace_queue_size = 0
static FILE * | trace_destination = NULL
| flag to indicate if trace is to be sent to a stream
static char * | trace_destination_name = NULL
| the name of the trace file
static char * | trace_destination_backup_name = NULL
| the name of the backup trace file
static int | lines_written = 0
| number of lines written to the current output file
static int | max_lines_per_file = 1000
| maximum number of lines to write to one trace file
static enum LOG_LEVELS | trace_output_level = INVALID_LEVEL
static Log_traceCallback * | trace_callback = NULL
static int | sametime_count = 0
struct timeval now_ts | last_ts
static char | msg_buf [512]
static pthread_mutex_t | log_mutex_store = PTHREAD_MUTEX_INITIALIZER
static mutex_type | log_mutex = &log_mutex_store

## Detailed Description

Logging and tracing module.

## Function Documentation

## ◆ Log()

void Log | ( | enum LOG_LEVELS | log_level,
|  | int | msgno,
|  | const char * | format,
|  |  | ...
| ) |  |

Log a message.

If possible, all messages should be indexed by message number, and the use of the format string should be minimized or negated altogether. If format is provided, the message number is only used as a message label.

Parameters

  log_level | the log level of the message
  msgno | the id of the message to use if the format string is NULL
  aFormat | the printf format string to be used if the message id does not exist
  ... | the printf inserts

## ◆ Log_stackTrace()

void Log_stackTrace | ( | enum LOG_LEVELS | log_level,
|  | int | msgno,
|  | thread_id_type | thread_id,
|  | int | current_depth,
|  | const char * | name,
|  | int | line,
|  | int * | rc
| ) |  |

The reason for this function is to make trace logging as fast as possible so that the function exit/entry history can be captured by default without unduly impacting performance.

Therefore it must do as little as possible.

Parameters

  log_level | the log level of the message
  msgno | the id of the message to use if the format string is NULL
  aFormat | the printf format string to be used if the message id does not exist
  ... | the printf inserts

## Variable Documentation

## ◆ trace_settings

trace_settings_type trace_settings

Initial value:
=
{
TRACE_MINIMUM,
400,
INVALID_LEVEL
}