62 #ifdef SWITCH_LOG_RECYCLE 74 static HANDLE hStdout;
75 static WORD wOldColorAttrs;
76 static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
95 char *full_message = node->
content;
96 char *parsed_full_message = NULL;
97 char *field_name = NULL;
101 if (node->
meta && cJSON_IsObject(node->
meta)) {
104 json = cJSON_CreateObject();
105 for (field = node->
meta->
child; field; field = field->
next) {
108 cJSON_AddItemToObject(json, field_name, cJSON_Duplicate(field,
cJSON_True));
116 json = cJSON_CreateObject();
124 cJSON_AddItemToObject(json, json_format->
host.
name, cJSON_CreateString(json_format->
host.
value));
126 cJSON_AddItemToObject(json, json_format->
host.
name, cJSON_CreateString(hostname));
128 cJSON_AddItemToObject(json, json_format->
host.
name, cJSON_CreateString(hostname));
136 cJSON_AddItemToObject(json, json_format->
timestamp.
name, cJSON_CreateNumber(timestamp));
139 cJSON_AddItemToObject(json, json_format->
level.
name, cJSON_CreateNumber(log_level));
143 cJSON_AddItemToObject(json, json_format->
ident.
name, cJSON_CreateString(json_format->
ident.
value));
145 cJSON_AddItemToObject(json, json_format->
ident.
name, cJSON_CreateString(
"freeswitch"));
150 cJSON_AddItemToObject(json, json_format->
pid.
name, cJSON_CreateNumber(atoi(json_format->
pid.
value)));
152 cJSON_AddItemToObject(json, json_format->
pid.
name, cJSON_CreateNumber((
int)getpid()));
156 cJSON_AddItemToObject(json, json_format->
uuid.
name, cJSON_CreateString(node->
userdata));
159 cJSON_AddItemToObject(json, json_format->
file.
name, cJSON_CreateString(node->
file));
161 cJSON_AddItemToObject(json, json_format->
line.
name, cJSON_CreateNumber(node->
line));
165 cJSON_AddItemToObject(json, json_format->
function.
name, cJSON_CreateString(node->
func));
172 if (*full_message ==
' ') {
175 if (*full_message ==
'\n') {
204 if (strncmp(full_message,
"LOG_FIELDS", 10) == 0) {
206 full_message = parsed_full_message;
213 for (hp = log_fields->
headers; hp; hp = hp->
next) {
215 if (strncmp(hp->
name,
"@#", 2) == 0) {
217 cJSON_AddItemToObject(json, field_name, cJSON_CreateNumber(strtod(hp->
value, NULL)));
220 cJSON_AddItemToObject(json, field_name, cJSON_CreateString(hp->
value));
229 cJSON_AddItemToObject(json, json_format->
full_message.
name, cJSON_CreateString(full_message));
231 cJSON_AddItemToObject(json,
"message", cJSON_CreateString(full_message));
235 char short_message[151];
236 char *short_message_end = NULL;
237 switch_snprintf(short_message,
sizeof(short_message) - 1,
"%s", full_message);
238 if ((short_message_end = strchr(short_message,
'\n'))) {
239 *short_message_end =
'\0';
241 cJSON_AddItemToObject(json, json_format->
short_message.
name, cJSON_CreateString(short_message));
252 #ifdef SWITCH_LOG_RECYCLE 259 node = malloc(
sizeof(*node));
261 #ifdef SWITCH_LOG_RECYCLE 317 cJSON_Delete(node->
meta);
320 #ifdef SWITCH_LOG_RECYCLE 366 char *argv[10] = { 0 };
368 char *p = strdup(str);
374 for (x = 0; x < argc && argv[x]; x++) {
375 if (!strcasecmp(argv[x],
"all")) {
416 if (!strcasecmp(
LEVELS[x], str)) {
431 for (ptr = BINDINGS; ptr; ptr = ptr->
next) {
434 last->next = ptr->
next;
436 BINDINGS = ptr->
next;
470 for (ptr = BINDINGS; ptr && ptr->
next; ptr = ptr->
next);
513 for (binding = BINDINGS; binding; binding = binding->
next) {
548 #define do_mods (LOG_QUEUE && THREAD_RUNNING) 557 cJSON *log_meta = NULL;
559 char *new_fmt = NULL;
563 const char *funcp = (func ? func :
"");
564 char *content = NULL;
567 #ifdef SWITCH_FUNC_IN_LOG 568 const char *extra_fmt =
"%s [%s] %s:%d %s()%c%s";
570 const char *extra_fmt =
"%s [%s] %s:%d%c%s";
587 if (limit_level < session->loglevel) {
600 if (level > limit_level) {
614 switch_snprintf(date,
sizeof(date),
"%0.4d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d.%0.6d %0.2f%%%%",
619 #ifdef SWITCH_FUNC_IN_LOG 620 len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
622 len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(fmt));
624 new_fmt = malloc(len + 1);
626 #ifdef SWITCH_FUNC_IN_LOG 638 fprintf(stderr,
"Memory Error\n");
645 if ((content = strchr(data, 128))) {
658 if (!
zstr(userdata)) {
678 memset(&to, 0,
sizeof(to));
680 FD_SET(fd, &can_write);
683 if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) {
684 aok = FD_ISSET(fd, &can_write);
693 SetConsoleTextAttribute(hStdout,
COLORS[level]);
694 WriteFile(hStdout, data, (DWORD) strlen(data), NULL, NULL);
695 SetConsoleTextAttribute(hStdout, wOldColorAttrs);
700 fprintf(handle,
"%s", data);
715 node->
slevel = special_level;
720 node->
meta = log_meta;
729 node->
userdata = !
zstr(userdata) ? strdup(userdata) : NULL;
739 cJSON_Delete(log_meta);
756 #ifdef SWITCH_LOG_RECYCLE 769 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
770 if (
switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
771 wOldColorAttrs = csbiInfo.wAttributes;
785 #ifdef SWITCH_LOG_RECYCLE
switch_log_json_format_item_t sequence
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_json_format_item_t version
switch_log_function_t function
static switch_memory_pool_t * LOG_POOL
switch_status_t switch_event_create_brackets(char *data, char a, char b, char c, switch_event_t **event, char **new_data, switch_bool_t dup)
#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)
void switch_log_meta_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, cJSON **meta, const char *fmt,...)
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)
static int64_t log_sequence
switch_log_json_format_item_t pid
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
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)
switch_log_json_format_item_t timestamp
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)
switch_status_t switch_event_dup(switch_event_t **event, switch_event_t *todup)
Duplicate an event.
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_log_json_format_item_t ident
#define SWITCH_SEQ_FYELLOW
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
#define SWITCH_MUTEX_NESTED
switch_log_json_format_item_t line
void switch_log_meta_vprintf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, cJSON **meta, const char *fmt, va_list ap)
uint32_t switch_log_str2mask(const char *str)
double switch_core_idle_cpu(void)
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 int switch_log_to_mask(switch_log_level_t level)
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_channel_get_variable(_c, _v)
#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_log_json_format_item_t uuid
switch_log_level_t slevel
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
switch_status_t(* switch_log_function_t)(const switch_log_node_t *node, switch_log_level_t level)
switch_log_json_format_item_t full_message
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)
char * switch_core_get_variable(_In_z_ const char *varname)
Retrieve a global variable from the core.
static switch_bool_t COLORIZE
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
const char * switch_log_level2str(switch_log_level_t level)
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
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
struct fspr_thread_mutex_t switch_mutex_t
switch_log_json_format_item_t short_message
static switch_log_node_t * switch_log_node_alloc(void)
switch_status_t switch_log_bind_logger(switch_log_function_t function, switch_log_level_t level, switch_bool_t is_console)
switch_status_t
Common return values.
cJSON * switch_log_node_to_json(const switch_log_node_t *node, int log_level, switch_log_json_format_t *json_format, switch_event_t *chan_vars)
Convert a log node to JSON object. Destroy JSON object when finished.
#define switch_core_session_locate(uuid_str)
Locate a session based on it's uuid.
switch_log_level_t hard_log_level
const char * custom_field_prefix
#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...
switch_log_json_format_item_t level
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)
#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)
switch_status_t switch_log_init(switch_memory_pool_t *pool, switch_bool_t colorize)
switch_log_json_format_item_t host
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)
switch_log_json_format_item_t function
FILE * switch_core_get_console(void)
Get the output console.
struct fspr_pool_t switch_memory_pool_t
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
switch_log_level_t loglevel
void switch_event_destroy(switch_event_t **event)
Destroy an event.
switch_text_channel_t channel
switch_status_t switch_channel_get_log_tags(switch_channel_t *channel, switch_event_t **log_tags)
struct fspr_thread_t switch_thread_t
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_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
switch_log_json_format_item_t file
switch_log_level_t
Log Level Enumeration.
switch_event_header_t * headers