The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
log.c
Go to the documentation of this file.
1 /*
2  * @copyright (c) 2016, Network RADIUS SAS (license@networkradius.com)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Network RADIUS SAS nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /**
29  * $Id: f8639d494c3f6c2e8e264184475499184e2fe8f9 $
30  * @file rlm_sigtran/log.c
31  * @brief Interface libosmo with FreeRADIUS logging
32  */
33 #define LOG_PREFIX "sigtran"
34 
35 #include <freeradius-devel/server/base.h>
36 #include <osmocom/core/logging.h>
37 #include "sigtran.h"
38 
39 static void do_log(UNUSED struct log_target *target, unsigned int level, const char *log)
40 {
41  switch (level) {
42  case LOGL_DEBUG:
43  DEBUG2("%s", log);
44  break;
45 
46  case LOGL_INFO:
47  case LOGL_NOTICE:
48  INFO("%s", log);
49  break;
50 
51  case LOGL_ERROR:
52  case LOGL_FATAL:
53  default:
54  ERROR("%s", log);
55  break;
56  }
57 }
58 
59 /** Patch our logging system into libosmo's
60  *
61  */
62 void sigtran_log_init(TALLOC_CTX *ctx)
63 {
64  struct log_target *log;
65  static struct log_info info;
66 
67  log_init(&info, ctx);
68 
69  /*
70  * Setup logging
71  */
72  log = log_target_create();
73  log_set_use_color(log, 0);
74  log_set_print_extended_timestamp(log, 0);
75  log_set_print_timestamp(log, 0);
76  if (DEBUG_ENABLED3) {
77  log_set_print_category(log, 1);
78  log_set_print_filename(log, 1);
79  } else {
80  log_set_print_category(log, 0);
81  log_set_print_filename(log, 0);
82  }
83  log->output = do_log; /* Use our proxy logging function */
84  log_add_target(log);
85  log_set_all_filter(log, 1);
86 }
87 
#define UNUSED
Definition: build.h:313
#define ERROR(fmt,...)
Definition: dhcpclient.c:41
#define DEBUG_ENABLED3
True if global debug level 1-3 messages are enabled.
Definition: log.h:259
static void do_log(UNUSED struct log_target *target, unsigned int level, const char *log)
Definition: log.c:39
void sigtran_log_init(TALLOC_CTX *ctx)
Patch our logging system into libosmo's.
Definition: log.c:62
#define DEBUG2(fmt,...)
Definition: radclient.h:43
#define INFO(fmt,...)
Definition: radict.c:54
Declarations for various sigtran functions.