yumapro  20.10-12
YumaPro SDK
log_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
3  *
4  * Unless required by applicable law or agreed to in writing,
5  * software distributed under the License is distributed on an
6  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7  * KIND, either express or implied. See the License for the
8  * specific language governing permissions and limitations
9  * under the License.
10  */
11 #ifndef _H_log_util
12 #define _H_log_util
13 /* FILE: log_util.h
14 *********************************************************************
15 * *
16 * P U R P O S E *
17 * *
18 *********************************************************************/
19 
25 /*********************************************************************
26 * *
27 * C H A N G E H I S T O R Y *
28 * *
29 *********************************************************************
30 
31 date init comment
32 ----------------------------------------------------------------------
33 08-jan-06 abb begun
34 02-jun-2012 mts adapted from log.h
35 */
36 
37 #include <stdio.h>
38 #include <xmlstring.h>
39 
40 #include "procdefs.h"
41 #include "status.h"
42 #include "log.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /********************************************************************
49 * *
50 * C O N S T A N T S *
51 * *
52 *********************************************************************/
53 
54 /*
55  * Update of the internal syslog buffer is based on:
56  *
57  * vsnprintf()
58  *
59  * This primitive expects the content area to be followed by an additional
60  * byte in order to append a NULL terminator to a max size content string.
61  * We in turn add yet another byte to store a well known marker byte in an
62  * attempt to detect errors and aid debugging. (Not rigorous, but better
63  * than nothing.)
64  *
65  * The below defs do this:
66  *
67  */
68 
69 //#define SYSLOG_BUF_CONTENT_SIZE 64 /* For overflow testing */
70 #define SYSLOG_BUF_CONTENT_SIZE 1024 /* Max syslog buffer content size */
71 #define SYSLOG_BUF_NULL_BYTE_SIZE 1 /* Add a byte for a NULL terminator */
72 #define SYSLOG_BUF_MARKER_BYTE_SIZE 1 /* Add a byte for a well known marker */
73 
74 #define SYSLOG_BUF_TOTAL_SIZE (SYSLOG_BUF_CONTENT_SIZE + \
75  SYSLOG_BUF_NULL_BYTE_SIZE + \
76  SYSLOG_BUF_MARKER_BYTE_SIZE)
77 
78 #define SYSLOG_BUF_NULL_BYTE_INDEX (SYSLOG_BUF_CONTENT_SIZE + \
79  SYSLOG_BUF_NULL_BYTE_SIZE - 1)
80 
81 #define SYSLOG_BUF_MARKER_BYTE_INDEX (SYSLOG_BUF_CONTENT_SIZE + \
82  SYSLOG_BUF_NULL_BYTE_SIZE + \
83  SYSLOG_BUF_MARKER_BYTE_SIZE - 1)
84 
85 #define LOG_PRIO_NONE -1
86 
87 /********************************************************************
88 * *
89 * T Y P E S *
90 * *
91 *********************************************************************/
92 
93 
101 typedef struct syslog_msg_desc_t_ {
102  uint idid;
103  char *start;
104  char *end;
105  char *ptr;
106  uint32 len;
107  int32 remaining;
108  boolean initialized;
109  boolean was_append;
110  boolean first_time;
111  boolean write_pending;
112  log_debug_app_t app;
113  log_debug_t level;
114  log_debug_t sub_level;
115  char buf[SYSLOG_BUF_TOTAL_SIZE];
116 } syslog_msg_desc_t;
117 
118 
119 /********************************************************************
120 * *
121 * F U N C T I O N S *
122 * *
123 *********************************************************************/
124 
125 
131 extern void
132  log_util_init_buf (syslog_msg_desc_t *dp);
133 
134 
140 extern void
141  log_util_flush (syslog_msg_desc_t *desc);
142 
143 
156 extern void
157  log_util_logbuf_common (syslog_msg_desc_t *desc,
158  log_debug_app_t app,
159  log_debug_t level,
160  log_debug_t sub_level,
161  const char *fstr,
162  va_list args);
163 
164 
177 extern void
178  log_util_logbuf_append (syslog_msg_desc_t *desc,
179  log_debug_app_t app,
180  log_debug_t level,
181  log_debug_t sub_level,
182  const char *fstr,
183  va_list args);
184 
185 
189 #ifdef __cplusplus
190 } /* end extern 'C' */
191 #endif
192 
193 #endif /* _H_log_util */
syslog_msg_desc_t_::initialized
boolean initialized
initialization done
Definition: log_util.h:108
tstamp.h
Timestamp utilities.
syslog_msg_desc_t_::idid
uint idid
internal idid field
Definition: log_util.h:102
LOG_DEBUG_NONE
@ LOG_DEBUG_NONE
value not set or error
Definition: log.h:386
xml_util.h
XML Utilities.
syslog_msg_desc_t_::write_pending
boolean write_pending
internal write pending
Definition: log_util.h:111
ncxconst.h
Contains NCX constants.
log_util_logbuf_common
void log_util_logbuf_common(syslog_msg_desc_t *desc, log_debug_app_t app, log_debug_t level, log_debug_t sub_level, const char *fstr, va_list args)
Send formatted string output to an internal log buffer.
Definition: log_util.c:549
log_util_init_buf
void log_util_init_buf(syslog_msg_desc_t *dp)
Initialize the contents of an internal log buffer descriptor.
Definition: log_util.c:88
ses_id_t
uint32 ses_id_t
Session ID.
Definition: ses.h:306
syslog_msg_desc_t_::buf
char buf[SYSLOG_BUF_TOTAL_SIZE]
buffer to use
Definition: log_util.h:115
syslog_msg_desc_t_::start
char * start
start of message
Definition: log_util.h:103
syslog_msg_desc_t_::app
log_debug_app_t app
app to use in message
Definition: log_util.h:112
syslog_msg_desc_t_::remaining
int32 remaining
remaining to write
Definition: log_util.h:107
syslog_msg_desc_t_::len
uint32 len
message len
Definition: log_util.h:106
syslog_msg_desc_t_::level
log_debug_t level
debug level to use
Definition: log_util.h:113
syslog_msg_desc_t_::ptr
char * ptr
internal message pointer
Definition: log_util.h:105
syslog_msg_desc_t_::sub_level
log_debug_t sub_level
sub-level to use
Definition: log_util.h:114
ncx_netconfd_running
boolean ncx_netconfd_running(void)
Check if netconfd running.
Definition: ncx.c:11805
log.h
NCX System Logging Manager.
syslog_msg_desc_t_::first_time
boolean first_time
first callflag
Definition: log_util.h:110
syslog_msg_desc_t_
Syslog/Vendor Message Buffer descriptor.
Definition: log_util.h:101
syslog_msg_desc_t_::was_append
boolean was_append
was appended flag
Definition: log_util.h:109
thd.h
Thread support (for now limited to netconfd)
syslog_msg_desc_t_::end
char * end
end of message
Definition: log_util.h:104
ncx.h
YANG module utility functions.
log_util_logbuf_append
void log_util_logbuf_append(syslog_msg_desc_t *desc, log_debug_app_t app, log_debug_t level, log_debug_t sub_level, const char *fstr, va_list args)
Append formatted string output to an internal log buffer.
Definition: log_util.c:588
thd_get_ids
void thd_get_ids(int *tid, ses_id_t *sid)
Return the TID and SID of the current running thread.
Definition: thd.c:1021
log_util_flush
void log_util_flush(syslog_msg_desc_t *desc)
Flush contents of internal buffer to external logging system.
Definition: log_util.c:525
log_util.h
Internal SYSLOG Logging support.
status.h
Global error messages for status code enumerations.