61 #ifdef SWITCH_LOG_RECYCLE
71 static HANDLE hStdout;
72 static WORD wOldColorAttrs;
73 static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
91 #ifdef SWITCH_LOG_RECYCLE
98 node = malloc(
sizeof(*node));
100 #ifdef SWITCH_LOG_RECYCLE
112 if (!
zstr(node->data)) {
113 newnode->
data = strdup(node->data);
117 if (!
zstr(node->userdata)) {
118 newnode->
userdata = strdup(node->userdata);
138 #ifdef SWITCH_LOG_RECYCLE
160 char *argv[10] = { 0 };
162 char *p = strdup(str);
168 for (x = 0; x < argc && argv[x]; x++) {
169 if (!strcasecmp(argv[x],
"all")) {
175 mask |= (1 <<
level);
209 if (!strcasecmp(
LEVELS[x], str)) {
224 for (ptr = BINDINGS; ptr; ptr = ptr->
next) {
227 last->next = ptr->
next;
229 BINDINGS = ptr->
next;
263 for (ptr = BINDINGS; ptr && ptr->
next; ptr = ptr->
next);
305 for (binding = BINDINGS; binding; binding = binding->
next) {
331 #define do_mods (LOG_QUEUE && THREAD_RUNNING)
336 char *new_fmt = NULL;
340 const char *funcp = (func ? func :
"");
341 char *content = NULL;
344 #ifdef SWITCH_FUNC_IN_LOG
345 const char *extra_fmt =
"%s [%s] %s:%d %s()%c%s";
347 const char *extra_fmt =
"%s [%s] %s:%d%c%s";
355 if (limit_level < session->loglevel) {
368 if (level > limit_level) {
382 switch_snprintf(date,
sizeof(date),
"%0.4d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d.%0.6d",
387 #ifdef SWITCH_FUNC_IN_LOG
388 len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
390 len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(fmt));
392 new_fmt = malloc(len + 1);
394 #ifdef SWITCH_FUNC_IN_LOG
406 fprintf(stderr,
"Memory Error\n");
413 if ((content = strchr(data, 128))) {
426 if (!
zstr(userdata)) {
446 memset(&to, 0,
sizeof(to));
448 FD_SET(fd, &can_write);
451 if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) {
452 aok = FD_ISSET(fd, &can_write);
461 SetConsoleTextAttribute(hStdout,
COLORS[level]);
462 WriteFile(hStdout, data, (DWORD) strlen(data), NULL, NULL);
463 SetConsoleTextAttribute(hStdout, wOldColorAttrs);
468 fprintf(handle,
"%s", data);
483 node->
slevel = special_level;
491 node->
userdata = !
zstr(userdata) ? strdup(userdata) : NULL;
517 #ifdef SWITCH_LOG_RECYCLE
530 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
531 if (
switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
532 wOldColorAttrs = csbiInfo.wAttributes;
546 #ifdef SWITCH_LOG_RECYCLE
struct apr_queue_t switch_queue_t
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
unsigned int switch_queue_size(switch_queue_t *queue)
switch_xml_t switch_status_t switch_event_running(void)
Determine if the event system has been initialized.
#define SWITCH_CHANNEL_SESSION_LOG(x)
void switch_core_memory_reclaim_logger(void)
static int console_mods_loaded
switch_text_channel_t
A target to write log/debug info to.
#define SWITCH_CHANNEL_LOG
switch_log_function_t function
static switch_memory_pool_t * LOG_POOL
#define SWITCH_SEQ_FMAGEN
switch_log_node_t * switch_log_node_dup(const switch_log_node_t *node)
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
switch_memory_pool_t * pool
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.
switch_status_t switch_log_unbind_logger(switch_log_function_t function)
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
switch_log_level_t slevel
struct switch_log_binding * next
switch_bool_t switch_is_number(const char *str)
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
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,...)
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
static switch_thread_t * thread
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
static switch_log_binding_t * BINDINGS
switch_text_channel_t channel
#define SWITCH_SEQ_FYELLOW
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
#define SWITCH_MUTEX_NESTED
uint32_t switch_log_str2mask(const char *str)
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.
static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t *t, void *obj)
#define SWITCH_CORE_QUEUE_LEN
static switch_queue_t * LOG_QUEUE
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
#define SWITCH_THREAD_STACKSIZE
static int8_t THREAD_RUNNING
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.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
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.
static const char * LEVELS[]
static const char * COLORS[]
void switch_cond_next(void)
static switch_bool_t COLORIZE
const char * switch_log_level2str(switch_log_level_t level)
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_log_level_t switch_log_str2level(const char *str)
switch_status_t switch_log_shutdown(void)
Shut down the logging engine.
static switch_mutex_t * BINDLOCK
switch_status_t switch_log_bind_logger(switch_log_function_t function, switch_log_level_t level, switch_bool_t is_console)
struct apr_thread_mutex_t switch_mutex_t
switch_status_t
Common return values.
static switch_log_node_t * switch_log_node_alloc()
struct apr_thread_t switch_thread_t
switch_log_level_t hard_log_level
#define SWITCH_SEQ_DEFAULT_COLOR
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
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_function_t)(const switch_log_node_t *node, switch_log_level_t level)
#define SWITCH_SEQ_FGREEN
#define switch_set_string(_dst, _src)
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
void switch_log_node_free(switch_log_node_t **pnode)
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
struct apr_pool_t switch_memory_pool_t
switch_status_t switch_log_init(switch_memory_pool_t *pool, switch_bool_t colorize)
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
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)
FILE * switch_core_get_console(void)
Get the output console.
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
switch_log_level_t loglevel
const char * switch_cut_path(const char *in)
Create a pointer to the file name in a given file path eliminating the directory name.
switch_log_level_t
Log Level Enumeration.