yumapro  23.10T-9
YumaPro SDK
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3 * Copyright (c) 2012 - 2024, YumaWorks, Inc., All Rights Reserved.
4 *
5 * Unless required by applicable law or agreed to in writing,
6 * software distributed under the License is distributed on an
7 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the
9 * specific language governing permissions and limitations
10 * under the License.
11 */
12#ifndef _H_log
13#define _H_log
14/* FILE: log.h
15*********************************************************************
16* *
17* P U R P O S E *
18* *
19*********************************************************************/
20
21
22
30/********************************************************************
31* *
32* C H A N G E H I S T O R Y *
33* *
34*********************************************************************
35
36date init comment
37----------------------------------------------------------------------
3808-jan-06 abb begun
3928may12 mts Logging feature set mods
4014may24 rz YPW-2213: Implement a new audit-log-localtime
41 CLI parameter
42*/
43
44
45
46
47#include <stdio.h>
48#include <xmlstring.h>
49
50#include "procdefs.h"
51#include "status.h"
52
53#ifdef PTHREADS
54#ifndef _H_thd
55#include "thd.h"
56#endif
57#endif
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63/********************************************************************
64* *
65* M A C R O S *
66* *
67*********************************************************************/
68
69#if defined(_XOPEN_SOURCE) || defined(CYGWIN) || defined(MACOSX)
70#define uint uint32
71#endif
72
73
74/*
75 * Log internal errors to stderr. We can't call logger code to
76 * handle its own internal errors.
77 */
78
79/********************************************************************
80* MACRO: LOG_INTERNAL_ERR
81*
82* Output string to stderr reporting error, function name, and line number
83* and resulting action ...
84*
85* EXAMPLE:
86*
87* MACRO: LOG_INTERNAL_ERR(Null buf ptr, RETURN);
88*
89* OUTPUT: ERROR [log_util_init_buf@86]: Null buf ptr - RETURN
90*
91*
92*********************************************************************/
93#define LOG_INTERNAL_ERR(err_str, action) \
94 log_internal_err("\nERROR [%s@%d]: " #err_str " - " #action, \
95 __FUNCTION__, __LINE__)
96
97#define LOG_INTERNAL_LOCK_ERR(name, err_str, hndl, rc, action) \
98 log_internal_lock_err( \
99 "\nERROR [%s@%d]: [" #name "] " #err_str " (%p:%d) - " #action, \
100 __FUNCTION__, __LINE__, (void *)(hndl), rc)
101
102
103/********************************************************************
104* MACRO: LOG_INTERNAL_BUFF_ERR
105*
106* Output string to stderr reporting error, function name, and line number.
107* Dump salient buffer descriptor state, and resulting action ...
108*
109* EXAMPLE:
110*
111* MACRO: LOG_INTERNAL_BUF_ERR(Bad buf, buf, remaining, REINIT);
112*
113* OUTPUT: ERROR [upd_log_buf@179]: Bad buf 'remaining' [ptr=81783a0, \
114* id=4242, start=81783cc, end=81787cc, len=1024(0x400), \
115* remaining=1024(0x400)]->remaining=400 - REINIT \
116*
117*********************************************************************/
118#define LOG_INTERNAL_BUF_ERR(err_str, ptr, action) \
119 log_internal_err("\nERROR [%s@%d]: " #err_str \
120 " [ptr=%p, id=%4x, start=%p, end=%p" \
121 ", len=%u(0x%x), remaining=%d(0x%x)]" \
122 " wp=%u" " - %s\n", __FUNCTION__, __LINE__, \
123 ptr, (ptr)->idid, (ptr)->start, (ptr)->end, \
124 (ptr)->len, (ptr)->len, (ptr)->remaining, (ptr)->remaining, \
125 (uint)(ptr)->write_pending, #action)
126
127
128/********************************************************************
129* *
130* C O N S T A N T S *
131* *
132*********************************************************************/
133#define LOG_CLEANUP_PHASE1 FALSE
134#define LOG_CLEANUP_PHASE2 !LOG_CLEANUP_PHASE1
135
136
137/********************************************************************
138* MACRO FILTER_DEBUG_LEVEL(lvl)
139*
140* Filter log calls at debug_level and syslog_level.
141*
142* Note: For efficiency, looks first at system_debug_level which is defined
143* to be max of (debug_level, syslog_log_level, pthread_log_level).
144* If system_debug_level indicates filtering, then no need to look
145* at context specific debug levels.
146*
147* Note: pthread_log_level only exists in PTHREAD build
148*
149* INPUTS:
150* lvl == debug level to inspect
151*
152* RETURNS:
153* TRUE => filter
154* FALSE => pass
155*********************************************************************/
156#define FILTER_DEBUG_LEVEL(lvl) \
157 ((log_get_system_log_level() < (lvl)) || \
158 ((log_get_log_level() < (lvl)) && \
159 (log_get_syslog_log_level() < (lvl))))
160
161#define ALLOW_DEBUG_LEVEL(lvl) !FILTER_DEBUG_LEVEL(lvl)
162
163#ifdef PTHREADS
164/********************************************************************
165* MACRO FILTER_PTHREAD_DEBUG_LEVEL(lvl)
166*
167* Filter pthread specific log calls at pthread_debug_level
168*
169* Note: For efficiency, looks first at system_debug_level which is defined
170* to be max of (debug_level, syslog_log_level, pthread_log_level).
171* If system_debug_level indicates filtering, then no need to look
172* at context specific debug levels.
173*
174* Note: pthread_log_level only exists in PTHREAD build
175*
176* INPUTS:
177* lvl == debug level to inspect
178*
179* RETURNS:
180* TRUE => filter
181* FALSE => pass
182*********************************************************************/
183#define FILTER_PTHREAD_DEBUG_LEVEL(lvl) \
184 ((log_get_system_log_level() < (lvl)) || \
185 (log_get_pthread_log_level() < (lvl)))
186
187#define ALLOW_PTHREAD_DEBUG_LEVEL(lvl) !FILTER_PTHREAD_DEBUG_LEVEL(lvl)
188#endif
189
190
191// Header only
192
205#define LOGDEV0 (log_get_system_log_level() >= LOG_DEBUG_DEV0)
206
207 // BEGIN ncxlib/log/logmacros
223
224
225
229#define LOGERROR (log_get_system_log_level() >= LOG_DEBUG_ERROR)
230
234#define LOGWARN (log_get_system_log_level() >= LOG_DEBUG_WARN)
235
239#define LOGINFO (log_get_system_log_level() >= LOG_DEBUG_INFO)
240
241
242#define LOGDEV1 (log_get_system_log_level() >= LOG_DEBUG_DEV1)
243
247#define LOGDEBUG (log_get_system_log_level() >= LOG_DEBUG_DEBUG)
248
252#define LOGDEBUG2 (log_get_system_log_level() >= LOG_DEBUG_DEBUG2)
253
257#define LOGDEBUG3 (log_get_system_log_level() >= LOG_DEBUG_DEBUG3)
258
262#define LOGDEBUG4 (log_get_system_log_level() >= LOG_DEBUG_DEBUG4)
263 // END ncxlib/log/logmacros
265
266
267
268/* macros to check pthread debug level only ... improves performance when
269 running without debugs enabled */
270#define LOGDEV1_THD (log_get_pthread_log_level() >= LOG_DEBUG_DEV1)
271#define LOGDBG_THD (log_get_pthread_log_level() >= LOG_DEBUG_DEBUG)
272#define LOGDBG2_THD (log_get_pthread_log_level() >= LOG_DEBUG_DEBUG2)
273#define LOGDBG3_THD (log_get_pthread_log_level() >= LOG_DEBUG_DEBUG3)
274#define LOGDBG4_THD (log_get_pthread_log_level() >= LOG_DEBUG_DEBUG4)
275
276 /* Ultra concise version */
277#define DWRT LOG_DEBUG_WRITE
278#define DEV0 LOG_DEBUG_DEV0
279#define DERR LOG_DEBUG_ERROR
280#define DWARN LOG_DEBUG_WARN
281#define DINFO LOG_DEBUG_INFO
282#define DEV1 LOG_DEBUG_DEV1
283#define DBG LOG_DEBUG_DEBUG
284#define DBG1 LOG_DEBUG_DEBUG
285#define DBG2 LOG_DEBUG_DEBUG2
286#define DBG3 LOG_DEBUG_DEBUG3
287#define DBG4 LOG_DEBUG_DEBUG4
288
289#define LOG_DEBUG_STR_OFF (const xmlChar *)"off"
290#define LOG_DEBUG_STR_WRITE (const xmlChar *)"write" /* "Force" output */
291#define LOG_DEBUG_STR_DEV0 (const xmlChar *)"dev0" /* Special debugging */
292#define LOG_DEBUG_STR_ERROR (const xmlChar *)"error"
293#define LOG_DEBUG_STR_WARN (const xmlChar *)"warn"
294#define LOG_DEBUG_STR_INFO (const xmlChar *)"info"
295#define LOG_DEBUG_STR_DEV1 (const xmlChar *)"dev1" /* Special debugging */
296#define LOG_DEBUG_STR_DEBUG (const xmlChar *)"debug"
297#define LOG_DEBUG_STR_DEBUG2 (const xmlChar *)"debug2"
298#define LOG_DEBUG_STR_DEBUG3 (const xmlChar *)"debug3"
299#define LOG_DEBUG_STR_DEBUG4 (const xmlChar *)"debug4"
300
301/* syslog wants to know what app is calling ... */
302#define LOG_DEBUG_APP_STR_UNKNOWN (const char *)"?yuma?"
303#define LOG_DEBUG_APP_STR_YANGCLI (const char *)"yangcli-pro"
304#define LOG_DEBUG_APP_STR_YANGDUMP (const char *)"yangdump-pro"
305#define LOG_DEBUG_APP_STR_YANGDIFF (const char *)"yangdiff-pro"
306#define LOG_DEBUG_APP_STR_NETCONFD (const char *)"netconfd-pro"
307
308/*
309 * Count to skip backtrace frames that are within the logging code ...
310 * these are usually not interesting or meaningful to the end user.
311 */
312#define FRAME_OVERHEAD_CNT 4
313
314/********************************************************************
315* *
316* T Y P E S *
317* *
318*********************************************************************/
319 // BEGIN ncxlib/log/logtypes
328
329
333typedef enum log_stream_t_ {
340
341
345typedef enum log_debug_t_ {
359
360
364typedef enum log_debug_app_t_ {
365 LOG_DEBUG_APP_NONE,
370 LOG_DEBUG_APP_MAX
372
373 // END ncxlib/log/logtypes
375
376
377
378#define VALID_DEBUG_APP(app) \
379 ((app) > LOG_DEBUG_APP_NONE) && ((app) < LOG_DEBUG_APP_MAX)
380
381#define APP_IS_NETCONFD (log_get_debug_app() == LOG_DEBUG_APP_NETCONFD)
382
383/* logging function template to switch between
384 * log_stdout and log_write
385 */
386typedef void (*logfn_void_t) (void);
387
388/*
389 * Function vectors to switch between native versus syslog (or
390 * vendor-specific) logging.
391 */
392typedef void (*logfn_t) (const char *fstr, ...)
393 __attribute__ ((format (printf, 1, 2)));
394
395
396/*
397 * log_common() and log_xxx_common()
398 */
399typedef void (*logfn_cmn_va_t) (boolean recursive,
400 log_debug_t level, log_debug_t sub_level,
401 const char *fstr, va_list args);
402
403/*
404 * log_append() and log_xxx_append()
405 */
406typedef void (*logfn_app_va_t) (boolean recursive,
407 log_debug_t level, log_debug_t sub_level,
408 const char *fstr, va_list args);
409 /* log_flush() and log_xxx_flush() */
410typedef void (*logfn_flush_t) (void);
411 /* log_xxx_connect() */
412typedef void (*logfn_connect_t) (void);
413 /* log_xxx_send() */
414typedef void (*logfn_send_t) (log_debug_app_t app, log_debug_t level,
415 const char *fstr, ...)
416 __attribute__ ((format (printf, 3, 4)));
417
418
419/* Accessed by log_syslog.c and log_vendor.c */
420extern logfn_connect_t logfn_connect;
421extern logfn_send_t logfn_send;
422
423/********************************************************************
424* *
425* V A R I A B L E S *
426* *
427*********************************************************************/
428
429
430
431/********************************************************************
432* *
433* F U N C T I O N S *
434* *
435*********************************************************************/
436
437/*
438* Enforce logger critical section via logger mutex
439*/
440extern void log_enter_cs ( void );
441
442
443/*
444* Enforce logger critical section via logger mutex
445*/
446extern void log_exit_cs ( void );
447
448 // BEGIN ncxlib/log/logfns
462
463
467extern void disable_default_stdout(void);
468
469
473extern void enable_default_stdout(void);
474
475
476
477
483void
484 log_cleanup ( boolean phase2, boolean debugs );
485
486
487/********************************************************************
488* FUNCTION log_internal_err
489*
490* Send internal logging error info to stderr. This function is called
491* when an error is detected while in the process of trying to send
492* info via the logging stream.
493*
494* See also LOG_INTERNAL_ERR() and LOG_INTERNAL_BUF_ERR macros.
495*
496* INPUTS:
497*
498* fstr == format output string
499* ... == variable argument list
500*
501* RETURNS:
502* None
503*********************************************************************/
504void
505 log_internal_err (const char *fstr, ...)
506 __attribute__ ((format (printf, 1, 2)));
507
508void
509 log_internal_lock_err (const char *fstr, ...)
510 __attribute__ ((format (printf, 1, 2)));
511
512
513/********************************************************************
514* FUNCTIONs log_set_xxx and log_get_xxx
515*
516* Read/write support for the various (binary) --log-xxx config
517* options above. Additional comments inline where noteworthy.
518*
519* INPUTS:
520* None
521*
522* RETURNS:
523* if log_get_xxx(), the requested configured value
524*********************************************************************/
525
526/* Backtrace info level */
527extern boolean
528 log_get_backtrace_detail (void);
529extern void
530 log_set_backtrace_detail (void);
531
532/* --logheader="custom" */
533extern void
534 log_set_custom (void);
535
536/* --log-header="localtime" */
537extern void
538 log_set_localtime (void);
539
540/* --audit-log-localtime=true */
541extern void
542 log_set_audit_localtime (void);
543
544/* --log-mirroring */
545extern void
546 log_set_mirroring (void);
547/* --log-mirroring */
548extern boolean
549 log_get_mirroring (void);
550
551/* --log-stderr */
552extern void
553 log_set_stderr (void);
554
555/* --log-suppress-ctrl */
556extern void
557 log_set_suppress_ctrl (void);
558
559/* --log-syslog --log-vendor */
560extern boolean
561 log_get_syslog_bfr_allocated (void);
562
563extern log_debug_t
564 log_syslog_log_level (void);
565
566/* --log-syslog --log-vendor */
567extern boolean
568 log_get_vendor_bfr_allocated (void);
569
570/* --log-syslog --log-vendor */
571extern void
572 log_set_syslog_bfr_allocated (void);
573
574/* --log-syslog --log-vendor */
575extern void
576 log_set_vendor_bfr_allocated (void);
577
578/* --log-syslog --log-vendor */
579extern void
580 log_clr_syslog_bfr_allocated (void);
581
582/* --log-syslog --log-vendor */
583extern void
584 log_clr_vendor_bfr_allocated (void);
585
586/* --log-syslog */
587extern void log_set_syslog (void);
588extern void log_clr_syslog (void);
589extern boolean log_get_syslog (void);
590
591/* --log-vendor */
592extern void
593 log_set_vendor (void);
594
595/* --log-backtrace-stream="logfile" */
596extern void
597 log_set_backtrace_logfile (void);
598
599/* --log-backtrace-stream="stderr" */
600extern void
601 log_set_backtrace_stderr (void);
602
603/* --log-backtrace-stream="stdout" */
604extern void
605 log_set_backtrace_stdout (void);
606
607/* --log-backtrace-stream="syslog" */
608extern boolean
609 log_get_backtrace_syslog (void);
610extern void
611 log_set_backtrace_syslog (void);
612
613/* --log-backtrace-stream="vendor" */
614extern boolean
615 log_get_backtrace_vendor (void);
616extern void
617 log_set_backtrace_vendor (void);
618
619
620/********************************************************************
621 * FUNCTION log_set_backtrace
622*
623* Set the maximum frame count to report on a backtrace log entry
624* (--log-backtrace=<frame_count>)
625*
626* INPUTS:
627*
628* frame_cnt == the requested frame count (if 0 then use internal default).
629*
630* RETURNS:
631* None
632*
633*********************************************************************/
634extern void
635 log_set_backtrace (uint frame_cnt);
636
637
638/********************************************************************
639* FUNCTIONs log_cvt_debug_level2bit
640*
641* Convert a debug level to a unique bit mask
642*
643* INPUTS:
644*
645* level == debug level enum to convert
646*
647* RETURNS:
648* Unique bit mask
649*
650*********************************************************************/
651extern uint
652 log_cvt_debug_level2bit (log_debug_t level);
653
654
655/********************************************************************
656* FUNCTIONs log_set_backtrace_level and log_clear_backtrace_level
657*
658* Manage the debug level bit mask to allow or restrict
659* reporting of backtrace log entries
660*
661* INPUTS:
662*
663* log_set_backtrace_level: level == debug level for which backtrace
664* log entries will be reported
665*
666* log_clear_backtrace_level: level == debug level for which backtrace
667* log entries should no longer be reported
668*
669*
670* RETURNS:
671* none
672*********************************************************************/
673extern void
674 log_clear_backtrace_level (log_debug_t level);
675
676
677extern void
678 log_set_backtrace_level (log_debug_t level);
679
680
681/********************************************************************
682* FUNCTION log_set_backtrace_level_mask
683*
684* Set the debug level bit mask to restrict reporting of backtrace info
685*
686* INPUTS:
687* mask == bit mask respresenting debug levels for which to append
688* backtrace info
689*
690* RETURNS:
691* none
692*********************************************************************/
693extern void
694 log_set_backtrace_level_mask (uint mask);
695
696
697/********************************************************************
698* FUNCTIONs log_get_backtrace_level_mask
699*
700* Return the debug level bit mask in current use
701*
702* INPUTS:
703* none
704*
705* RETURNS:
706* mask == bit mask respresenting debug levels for which to append
707* backtrace info
708*********************************************************************/
709extern uint
710 log_get_backtrace_level_mask (void);
711
712/********************************************************************
713* FUNCTIONs log_test_backtrace_level
714*
715* Return whether a given debug level is enabled for backtrace
716*
717* INPUTS:
718* level == debug level to test
719*
720* RETURNS:
721* TRUE == backtrace enabled for level
722* FALSE == backtrace disabled for level
723*********************************************************************/
724extern boolean
725 log_test_backtrace_level (log_debug_t level);
726
727
728/********************************************************************
729* FUNCTION log_do_backtrace
730*
731* Return the configured status for including backtrace info on a
732* given output stream (e.g., logfile, syslog, stderr, etc.) at a
733* given content level (e.g., error, warn, info, etc.).
734*
735* NOTE: Slightly funky. To use, pass the current (boolean) value
736* of the config flag to be tested, along with the current
737* content level (sub_level).
738*
739* INPUTS:
740*
741* sub_level == the content level for the log output
742* flag == the --log-backtrace-stream flag to test
743*
744* RETURNS:
745*
746* TRUE == backtrace info should be generated
747* FALSE == backtrace info should NOT be generated
748*
749*********************************************************************/
750extern boolean
751 log_do_backtrace (log_debug_t sub_level, boolean flag);
752
753
769extern status_t
770 log_open (const char *fname,
771 boolean append,
772 boolean tstamps);
773
774
780extern void
781 log_close (void);
782
783
799extern status_t
800 log_audit_open (const char *fname,
801 boolean append,
802 boolean tstamps);
803
804
810extern void
811 log_audit_close (void);
812
813
819extern boolean
820 log_audit_is_open (void);
821
822
833extern status_t
834 log_alt_open (const char *fname);
835
836
849extern status_t
850 log_alt_open_ex (const char *fname,
851 boolean overwrite);
852
853
872extern status_t
873 log_alt_open_force (const char *fname,
874 boolean overwrite,
875 boolean force_mode);
876
877
878
884extern void
885 log_alt_close (void);
886
887
895extern void
896 log_init (void);
897
898
899/********************************************************************
900* FUNCTION log_common
901*
902* Generate "new" message log output, optionally pre-pended with an
903* internal status header (date, time, level, etc). Additional info
904* may be appended (via log_append()) on the same or subsequent lines.
905*
906* INPUTS:
907* recursive == TRUE means this is a recursive callback from print_backtrace()
908* level == internal logger "screening" level
909* sub_level == internal logger functional (content) level
910* fstr == format string in printf format
911* args == any additional arguments for printf
912*
913* KLUDGE ALERT:
914* For convenience we equate the 'recursive' param to a call from
915* print_backtrace(), passing this information unvetted on to
916* log_common_internal(). At present, this works because print_backtrace()
917* is the ONLY routine to pass recursive as TRUE. Someday this may change.
918*
919*********************************************************************/
920extern void
921 log_common (boolean recursive, log_debug_t level, log_debug_t sub_level,
922 const char *fstr, va_list args);
923
924
925/*
926* Append formatted string to the current logger output stream
927*
928* INPUTS:
929* recursive == TRUE means this is a recursive callback from print_backtrace()
930* level == internal logger "screening" level
931* sub_level == internal logger functional (content) level
932* fstr == format string in printf format
933* args == additional arguments for printf
934*
935*********************************************************************/
936extern void
937 log_append (boolean recursive, log_debug_t level, log_debug_t sub_level,
938 const char *fstr, va_list args);
939
940
952extern void
953 log_flush (void);
954
955
956/********************************************************************
957* FUNCTION log_print_backtrace
958*
959* Print up to (array[] size) stack frame addresses
960*
961* INPUT:
962*
963* orig_sub_level == content level
964* localfn_flush == flush call vector function
965* max_detail == include maximum backtrace return information
966* frame_overhead == number of frames in logger code (skip)
967* preamble == prompt string to precede backtrace output
968*
969* RETURNS:
970* none
971*********************************************************************/
972extern void
973 log_print_backtrace (boolean syslog_call,
974 log_debug_t orig_sub_level,
975 logfn_flush_t localfn_flush,
976 boolean max_detail,
977 uint frame_overhead,
978 const char *preamble);
979
980
981/********************************************************************
982* FUNCTION log_capture_backtrace
983*
984* Capture backtrace context for storage and later display. Used by
985* chkheaps.c
986*
987* INPUT:
988* strP == ptr to a ptr to an array of printable strings describing the
989* backtrace represented by bt_arrayP. This memory MUST be
990* returned (via free()) by the caller.
991* bt_arrayP == ptr to a (pre-allocated) buffer of size sufficient
992* to hold max_frames backtrace addresses (void * ptrs).
993* max_frames == max frames to dump, preallocated and described by bt_arrayP
994*
995* RETURNS:
996* none
997*********************************************************************/
998extern uint
999 log_capture_backtrace (char ***strP, void *bt_arrayP, uint max_frames);
1000
1001
1002/********************************************************************
1003* FUNCTION log_backtrace
1004*
1005* Output a string followed by backtrace detail, regardless of
1006* backtrace setting.
1007*
1008* In general, use only for debugging ... should not be present in released
1009* software (though it might be useful for debugging in the field).
1010*
1011* INPUTS:
1012* level == output level
1013* fstr == format string for log message
1014* ... == variable arg list for format string
1015*********************************************************************/
1016extern void
1017 log_backtrace (log_debug_t level, const char *fstr, ...)
1018 __attribute__ ((format (printf, 2, 3)));
1019
1020
1021/********************************************************************
1022* FUNCTION log_stderr_backtrace
1023*
1024* Print up to (array[] size) stack frame addresses but output to STDERR.
1025* This is useful for debugging within logger, e.g., when generating an
1026* error internal to the logging subsystem. (See log_internal_err())
1027*
1028* INPUT:
1029*
1030* max_detail == include maximum backtrace return information
1031* preamble == prompt string to precede backtrace output
1032*
1033* RETURNS:
1034* none
1035*********************************************************************/
1036void
1037 log_stderr_backtrace (boolean max_detail, const char *preamble);
1038
1039
1050extern void
1051 log_stdout (const char *fstr, ...)
1052 __attribute__ ((format (printf, 1, 2)));
1053
1054
1062extern void
1063 log_stdout_level (log_debug_t level, const char *fstr, ...)
1064 __attribute__ ((format (printf, 2, 3)));
1065
1066
1077extern void
1078 log_write (const char *fstr, ...)
1079 __attribute__ ((format (printf, 1, 2)));
1080
1088extern void
1089 log_write_append (const char *fstr, ...)
1090 __attribute__ ((format (printf, 1, 2)));
1091
1092
1093extern void
1094 log_write_filtered (log_debug_t level, const char *fstr, ...)
1095 __attribute__ ((format (printf, 2, 3)));
1096
1097extern void
1098 log_write_filtered_append (log_debug_t level, const char *fstr, ...)
1099 __attribute__ ((format (printf, 2, 3)));
1100
1101extern void
1102 log_write_syslog_level (log_debug_t level, const char *fstr, ...)
1103 __attribute__ ((format (printf, 2, 3)));
1104
1105extern void
1106 log_write_syslog_level_append (log_debug_t level, const char *fstr, ...)
1107 __attribute__ ((format (printf, 2, 3)));
1108
1109
1118extern void
1119 log_audit_write (const char *fstr, ...)
1120 __attribute__ ((format (printf, 1, 2)));
1121
1122
1131extern void
1132 log_audit_write_level (log_debug_t level, const char *fstr, ...)
1133 __attribute__ ((format (printf, 2, 3)));
1134
1135
1136/********************************************************************
1137* FUNCTION log_audit_indent
1138*
1139* Printf a newline to the audit logfile,
1140* then the specified number of space chars
1141*
1142* INPUTS:
1143* indentcnt == number of indent chars, -1 == skip everything
1144*
1145*********************************************************************/
1146extern void
1147 log_audit_indent (int32 indentcnt);
1148
1149extern void
1150 log_audit_indent_level (log_debug_t level, int32 indentcnt);
1151
1152
1159extern void
1160 log_alt_write (const char *fstr, ...)
1161 __attribute__ ((format (printf, 1, 2)));
1162
1163
1171extern void
1172 log_alt_write_level (log_debug_t level, const char *fstr, ...)
1173 __attribute__ ((format (printf, 2, 3)));
1174
1175
1176
1177/********************************************************************
1178* FUNCTION log_alt_indent
1179*
1180* Printf a newline to the alternate logfile,
1181* then the specified number of space chars
1182*
1183* INPUTS:
1184* indentcnt == number of indent chars, -1 == skip everything
1185*
1186*********************************************************************/
1187extern void
1188 log_alt_indent (int32 indentcnt);
1189
1190extern void
1191 log_alt_indent_level (log_debug_t level, int32 indentcnt);
1192
1193
1194/********************************************************************
1195* FUNCTION vlog_error
1196*
1197* Generate a LOG_DEBUG_ERROR log entry
1198*
1199* INPUTS:
1200* fstr == format string in printf format
1201* valist == any additional arguments for printf
1202*
1203*********************************************************************/
1204void
1205 vlog_error (const char *fstr, va_list args );
1206
1207
1220extern void
1221 log_error (const char *fstr, ...)
1222 __attribute__ ((format (printf, 1, 2)));
1223
1224
1232extern void
1233 log_error_append (const char *fstr, ...)
1234 __attribute__ ((format (printf, 1, 2)));
1235
1236
1244extern void
1245 log_warn (const char *fstr, ...)
1246 __attribute__ ((format (printf, 1, 2)));
1247
1248
1256extern void
1257 log_warn_append (const char *fstr, ...)
1258 __attribute__ ((format (printf, 1, 2)));
1259
1260
1268extern void
1269 log_info (const char *fstr, ...)
1270 __attribute__ ((format (printf, 1, 2)));
1271
1272
1280extern void
1281 log_info_append (const char *fstr, ...)
1282 __attribute__ ((format (printf, 1, 2)));
1283
1284
1292extern void
1293 log_debug (const char *fstr, ...)
1294 __attribute__ ((format (printf, 1, 2)));
1295
1296
1304extern void
1305 log_debug_append (const char *fstr, ...)
1306 __attribute__ ((format (printf, 1, 2)));
1307
1308
1316extern void
1317 log_debug2 (const char *fstr, ...)
1318 __attribute__ ((format (printf, 1, 2)));
1319
1320
1328extern void
1329 log_debug2_append (const char *fstr, ...)
1330 __attribute__ ((format (printf, 1, 2)));
1331
1332
1340extern void
1341 log_debug3 (const char *fstr, ...)
1342 __attribute__ ((format (printf, 1, 2)));
1343
1344
1352extern void
1353 log_debug3_append (const char *fstr, ...)
1354 __attribute__ ((format (printf, 1, 2)));
1355
1356
1364extern void
1365 log_debug4 (const char *fstr, ...)
1366 __attribute__ ((format (printf, 1, 2)));
1367
1368
1376extern void
1377 log_debug4_append (const char *fstr, ...)
1378 __attribute__ ((format (printf, 1, 2)));
1379
1380
1381/********************************************************************
1382* FUNCTIONs log_dev0 and log_dev0_append
1383*
1384* Generate (append to) a LOG_DEBUG_DEV0 log entry
1385*
1386* NOTE: This level is intended primarily for debugging, where output related
1387* issues at {ERROR, WARN, INFO} levels change program behavior)
1388*
1389* INPUTS:
1390* fstr == format string in printf format
1391* ... == any additional arguments for printf
1392*
1393*********************************************************************/
1394extern void
1395 log_dev0 (const char *fstr, ...)
1396 __attribute__ ((format (printf, 1, 2)));
1397
1398extern void
1399 log_dev0_append (const char *fstr, ...)
1400 __attribute__ ((format (printf, 1, 2)));
1401
1402
1403/********************************************************************
1404* FUNCTIONs log_dev1 and log_dev1_append
1405*
1406* Generate (append to) a LOG_DEBUG_DEV1 log entry
1407*
1408* NOTE: This level is intended primarily for debugging, where output related
1409* issues at {DEBUG, DEBUG2, DEBUG3, DEBUG4} change program behavior)
1410*
1411* INPUTS:
1412* fstr == format string in printf format
1413* ... == any additional arguments for printf
1414*
1415*********************************************************************/
1416extern void
1417 log_dev1 (const char *fstr, ...)
1418 __attribute__ ((format (printf, 1, 2)));
1419
1420extern void
1421 log_dev1_append (const char *fstr, ...)
1422 __attribute__ ((format (printf, 1, 2)));
1423
1424
1425/********************************************************************
1426* FUNCTIONs log_write_level and log_write_level_append
1427*
1428* Generate (append to) a LOG_DEBUG_<LEVEL> log trace entry
1429*
1430* NOTE: Useful when the desired debug level is passed as a param
1431*
1432* INPUTS:
1433* level == debug level
1434* fstr == format string in printf format
1435* ... == any additional arguments for printf
1436*
1437*********************************************************************/
1438extern void
1439 log_write_level (log_debug_t level, const char *fstr, ...)
1440 __attribute__ ((format (printf, 2, 3)));
1441
1442extern void
1443 log_write_level_append (log_debug_t level, const char *fstr, ...)
1444 __attribute__ ((format (printf, 2, 3)));
1445
1446
1447
1454extern logfn_t
1455 log_get_logfn (log_debug_t loglevel);
1456
1457
1465extern logfn_t
1466 log_get_appendfn (log_debug_t loglevel);
1467
1468
1469
1470/********************************************************************
1471* FUNCTIONs log_xxx_thd and log_xxx_append_thd
1472*
1473* Generate (or append to) a "thread" LOG_DEBUG_XXX level log entry
1474*
1475* INPUTS:
1476* fstr == format string in printf format
1477* ... == any additional arguments for printf
1478*
1479*********************************************************************/
1480#ifdef PTHREADS
1481extern void
1482 log_dev1_thd (const char *fstr, ...)
1483 __attribute__ ((format (printf, 1, 2)));
1484
1485extern void
1486 log_dev1_append_thd (const char *fstr, ...)
1487 __attribute__ ((format (printf, 1, 2)));
1488
1489extern void
1490 log_debug_thd (const char *fstr, ...)
1491 __attribute__ ((format (printf, 1, 2)));
1492
1493extern void
1494 log_debug_append_thd (const char *fstr, ...)
1495 __attribute__ ((format (printf, 1, 2)));
1496
1497extern void
1498 log_debug2_thd (const char *fstr, ...)
1499 __attribute__ ((format (printf, 1, 2)));
1500
1501extern void
1502 log_debug2_append_thd (const char *fstr, ...)
1503 __attribute__ ((format (printf, 1, 2)));
1504
1505extern void
1506 log_debug3_thd (const char *fstr, ...)
1507 __attribute__ ((format (printf, 1, 2)));
1508
1509extern void
1510 log_debug3_append_thd (const char *fstr, ...)
1511 __attribute__ ((format (printf, 1, 2)));
1512
1513extern void
1514 log_debug4_thd (const char *fstr, ...)
1515 __attribute__ ((format (printf, 1, 2)));
1516
1517extern void
1518 log_debug4_append_thd (const char *fstr, ...)
1519 __attribute__ ((format (printf, 1, 2)));
1520#endif //#ifdef PTHREADS
1521
1522
1523/********************************************************************
1524* FUNCTION log_noop
1525*
1526* Do not generate any log message NO-OP
1527* Used to set logfn_t to no-loggging option
1528*
1529* INPUTS:
1530* fstr == format string in printf format
1531* ... == any additional arguments for printf
1532*
1533*********************************************************************/
1534extern void
1535 log_noop (const char *fstr, ...)
1536 __attribute__ ((format (printf, 1, 2)));
1537
1538
1544extern void log_set_log_level (log_debug_t dlevel);
1545
1551extern void log_set_syslog_log_level (log_debug_t dlevel);
1552
1553
1554#ifdef PTHREADS
1560extern void log_set_pthread_log_level (log_debug_t dlevel);
1561#endif // PTHREADS
1562
1563
1564/*
1565* FUNCTION log_get_system_log_level
1566*
1567* Get the global debug filter threshold level
1568*
1569* RETURNS:
1570* the debug level
1571*********************************************************************/
1572extern log_debug_t log_get_system_log_level (void);
1573
1574
1580extern log_debug_t log_get_log_level (void);
1581
1582
1589
1590
1597
1598
1599/********************************************************************
1600* FUNCTION log_get_debug_level_enum
1601*
1602* Get the corresponding debug enum for the specified string
1603*
1604* INPUTS:
1605* str == string value to convert
1606*
1607* RETURNS:
1608* the corresponding enum for the specified debug level
1609*********************************************************************/
1610extern log_debug_t
1611 log_get_debug_level_enum (const char *str);
1612
1613extern uint
1614 log_parse_debug_level_str (const char *str);
1615
1616
1617/********************************************************************
1618* FUNCTION log_get_debug_level_string
1619*
1620* Get the corresponding string for the debug enum
1621*
1622* INPUTS:
1623* level == the enum for the specified debug level
1624*
1625* RETURNS:
1626* the string value for this enum
1627
1628*********************************************************************/
1629extern const xmlChar *
1630 log_get_debug_level_string (log_debug_t level);
1631
1632
1633
1634/********************************************************************
1635* FUNCTION log_get_debug_level_value
1636*
1637* Get the corresponding YANG enum value for the debug enum
1638*
1639* INPUTS:
1640* level == the enum for the specified debug level
1641*
1642* RETURNS:
1643* the int32 value for this enum
1644*********************************************************************/
1645extern int32
1646 log_get_debug_level_value (log_debug_t level);
1647
1648
1649/********************************************************************
1650* FUNCTION log_get_debug_app_string
1651*
1652* Get the corresponding string for the debug app enum
1653*
1654* INPUTS:
1655* app == the enum for the specified debug app
1656*
1657* RETURNS:
1658* the string value for this enum
1659
1660*********************************************************************/
1661extern const char *
1662 log_debug_get_app_string (log_debug_app_t app);
1663
1664/********************************************************************
1665* FUNCTION log_debug_app2facility
1666*
1667* Translate from YumaPro app to syslog facility
1668*
1669* INPUTS:
1670* app == the enum for the specified YUMA app
1671*
1672* RETURNS:
1673* Appropriate syslog facility code
1674*
1675*********************************************************************/
1676extern int
1677 log_debug_app2facility (log_debug_app_t app);
1678
1679
1680/********************************************************************
1681* FUNCTION log_set_debug_app
1682*
1683* Set syslog application level ... for example, yangcli will set
1684* USER while netconfd will set DAEMON for use by syslog.
1685*
1686* INPUTS:
1687* app == the enum for the specified YUMA app
1688*
1689* RETURNS:
1690* None
1691*
1692*********************************************************************/
1693extern void
1694 log_set_debug_app (log_debug_app_t app);
1695
1696
1697/********************************************************************
1698* FUNCTION log_get_debug_app
1699*
1700* Return syslog application level.
1701*
1702* INPUTS:
1703* None
1704*
1705* RETURNS:
1706* enum for the current YUMA app
1707*
1708*********************************************************************/
1709extern log_debug_app_t
1710 log_get_debug_app (void);
1711
1712
1713/********************************************************************
1714* FUNCTION log_debug_app_string
1715*
1716* Return syslog application level string equivalent
1717*
1718* INPUTS:
1719* None
1720*
1721* RETURNS:
1722* String equivalent for the current YUMA app type
1723*
1724*********************************************************************/
1725extern const char *
1726 log_debug_app_string (void);
1727
1728/********************************************************************
1729* FUNCTION log_is_open
1730*
1731* Check if the logfile is active
1732*
1733* RETURNS:
1734* TRUE if logfile open, FALSE otherwise
1735*********************************************************************/
1736extern boolean
1737 log_is_open (void);
1738
1739
1740/********************************************************************
1741* FUNCTION log_indent
1742*
1743* Printf a newline, then the specified number of chars
1744*
1745* INPUTS:
1746* indentcnt == number of indent chars, -1 == skip everything
1747*
1748*********************************************************************/
1749extern void
1750 log_indent (int32 indentcnt);
1751extern void
1752 log_indent_append (int32 indentcnt);
1753extern void
1754 log_indent_level_append (log_debug_t level, int32 indentcnt);
1755
1756
1757/********************************************************************
1758* FUNCTION log_stdout_indent
1759*
1760* Printf a newline to stdout, then the specified number of chars
1761*
1762* INPUTS:
1763* indentcnt == number of indent chars, -1 == skip everything
1764*
1765*********************************************************************/
1766extern void
1767 log_stdout_indent (int32 indentcnt);
1768
1769extern void
1770 log_stdout_level_indent (log_debug_t level, int32 indentcnt);
1771
1772
1773/********************************************************************
1774* FUNCTION log_get_logfile
1775*
1776* Get the open logfile for direct output
1777* Needed by libtecla to write command line history
1778*
1779* RETURNS:
1780* pointer to open FILE if any
1781* NULL if no open logfile
1782*********************************************************************/
1783extern FILE *
1784 log_get_logfile (void);
1785
1786
1787/********************************************************************
1788* FUNCTION log_start_capture
1789*
1790* Open a capture logfile for writing
1791*
1792* INPUTS:
1793* fname == full filespec string for capfile
1794*
1795* RETURNS:
1796* status
1797*********************************************************************/
1798extern status_t
1799 log_start_capture (const char *fname);
1800
1801
1802/********************************************************************
1803* FUNCTION log_end_capture
1804*
1805* Close a capture logfile after writing
1806*
1807*********************************************************************/
1808extern void
1809 log_end_capture (void);
1810
1811
1812/********************************************************************
1813* FUNCTION log_trigger_rotate
1814*
1815* Trigger the logrotate procedure
1816*
1817* RETURNS:
1818* none
1819*********************************************************************/
1820extern void
1821 log_trigger_rotate (void);
1822
1823/********************************************************************
1824* FUNCTION log_rotate_requested
1825*
1826* Check if logrotate procedure is in progress
1827*
1828* RETURNS:
1829* TRUE if logrotate procedure has been started
1830*
1831*********************************************************************/
1832extern boolean
1833 log_rotate_requested (void);
1834
1835
1847extern void
1848 log_set_highres_datetime (boolean val);
1849
1850
1857extern boolean
1859
1860
1861 // END ncxlib/log/logfns
1863
1864
1865
1866#ifdef __cplusplus
1867} /* end extern 'C' */
1868#endif
1869
1870#endif /* _H_log */
void log_alt_write(const char *fstr,...) __attribute__((format(printf
Write to the alternate log file.
logfn_t log_get_appendfn(log_debug_t loglevel)
Get the logfn_t for the corresponding log-level FOR APPEND.
Definition: log.c:3307
void void log_alt_write_level(log_debug_t level, const char *fstr,...) __attribute__((format(printf
Write to the alternate log file if debug-level set.
void log_error(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_ERROR log entry.
void void log_error_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_ERROR log entry.
void log_init(void)
Initialize logger state.
Definition: log.c:539
void log_close(void)
Close the logfile.
Definition: log.c:1137
log_debug_t log_get_pthread_log_level(void)
Get the pthreads log level.
Definition: log.c:3792
void void void void void void void log_debug(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG log entry.
void void log_stdout_level(log_debug_t level, const char *fstr,...) __attribute__((format(printf
Write output to STDOUT if debug level set.
void log_flush(void)
Flush output buffers.
Definition: log.c:1991
status_t log_alt_open_force(const char *fname, boolean overwrite, boolean force_mode)
Open an alternate logfile for writing.
Definition: log.c:1292
void void void void void void void void void void void void log_set_log_level(log_debug_t dlevel)
Set the main log level.
Definition: log.c:3627
void void void log_write(const char *fstr,...) __attribute__((format(printf
Write a new entry to the main log.
void void void void void void void void void void void log_debug3(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG3 log entry.
log_debug_t log_get_log_level(void)
Get the main log level.
Definition: log.c:3740
void void void void void void void void void log_audit_write(const char *fstr,...) __attribute__((format(printf
Write an new entry to the audit log file.
void log_set_highres_datetime(boolean val)
Set the high resolution date-time usage flag.
Definition: log.c:4360
log_debug_t log_get_syslog_log_level(void)
Get the syslog log level.
Definition: log.c:3755
void void void void void void void void void void log_audit_write_level(log_debug_t level, const char *fstr,...) __attribute__((format(printf
Write an new entry to the audit log file if the log level is set.
void void void void void void void void void void void void log_debug3_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_DEBUG3 log entry.
void disable_default_stdout(void)
Used by yp-client to disable log.c output.
Definition: log.c:270
void void void void void void void void void void void void void void void void void void void void logfn_t log_get_logfn(log_debug_t loglevel)
Get the logfn_t for the corresponding log-level.
Definition: log.c:3267
status_t log_alt_open(const char *fname)
Open an alternate logfile for writing.
Definition: log.c:1242
void log_alt_close(void)
Close the alternate logfile.
Definition: log.c:1329
boolean log_audit_is_open(void)
Check if the audit log is open.
Definition: log.c:1221
void void void void void void void void void void void void void void log_debug4_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_DEBUG4 log entry.
void void void log_warn(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_WARN log entry.
void void void void void void void void void void log_debug2_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_DEBUG2 log entry.
void void void void log_warn_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_WARN log entry.
boolean log_get_highres_datetime(void)
Get the high resolution date-time usage flag.
Definition: log.c:4378
status_t log_open(const char *fname, boolean append, boolean tstamps)
Open a logfile for writing.
Definition: log.c:1119
void log_audit_close(void)
Close the audit_logfile.
Definition: log.c:1193
void log_set_pthread_log_level(log_debug_t dlevel)
Set the pthreads log level.
Definition: log.c:3702
void log_set_syslog_log_level(log_debug_t dlevel)
Set the syslog log level.
Definition: log.c:3670
void void void void void void void void log_debug_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_DEBUG log entry.
void log_stdout(const char *fstr,...) __attribute__((format(printf
Write output to STDOUT.
status_t log_audit_open(const char *fname, boolean append, boolean tstamps)
Open the audit logfile for writing.
Definition: log.c:1175
void void void void void void void void void void void void void log_debug4(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG4 log entry.
void void void void void void log_info_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_INFO log entry.
void void void void log_write_append(const char *fstr,...) __attribute__((format(printf
Append to the last log entry to the main log.
void void void void void log_info(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_INFO log entry.
void enable_default_stdout(void)
Used by C program variants of yp-client to enable log.c output.
Definition: log.c:275
status_t log_alt_open_ex(const char *fname, boolean overwrite)
Open an alternate logfile for writing.
Definition: log.c:1263
void log_cleanup(boolean phase2, boolean debugs)
Final logger cleanup prior to restart or shutdown.
Definition: log.c:564
void void void void void void void void void log_debug2(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG2 log entry.
log_debug_app_t
syslog wants to know what app is logging ...
Definition: log.h:364
log_stream_t
The output stream enumerations used in util/log.c.
Definition: log.h:333
log_debug_t
The debug level enumerations used in util/log.c.
Definition: log.h:345
@ LOG_DEBUG_APP_YANGDIFF
app is yangdiff
Definition: log.h:368
@ LOG_DEBUG_APP_YANGCLI
app is yangcli
Definition: log.h:366
@ LOG_DEBUG_APP_NETCONFD
app is netconfd
Definition: log.h:369
@ LOG_DEBUG_APP_YANGDUMP
app is yangdump
Definition: log.h:367
@ LOG_STREAM_LOGFILE
Output destined for logfile.
Definition: log.h:337
@ LOG_STREAM_STDERR
Output destined for stderr.
Definition: log.h:336
@ LOG_STREAM_NONE
value not set or error
Definition: log.h:334
@ LOG_STREAM_STDOUT
Output destined for stdout.
Definition: log.h:335
@ LOG_STREAM_CAPFILE
Output destined for capfile.
Definition: log.h:338
@ LOG_DEBUG_DEV0
Special use developer debugging only.
Definition: log.h:349
@ LOG_DEBUG_NONE
value not set or error
Definition: log.h:346
@ LOG_DEBUG_ERROR
fatal + internal errors only
Definition: log.h:350
@ LOG_DEBUG_DEBUG
debug level 1
Definition: log.h:354
@ LOG_DEBUG_WARN
all errors + warnings
Definition: log.h:351
@ LOG_DEBUG_DEBUG2
debug level 2
Definition: log.h:355
@ LOG_DEBUG_INFO
all previous + user info trace
Definition: log.h:352
@ LOG_DEBUG_DEBUG4
debug level 4
Definition: log.h:357
@ LOG_DEBUG_DEV1
Special use developer debugging only.
Definition: log.h:353
@ LOG_DEBUG_WRITE
logging turned on
Definition: log.h:348
@ LOG_DEBUG_DEBUG3
debug level 3
Definition: log.h:356
@ LOG_DEBUG_OFF
logging turned off
Definition: log.h:347
status_t
global error return code
Definition: status_enum.h:210
Global error messages for status code enumerations.
Thread support (for now limited to netconfd)