FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Typedefs | Functions | Variables
switch_log.c File Reference
#include <switch.h>
#include "private/switch_core_pvt.h"
+ Include dependency graph for switch_log.c:

Go to the source code of this file.

Data Structures

struct  switch_log_binding
 

Macros

#define do_mods   (LOG_QUEUE && THREAD_RUNNING)
 

Typedefs

typedef struct switch_log_binding switch_log_binding_t
 

Functions

static switch_log_node_tswitch_log_node_alloc ()
 
switch_log_node_tswitch_log_node_dup (const switch_log_node_t *node)
 
void switch_log_node_free (switch_log_node_t **pnode)
 
const char * switch_log_level2str (switch_log_level_t level)
 
uint32_t switch_log_str2mask (const char *str)
 
switch_log_level_t switch_log_str2level (const char *str)
 
switch_status_t switch_log_unbind_logger (switch_log_function_t function)
 
switch_status_t switch_log_bind_logger (switch_log_function_t function, switch_log_level_t level, switch_bool_t is_console)
 
static void *SWITCH_THREAD_FUNC log_thread (switch_thread_t *t, void *obj)
 
void switch_log_printf (switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, const char *fmt,...)
 
void switch_log_vprintf (switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, const char *fmt, va_list ap)
 
switch_status_t switch_log_init (switch_memory_pool_t *pool, switch_bool_t colorize)
 
void switch_core_memory_reclaim_logger (void)
 
switch_status_t switch_log_shutdown (void)
 Shut down the logging engine. More...
 

Variables

static const char * LEVELS []
 
static switch_memory_pool_tLOG_POOL = NULL
 
static switch_log_binding_tBINDINGS = NULL
 
static switch_mutex_tBINDLOCK = NULL
 
static switch_queue_tLOG_QUEUE = NULL
 
static int8_t THREAD_RUNNING = 0
 
static uint8_t MAX_LEVEL = 0
 
static int mods_loaded = 0
 
static int console_mods_loaded = 0
 
static switch_bool_t COLORIZE = SWITCH_FALSE
 
static const char * COLORS []
 
static switch_thread_tthread
 

Macro Definition Documentation

#define do_mods   (LOG_QUEUE && THREAD_RUNNING)

Definition at line 331 of file switch_log.c.

Referenced by switch_log_vprintf().

Typedef Documentation

Definition at line 55 of file switch_log.c.

Function Documentation

static void* SWITCH_THREAD_FUNC log_thread ( switch_thread_t t,
void *  obj 
)
static

Definition at line 281 of file switch_log.c.

References BINDLOCK, switch_log_binding::function, switch_log_binding::level, switch_log_node_t::level, LOG_QUEUE, switch_log_binding::next, SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_node_free(), switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_pop(), SWITCH_STATUS_SUCCESS, and THREAD_RUNNING.

Referenced by switch_log_init().

282 {
283 
284  if (!obj) {
285  obj = NULL;
286  }
287  THREAD_RUNNING = 1;
288 
289  while (THREAD_RUNNING == 1) {
290  void *pop = NULL;
291  switch_log_node_t *node = NULL;
292  switch_log_binding_t *binding;
293 
295  break;
296  }
297 
298  if (!pop) {
299  THREAD_RUNNING = -1;
300  break;
301  }
302 
303  node = (switch_log_node_t *) pop;
305  for (binding = BINDINGS; binding; binding = binding->next) {
306  if (binding->level >= node->level) {
307  binding->function(node, node->level);
308  }
309  }
311 
312  switch_log_node_free(&node);
313 
314  }
315 
316  THREAD_RUNNING = 0;
318  return NULL;
319 }
switch_log_level_t level
Definition: switch_log.h:59
Log Data.
Definition: switch_log.h:49
#define SWITCH_CHANNEL_LOG
switch_log_function_t function
Definition: switch_log.c:49
struct switch_log_binding * next
Definition: switch_log.c:52
void switch_log_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, const char *fmt,...)
Definition: switch_log.c:321
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1119
static switch_log_binding_t * BINDINGS
Definition: switch_log.c:58
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static switch_queue_t * LOG_QUEUE
Definition: switch_log.c:60
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static int8_t THREAD_RUNNING
Definition: switch_log.c:64
static switch_mutex_t * BINDLOCK
Definition: switch_log.c:59
void switch_log_node_free(switch_log_node_t **pnode)
Definition: switch_log.c:125
switch_log_level_t level
Definition: switch_log.c:50
switch_status_t switch_log_bind_logger ( switch_log_function_t  function,
switch_log_level_t  level,
switch_bool_t  is_console 
)

Definition at line 245 of file switch_log.c.

References BINDLOCK, console_mods_loaded, switch_log_binding::function, switch_log_binding::is_console, switch_log_binding::level, LOG_POOL, MAX_LEVEL, mods_loaded, switch_log_binding::next, switch_assert, switch_core_alloc, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_MEMERR, and SWITCH_STATUS_SUCCESS.

246 {
247  switch_log_binding_t *binding = NULL, *ptr = NULL;
248  switch_assert(function != NULL);
249 
250  if (!(binding = switch_core_alloc(LOG_POOL, sizeof(*binding)))) {
251  return SWITCH_STATUS_MEMERR;
252  }
253 
254  if ((uint8_t) level > MAX_LEVEL) {
255  MAX_LEVEL = level;
256  }
257 
258  binding->function = function;
259  binding->level = level;
260  binding->is_console = is_console;
261 
263  for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next);
264 
265  if (ptr) {
266  ptr->next = binding;
267  } else {
268  BINDINGS = binding;
269  }
270  if (is_console) {
272  }
273  mods_loaded++;
275 
276  return SWITCH_STATUS_SUCCESS;
277 }
static int console_mods_loaded
Definition: switch_log.c:67
static uint8_t MAX_LEVEL
Definition: switch_log.c:65
switch_log_function_t function
Definition: switch_log.c:49
static switch_memory_pool_t * LOG_POOL
Definition: switch_log.c:57
struct switch_log_binding * next
Definition: switch_log.c:52
static int mods_loaded
Definition: switch_log.c:66
static switch_log_binding_t * BINDINGS
Definition: switch_log.c:58
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
static switch_mutex_t * BINDLOCK
Definition: switch_log.c:59
switch_log_level_t level
Definition: switch_log.c:50
#define switch_assert(expr)
switch_status_t switch_log_init ( switch_memory_pool_t pool,
switch_bool_t  colorize 
)

Definition at line 506 of file switch_log.c.

References BINDLOCK, COLORIZE, LOG_POOL, LOG_QUEUE, log_thread(), pool, switch_assert, switch_cond_next(), switch_core_get_console(), SWITCH_CORE_QUEUE_LEN, switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_queue_create(), SWITCH_STATUS_SUCCESS, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_stacksize_set(), SWITCH_TRUE, thread, and THREAD_RUNNING.

507 {
508  switch_threadattr_t *thd_attr;;
509 
510  switch_assert(pool != NULL);
511 
512  LOG_POOL = pool;
513 
515 
517 #ifdef SWITCH_LOG_RECYCLE
518  switch_queue_create(&LOG_RECYCLE_QUEUE, SWITCH_CORE_QUEUE_LEN, LOG_POOL);
519 #endif
522  switch_thread_create(&thread, thd_attr, log_thread, NULL, LOG_POOL);
523 
524  while (!THREAD_RUNNING) {
526  }
527 
528  if (colorize) {
529 #ifdef WIN32
530  hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
531  if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
532  wOldColorAttrs = csbiInfo.wAttributes;
534  }
535 #else
537 #endif
538  }
539 
540 
541  return SWITCH_STATUS_SUCCESS;
542 }
static switch_memory_pool_t * LOG_POOL
Definition: switch_log.c:57
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
switch_memory_pool_t * pool
static switch_thread_t * thread
Definition: switch_log.c:279
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t *t, void *obj)
Definition: switch_log.c:281
#define SWITCH_CORE_QUEUE_LEN
Definition: switch_types.h:560
static switch_queue_t * LOG_QUEUE
Definition: switch_log.c:60
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:551
static int8_t THREAD_RUNNING
Definition: switch_log.c:64
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
void switch_cond_next(void)
Definition: switch_time.c:638
static switch_bool_t COLORIZE
Definition: switch_log.c:68
static switch_mutex_t * BINDLOCK
Definition: switch_log.c:59
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:642
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:675
FILE * switch_core_get_console(void)
Get the output console.
Definition: switch_core.c:230
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1109
#define switch_assert(expr)
const char* switch_log_level2str ( switch_log_level_t  level)

Definition at line 149 of file switch_log.c.

References switch_log_binding::level, LEVELS, and SWITCH_LOG_DEBUG.

Referenced by switch_log_vprintf().

150 {
151  if (level > SWITCH_LOG_DEBUG) {
152  level = SWITCH_LOG_DEBUG;
153  }
154  return LEVELS[level];
155 }
static const char * LEVELS[]
Definition: switch_log.c:36
static switch_log_node_t* switch_log_node_alloc ( )
static

Definition at line 88 of file switch_log.c.

References switch_assert, switch_queue_trypop(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_log_node_dup(), and switch_log_vprintf().

89 {
90  switch_log_node_t *node = NULL;
91 #ifdef SWITCH_LOG_RECYCLE
92  void *pop = NULL;
93 
94  if (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
95  node = (switch_log_node_t *) pop;
96  } else {
97 #endif
98  node = malloc(sizeof(*node));
99  switch_assert(node);
100 #ifdef SWITCH_LOG_RECYCLE
101  }
102 #endif
103  return node;
104 }
Log Data.
Definition: switch_log.h:49
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
#define switch_assert(expr)
void switch_log_printf ( switch_text_channel_t  channel,
const char *  file,
const char *  func,
int  line,
const char *  userdata,
switch_log_level_t  level,
const char *  fmt,
  ... 
)

Definition at line 321 of file switch_log.c.

References switch_log_vprintf().

Referenced by log_thread(), and switch_core_memory_reclaim_logger().

323 {
324  va_list ap;
325 
326  va_start(ap, fmt);
327  switch_log_vprintf(channel, file, func, line, userdata, level, fmt, ap);
328  va_end(ap);
329 }
void switch_log_vprintf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, const char *fmt, va_list ap)
Definition: switch_log.c:332
switch_log_level_t switch_log_str2level ( const char *  str)

Definition at line 186 of file switch_log.c.

References switch_log_binding::level, LEVELS, switch_is_number(), and SWITCH_LOG_INVALID.

Referenced by switch_log_str2mask().

187 {
188  int x = 0;
190 
191  if (switch_is_number(str)) {
192  x = atoi(str);
193 
194  if (x > SWITCH_LOG_INVALID) {
195  return SWITCH_LOG_INVALID - 1;
196  } else if (x < 0) {
197  return 0;
198  } else {
199  return x;
200  }
201  }
202 
203 
204  for (x = 0;; x++) {
205  if (!LEVELS[x]) {
206  break;
207  }
208 
209  if (!strcasecmp(LEVELS[x], str)) {
210  level = (switch_log_level_t) x;
211  break;
212  }
213  }
214 
215  return level;
216 }
switch_bool_t switch_is_number(const char *str)
static const char * LEVELS[]
Definition: switch_log.c:36
switch_log_level_t
Log Level Enumeration.
uint32_t switch_log_str2mask ( const char *  str)

Definition at line 157 of file switch_log.c.

References switch_log_binding::level, switch_assert, SWITCH_LOG_INVALID, switch_log_str2level(), and switch_separate_string().

158 {
159  int argc = 0, x = 0;
160  char *argv[10] = { 0 };
161  uint32_t mask = 0;
162  char *p = strdup(str);
163  switch_log_level_t level;
164 
165  switch_assert(p);
166 
167  if ((argc = switch_separate_string(p, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
168  for (x = 0; x < argc && argv[x]; x++) {
169  if (!strcasecmp(argv[x], "all")) {
170  mask = 0xFF;
171  break;
172  } else {
173  level = switch_log_str2level(argv[x]);
174  if (level != SWITCH_LOG_INVALID) {
175  mask |= (1 << level);
176  }
177  }
178  }
179  }
180 
181  free(p);
182 
183  return mask;
184 }
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
switch_log_level_t switch_log_str2level(const char *str)
Definition: switch_log.c:186
#define switch_assert(expr)
switch_log_level_t
Log Level Enumeration.
switch_status_t switch_log_unbind_logger ( switch_log_function_t  function)

Definition at line 218 of file switch_log.c.

References BINDLOCK, console_mods_loaded, switch_log_binding::function, switch_log_binding::is_console, mods_loaded, switch_log_binding::next, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

219 {
220  switch_log_binding_t *ptr = NULL, *last = NULL;
222 
224  for (ptr = BINDINGS; ptr; ptr = ptr->next) {
225  if (ptr->function == function) {
226  if (last) {
227  last->next = ptr->next;
228  } else {
229  BINDINGS = ptr->next;
230  }
231  status = SWITCH_STATUS_SUCCESS;
232  mods_loaded--;
233  if (ptr->is_console) {
235  }
236  break;
237  }
238  last = ptr;
239  }
241 
242  return status;
243 }
static int console_mods_loaded
Definition: switch_log.c:67
switch_log_function_t function
Definition: switch_log.c:49
struct switch_log_binding * next
Definition: switch_log.c:52
static int mods_loaded
Definition: switch_log.c:66
static switch_log_binding_t * BINDINGS
Definition: switch_log.c:58
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static switch_mutex_t * BINDLOCK
Definition: switch_log.c:59
switch_status_t
Common return values.
void switch_log_vprintf ( switch_text_channel_t  channel,
const char *  file,
const char *  func,
int  line,
const char *  userdata,
switch_log_level_t  level,
const char *  fmt,
va_list  ap 
)

Definition at line 332 of file switch_log.c.

References switch_log_node_t::channel, COLORIZE, COLORS, console_mods_loaded, switch_log_node_t::content, switch_log_node_t::data, switch_runtime::debug_level, do_mods, switch_log_node_t::file, switch_log_node_t::func, switch_runtime::hard_log_level, switch_log_node_t::level, switch_log_node_t::line, LOG_QUEUE, switch_core_session::loglevel, MAX_LEVEL, memset(), runtime, switch_log_node_t::slevel, switch_assert, SWITCH_CHANNEL_ID_EVENT, SWITCH_CHANNEL_ID_LOG_CLEAN, SWITCH_CHANNEL_ID_SESSION, switch_core_data_channel(), switch_core_session_get_uuid(), switch_cut_path(), switch_event_add_header(), switch_event_add_header_string(), switch_event_create, switch_event_fire, SWITCH_EVENT_LOG, switch_event_running(), SWITCH_LOG_INVALID, switch_log_level2str(), switch_log_node_alloc(), switch_log_node_free(), SWITCH_LOG_UNINIT, switch_micro_time_now(), switch_queue_trypush(), switch_safe_free, SWITCH_SEQ_DEFAULT_COLOR, switch_set_string, switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, switch_time_exp_lt(), switch_vasprintf(), switch_log_node_t::timestamp, switch_time_exp_t::tm_hour, switch_time_exp_t::tm_mday, switch_time_exp_t::tm_min, switch_time_exp_t::tm_mon, switch_time_exp_t::tm_sec, switch_time_exp_t::tm_usec, switch_time_exp_t::tm_year, switch_log_node_t::userdata, and zstr.

Referenced by switch_log_printf().

334 {
335  char *data = NULL;
336  char *new_fmt = NULL;
337  int ret = 0;
338  FILE *handle;
339  const char *filep = (file ? switch_cut_path(file) : "");
340  const char *funcp = (func ? func : "");
341  char *content = NULL;
343  uint32_t len;
344 #ifdef SWITCH_FUNC_IN_LOG
345  const char *extra_fmt = "%s [%s] %s:%d %s()%c%s";
346 #else
347  const char *extra_fmt = "%s [%s] %s:%d%c%s";
348 #endif
350  switch_log_level_t special_level = SWITCH_LOG_UNINIT;
351 
352  if (channel == SWITCH_CHANNEL_ID_SESSION && userdata) {
354  special_level = session->loglevel;
355  if (limit_level < session->loglevel) {
356  limit_level = session->loglevel;
357  }
358  }
359 
360  if (level > 100) {
361  if ((uint32_t) (level - 100) > runtime.debug_level) {
362  return;
363  }
364 
365  level = 1;
366  }
367 
368  if (level > limit_level) {
369  return;
370  }
371 
373 
374  handle = switch_core_data_channel(channel);
375 
376  if (channel != SWITCH_CHANNEL_ID_LOG_CLEAN) {
377  char date[80] = "";
378  //switch_size_t retsize;
380 
381  switch_time_exp_lt(&tm, now);
382  switch_snprintf(date, sizeof(date), "%0.4d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d.%0.6d",
383  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec);
384 
385  //switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
386 
387 #ifdef SWITCH_FUNC_IN_LOG
388  len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
389 #else
390  len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(fmt));
391 #endif
392  new_fmt = malloc(len + 1);
393  switch_assert(new_fmt);
394 #ifdef SWITCH_FUNC_IN_LOG
395  switch_snprintf(new_fmt, len, extra_fmt, date, switch_log_level2str(level), filep, line, funcp, 128, fmt);
396 #else
397  switch_snprintf(new_fmt, len, extra_fmt, date, switch_log_level2str(level), filep, line, 128, fmt);
398 #endif
399 
400  fmt = new_fmt;
401  }
402 
403  ret = switch_vasprintf(&data, fmt, ap);
404 
405  if (ret == -1) {
406  fprintf(stderr, "Memory Error\n");
407  goto end;
408  }
409 
410  if (channel == SWITCH_CHANNEL_ID_LOG_CLEAN) {
411  content = data;
412  } else {
413  if ((content = strchr(data, 128))) {
414  *content = ' ';
415  }
416  }
417 
418  if (channel == SWITCH_CHANNEL_ID_EVENT) {
419  switch_event_t *event;
421  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Log-Data", data);
422  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Log-File", filep);
423  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Log-Function", funcp);
424  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
425  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Level", "%d", (int) level);
426  if (!zstr(userdata)) {
427  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "User-Data", userdata);
428  }
429  switch_event_fire(&event);
430  data = NULL;
431  }
432 
433  goto end;
434  }
435 
436  if (console_mods_loaded == 0 || !do_mods) {
437  if (handle) {
438  int aok = 1;
439 #ifndef WIN32
440 
441  fd_set can_write;
442  int fd;
443  struct timeval to;
444 
445  fd = fileno(handle);
446  memset(&to, 0, sizeof(to));
447  FD_ZERO(&can_write);
448  FD_SET(fd, &can_write);
449  to.tv_sec = 0;
450  to.tv_usec = 100000;
451  if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) {
452  aok = FD_ISSET(fd, &can_write);
453  } else {
454  aok = 0;
455  }
456 #endif
457  if (aok) {
458  if (COLORIZE) {
459 
460 #ifdef WIN32
461  SetConsoleTextAttribute(hStdout, COLORS[level]);
462  WriteFile(hStdout, data, (DWORD) strlen(data), NULL, NULL);
463  SetConsoleTextAttribute(hStdout, wOldColorAttrs);
464 #else
465  fprintf(handle, "%s%s%s", COLORS[level], data, SWITCH_SEQ_DEFAULT_COLOR);
466 #endif
467  } else {
468  fprintf(handle, "%s", data);
469  }
470  }
471  }
472  }
473 
474  if (do_mods && level <= MAX_LEVEL) {
476 
477  node->data = data;
478  data = NULL;
479  switch_set_string(node->file, filep);
480  switch_set_string(node->func, funcp);
481  node->line = line;
482  node->level = level;
483  node->slevel = special_level;
484  node->content = content;
485  node->timestamp = now;
486  node->channel = channel;
487  if (channel == SWITCH_CHANNEL_ID_SESSION) {
488  switch_core_session_t *session = (switch_core_session_t *) userdata;
489  node->userdata = userdata ? strdup(switch_core_session_get_uuid(session)) : NULL;
490  } else {
491  node->userdata = !zstr(userdata) ? strdup(userdata) : NULL;
492  }
493 
495  switch_log_node_free(&node);
496  }
497  }
498 
499  end:
500 
501  switch_safe_free(data);
502  switch_safe_free(new_fmt);
503 
504 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
switch_xml_t switch_status_t switch_event_running(void)
Determine if the event system has been initialized.
Definition: switch_event.c:417
switch_log_level_t level
Definition: switch_log.h:59
static int console_mods_loaded
Definition: switch_log.c:67
Log Data.
Definition: switch_log.h:49
static uint8_t MAX_LEVEL
Definition: switch_log.c:65
#define do_mods
Definition: switch_log.c:331
switch_time_t timestamp
Definition: switch_log.h:61
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
switch_log_level_t slevel
Definition: switch_log.h:67
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:323
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
switch_text_channel_t channel
Definition: switch_log.h:66
int64_t switch_time_t
Definition: switch_apr.h:188
static switch_queue_t * LOG_QUEUE
Definition: switch_log.c:60
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_core_session_t * session
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
int switch_vasprintf(_Out_opt_ char **buf, _In_z_ _Printf_format_string_ const char *format, _In_ va_list ap)
FILE * switch_core_data_channel(switch_text_channel_t channel)
Retrieve a FILE stream of a given text channel name.
Definition: switch_core.c:263
static const char * COLORS[]
Definition: switch_log.c:83
static switch_bool_t COLORIZE
Definition: switch_log.c:68
const char * switch_log_level2str(switch_log_level_t level)
Definition: switch_log.c:149
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
static switch_log_node_t * switch_log_node_alloc()
Definition: switch_log.c:88
switch_log_level_t hard_log_level
#define SWITCH_SEQ_DEFAULT_COLOR
Definition: switch_types.h:69
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:383
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:665
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
void switch_log_node_free(switch_log_node_t **pnode)
Definition: switch_log.c:125
uint32_t debug_level
switch_log_level_t loglevel
#define switch_assert(expr)
const char * switch_cut_path(const char *in)
Create a pointer to the file name in a given file path eliminating the directory name.
memset(buf, 0, buflen)
switch_log_level_t
Log Level Enumeration.

Variable Documentation

switch_log_binding_t* BINDINGS = NULL
static

Definition at line 58 of file switch_log.c.

switch_mutex_t* BINDLOCK = NULL
static
switch_bool_t COLORIZE = SWITCH_FALSE
static

Definition at line 68 of file switch_log.c.

Referenced by switch_log_init(), and switch_log_vprintf().

const char* COLORS[]
static
Initial value:
=
#define SWITCH_SEQ_FMAGEN
Definition: switch_types.h:96
#define SWITCH_SEQ_FYELLOW
Definition: switch_types.h:94
#define SWITCH_SEQ_FCYAN
Definition: switch_types.h:97
#define SWITCH_SEQ_FRED
Definition: switch_types.h:92
#define SWITCH_SEQ_DEFAULT_COLOR
Definition: switch_types.h:69
#define SWITCH_SEQ_FGREEN
Definition: switch_types.h:93

Definition at line 83 of file switch_log.c.

Referenced by switch_log_vprintf().

int console_mods_loaded = 0
static
const char* LEVELS[]
static
Initial value:
= {
"CONSOLE",
"ALERT",
"CRIT",
"ERR",
"WARNING",
"NOTICE",
"INFO",
"DEBUG",
NULL
}

Definition at line 36 of file switch_log.c.

Referenced by switch_log_level2str(), and switch_log_str2level().

switch_memory_pool_t* LOG_POOL = NULL
static

Definition at line 57 of file switch_log.c.

Referenced by switch_log_bind_logger(), and switch_log_init().

switch_queue_t* LOG_QUEUE = NULL
static

Definition at line 60 of file switch_log.c.

Referenced by log_thread(), switch_log_init(), switch_log_shutdown(), and switch_log_vprintf().

uint8_t MAX_LEVEL = 0
static

Definition at line 65 of file switch_log.c.

Referenced by switch_log_bind_logger(), and switch_log_vprintf().

int mods_loaded = 0
static

Definition at line 66 of file switch_log.c.

Referenced by switch_log_bind_logger(), and switch_log_unbind_logger().

switch_thread_t* thread
static
int8_t THREAD_RUNNING = 0
static

Definition at line 64 of file switch_log.c.

Referenced by log_thread(), switch_log_init(), and switch_log_shutdown().