openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

bslmgmt.c (2280B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * Broadcom System Log Management
      8  */
      9 
     10 #include <sal/core/libc.h> 
     11 #include <sal/appl/io.h> 
     12 #include <shared/bsl.h>
     13 #include <shared/bslnames.h>
     14 #include <appl/diag/bslenable.h>
     15 #include <appl/diag/bslcons.h>
     16 #include <appl/diag/bsltrace.h>
     17 #include <appl/diag/bslfile.h>
     18 #include <appl/diag/bslsink.h>
     19 #include <appl/diag/bslmgmt.h>
     20 
     21 /*
     22  * Output hook for core BSL configuration
     23  */
     24 STATIC int
     25 bslmgmt_out_hook(bsl_meta_t *meta, const char *format, va_list args)
     26 {
     27     int rv = 0;
     28     int sink_rv;
     29     va_list args_copy;
     30     bslsink_sink_t *sink = bslsink_sink_find_by_id(0);
     31 
     32     if (meta->severity > bslenable_get(meta->layer, meta->source)) {
     33         return 0;
     34     }
     35 
     36     while (sink != NULL) {
     37         /* Avoid consuming same arg list twice. */
     38         va_copy(args_copy, args);
     39         sink_rv = bslsink_out(sink, meta, format, args_copy);
     40         va_end(args_copy); 
     41         if (sink_rv > 0) {
     42             rv = sink_rv;
     43         }
     44         sink = sink->next;
     45     }
     46     return rv;
     47 }
     48 
     49 /*
     50  * Check hook for core BSL configuration
     51  */
     52 STATIC int
     53 bslmgmt_check_hook(bsl_packed_meta_t meta_pack)
     54 {
     55     int layer, source, severity;
     56 
     57     layer = BSL_LAYER_GET(meta_pack);
     58     source = BSL_SOURCE_GET(meta_pack);
     59     severity = BSL_SEVERITY_GET(meta_pack);
     60 
     61     return (severity <= bslenable_get(layer, source));
     62 }
     63 
     64 int
     65 bslmgmt_cleanup(void)
     66 {
     67     return bslsink_cleanup();
     68 }
     69 
     70 int
     71 bslmgmt_init(void)
     72 {
     73     bsl_config_t bsl_config;
     74 
     75     bslenable_reset_all();
     76 
     77     bsl_config_t_init(&bsl_config);
     78     bsl_config.out_hook = bslmgmt_out_hook;
     79     bsl_config.check_hook = bslmgmt_check_hook;
     80     bsl_init(&bsl_config);
     81 
     82     /* Initialize output hook */
     83     bslsink_init();
     84 
     85     /* Create console sink */
     86     bslcons_init();
     87 
     88 #ifndef NO_FILEIO
     89     /* Create file sink */
     90     bslfile_init();
     91 #endif
     92 
     93 #ifdef BSL_TRACE_INCLUDE
     94     /* Create trace sink */
     95     bsltrace_init();
     96     /* Turn on debug so that trace sink can catch it */
     97     bslmgmt_set(bslLayerBcm, bslSourceTrace, bslSeverityDebug);
     98     bslmgmt_set(bslLayerSoc, bslSourceTrace, bslSeverityDebug);
     99 #endif
    100 
    101     return 0;
    102 }