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