Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
syslog.h File Reference

Syslog support functions for Asterisk logging. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ASTNUMLOGLEVELS   32
 

Functions

int ast_syslog_facility (const char *facility)
 Maps a syslog facility name from a string to a syslog facility constant. More...
 
const char * ast_syslog_facility_name (int facility)
 Maps a syslog facility constant to a string. More...
 
int ast_syslog_priority (const char *priority)
 Maps a syslog priority name from a string to a syslog priority constant. More...
 
int ast_syslog_priority_from_loglevel (int level)
 Maps an Asterisk log level (i.e. LOG_ERROR) to a syslog priority constant. More...
 
const char * ast_syslog_priority_name (int priority)
 Maps a syslog priority constant to a string. More...
 

Detailed Description

Syslog support functions for Asterisk logging.

Definition in file syslog.h.

Macro Definition Documentation

◆ ASTNUMLOGLEVELS

#define ASTNUMLOGLEVELS   32

Definition at line 31 of file syslog.h.

Referenced by ast_syslog_priority_from_loglevel().

Function Documentation

◆ ast_syslog_facility()

int ast_syslog_facility ( const char *  facility)

Maps a syslog facility name from a string to a syslog facility constant.

Since
1.8
Parameters
facilityFacility name to map (i.e. "daemon")
Return values
syslogfacility constant (i.e. LOG_DAEMON) if found
-1if facility is not found

Definition at line 85 of file syslog.c.

References ARRAY_LEN, facility_map, and name.

Referenced by load_config(), and make_logchannel().

86 {
87  int index;
88 
89  for (index = 0; index < ARRAY_LEN(facility_map); index++) {
90  if (!strcasecmp(facility_map[index].name, facility)) {
91  return facility_map[index].value;
92  }
93  }
94 
95  return -1;
96 }
static const struct @426 facility_map[]
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
const char * name
Definition: syslog.c:36

◆ ast_syslog_facility_name()

const char* ast_syslog_facility_name ( int  facility)

Maps a syslog facility constant to a string.

Since
1.8
Parameters
facilitysyslog facility constant to map (i.e. LOG_DAEMON)
Return values
facilityname (i.e. "daemon") if found
NULLif facility is not found

Definition at line 98 of file syslog.c.

References ARRAY_LEN, facility_map, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, name, NULL, priority_map, and value.

Referenced by load_config().

99 {
100  int index;
101 
102  for (index = 0; index < ARRAY_LEN(facility_map); index++) {
103  if (facility_map[index].value == facility) {
104  return facility_map[index].name;
105  }
106  }
107 
108  return NULL;
109 }
static const struct @426 facility_map[]
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37

◆ ast_syslog_priority()

int ast_syslog_priority ( const char *  priority)

Maps a syslog priority name from a string to a syslog priority constant.

Since
1.8
Parameters
priorityPriority name to map (i.e. "notice")
Return values
syslogpriority constant (i.e. LOG_NOTICE) if found
-1if priority is not found

Definition at line 126 of file syslog.c.

References ARRAY_LEN, name, and priority_map.

Referenced by load_config().

127 {
128  int index;
129 
130  for (index = 0; index < ARRAY_LEN(priority_map); index++) {
131  if (!strcasecmp(priority_map[index].name, priority)) {
132  return priority_map[index].value;
133  }
134  }
135 
136  return -1;
137 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
const char * name
Definition: syslog.c:36
static int priority
static const struct @427 priority_map[]

◆ ast_syslog_priority_from_loglevel()

int ast_syslog_priority_from_loglevel ( int  level)

Maps an Asterisk log level (i.e. LOG_ERROR) to a syslog priority constant.

Since
1.8
Parameters
levelAsterisk log level constant (i.e. LOG_ERROR)
Return values
syslogpriority constant (i.e. LOG_ERR) if found
-1if priority is not found

Definition at line 162 of file syslog.c.

References ARRAY_LEN, ASTNUMLOGLEVELS, LOG_NOTICE, and logger_level_to_syslog_map.

Referenced by logger_print_normal().

163 {
164  /* First 16 levels are reserved for system use.
165  * Default to using LOG_NOTICE for dynamic logging.
166  */
167  if (level >= 16 && level < ASTNUMLOGLEVELS) {
168  return LOG_NOTICE;
169  }
170 
171  if (level < 0 || level >= ARRAY_LEN(logger_level_to_syslog_map)) {
172  return -1;
173  }
174 
175  return logger_level_to_syslog_map[level];
176 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define LOG_NOTICE
Definition: logger.h:263
static const int logger_level_to_syslog_map[]
Definition: syslog.c:152
#define ASTNUMLOGLEVELS
Definition: syslog.h:31

◆ ast_syslog_priority_name()

const char* ast_syslog_priority_name ( int  priority)

Maps a syslog priority constant to a string.

Since
1.8
Parameters
prioritysyslog priority constant to map (i.e. LOG_NOTICE)
Return values
priorityname (i.e. "notice") if found
NULLif priority is not found

Definition at line 139 of file syslog.c.

References ARRAY_LEN, NULL, priority_map, and value.

Referenced by load_config().

140 {
141  int index;
142 
143  for (index = 0; index < ARRAY_LEN(priority_map); index++) {
144  if (priority_map[index].value == priority) {
145  return priority_map[index].name;
146  }
147  }
148 
149  return NULL;
150 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
static int priority
static const struct @427 priority_map[]