Commit e41202c0 authored by hardy's avatar hardy

Merge remote-tracking branch 'origin/nfapi-carriage-returns' into integration_2021_wk47_b

parents c98e9e9a bcf1ac0c
/* /*
* Copyright 2017 Cisco Systems, Inc. * Copyright 2017 Cisco Systems, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <stdio.h>
#include <stdio.h> #include <stdarg.h>
#include <stdarg.h> #include <stdint.h>
#include <stdint.h> #include <stdlib.h>
#include <stdlib.h> #include <string.h>
#include <string.h> #include <unistd.h>
#include <unistd.h> #include <errno.h>
#include <errno.h> #include <sys/time.h>
#include <sys/time.h> #include <sys/types.h>
#include <sys/types.h> #include <pthread.h>
#include <pthread.h> #include <syslog.h>
#include <syslog.h>
#include <debug.h>
#include <debug.h>
#define MAX_MSG_LENGTH 2096
#define MAX_MSG_LENGTH 2096 #define TRACE_HEADER_LENGTH 44
#define TRACE_HEADER_LENGTH 44
void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...);
void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...);
// initialize the trace function to 0
// initialize the trace function to 0 void (*nfapi_trace_g)(nfapi_trace_level_t level, const char* format, ...) = &nfapi_trace_dbg;
void (*nfapi_trace_g)(nfapi_trace_level_t level, const char* format, ...) = &nfapi_trace_dbg;
nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_INFO;
nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_INFO; //nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_WARN;
//nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_WARN;
void nfapi_set_trace_level(nfapi_trace_level_t new_level)
void nfapi_set_trace_level(nfapi_trace_level_t new_level) {
{ nfapi_trace_level_g = new_level;
nfapi_trace_level_g = new_level; }
}
void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...)
void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...) {
{ char trace_buff[MAX_MSG_LENGTH + TRACE_HEADER_LENGTH];
char trace_buff[MAX_MSG_LENGTH + TRACE_HEADER_LENGTH]; uint32_t num_chars;
uint32_t num_chars; va_list p_args;
va_list p_args; struct timeval tv;
struct timeval tv; pthread_t tid = pthread_self();
pthread_t tid = pthread_self();
(void)gettimeofday(&tv, NULL);
(void)gettimeofday(&tv, NULL);
num_chars = (uint32_t)snprintf(trace_buff, TRACE_HEADER_LENGTH, "%04u.%06u: 0x%02x: %10u: ", ((uint32_t)tv.tv_sec) & 0x1FFF, (uint32_t)tv.tv_usec, (uint32_t)level, (uint32_t)tid);
num_chars = (uint32_t)snprintf(trace_buff, TRACE_HEADER_LENGTH, "%04u.%06u: 0x%02x: %10u: ", ((uint32_t)tv.tv_sec) & 0x1FFF, (uint32_t)tv.tv_usec, (uint32_t)level, (uint32_t)tid);
if (num_chars > TRACE_HEADER_LENGTH)
if (num_chars > TRACE_HEADER_LENGTH) {
{ printf("trace_dbg: Error, num_chars is too large: %d", num_chars);
printf("trace_dbg: Error, num_chars is too large: %d", num_chars); return;
return; }
}
va_start(p_args, format);
va_start(p_args, format); if ((num_chars = (uint32_t)vsnprintf(&trace_buff[num_chars], MAX_MSG_LENGTH, format, p_args)))
if ((num_chars = (uint32_t)vsnprintf(&trace_buff[num_chars], MAX_MSG_LENGTH, format, p_args))) {
{ if (level <= NFAPI_TRACE_WARN)
if (level <= NFAPI_TRACE_WARN) {
{ printf("%s", trace_buff);
printf("%s", trace_buff); }
} printf("%s", trace_buff);
printf("%s", trace_buff); }
} va_end(p_args);
va_end(p_args); }
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment