Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
log.h File Reference

Go to the source code of this file.

Macros

#define panic   gw_panic
 

Enumerations

enum  output_level {
  GW_DEBUG, GW_INFO, GW_WARNING, GW_ERROR,
  GW_PANIC, GW_BACKTRACE
}
 
enum  excl_state { GW_NON_EXCL, GW_EXCL }
 

Functions

void log_init (void)
 
void log_shutdown (void)
 
void gw_panic (int, const char *,...) PRINTFLIKE(2
 
void void gw_backtrace (void **, size_t, int)
 
void error (int, const char *,...) PRINTFLIKE(2
 
void void warning (int, const char *,...) PRINTFLIKE(2
 
void void void info (int, const char *,...) PRINTFLIKE(2
 
void void void void debug (const char *, int, const char *,...) PRINTFLIKE(3
 
void void void void void log_set_debug_places (const char *places)
 
void log_set_output_level (enum output_level level)
 
void log_set_log_level (enum output_level level)
 
void log_set_syslog_facility (char *facility)
 
void log_set_syslog (const char *ident, int syslog_level)
 
int log_open (char *filename, int level, enum excl_state excl)
 
void log_reopen (void)
 
void log_close_all (void)
 
void log_thread_to (int idx)
 

Macro Definition Documentation

#define panic   gw_panic

Definition at line 87 of file log.h.

Referenced by accept_thread(), at2_detect_modem_type(), at2_read_modems(), bb_smscconn_receive(), become_daemon(), cfg_get_group_checksum(), cfg_get_real(), cfg_read(), check(), check_args(), check_comparisons(), client(), client_destroy(), client_session(), conn_claim(), connect_to_bearerbox(), convert(), convert_wmlscript_to_wmlscriptc(), create_onetrans(), create_oneuser(), dlr_db_fields_create(), dlr_init(), dlr_init_spool(), emi2_handle_smscreq(), emi2_idleprocessing(), entity_read(), generic_init(), get_and_set_debugs(), getthreadinfo(), gw_check_calloc(), gw_check_claim_area(), gw_check_free(), gw_check_malloc(), gw_check_realloc(), gw_native_calloc(), gw_native_malloc(), gw_native_realloc(), gw_rwlock_create(), gw_rwlock_destroy(), gw_rwlock_init_static(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwthread_init(), handle_action(), handle_reply(), handle_transaction(), handler(), http_use_proxy(), httpadmin_start(), httpd_emu_create(), init_batch(), init_bearerbox(), init_reroute(), init_smsbox(), init_smsbox_routes(), init_wapbox(), ip_allowed_by_ppg(), lock(), main(), main_for_extract(), main_for_list_add_and_delete(), main_for_producer_and_consumer(), main_thread(), msg_pack(), mutex_destroy(), mutex_lock_real(), mutex_trylock_real(), mutex_unlock_real(), new_thread(), octstr_imm(), parachute_init_signals(), parachute_start(), post_content_create(), proxy_thread(), push_content_create(), radius_acct_init(), radius_type_convert(), read_ppg_config(), read_test_ppg_config(), receive_request(), record_allocation(), restore_user_signals(), run_requests(), semaphore_create(), semaphore_destroy(), semaphore_getvalue(), send_post(), server(), setup_official_name(), signal_handler(), smpp_emu(), smpp_emu_handle_pdu(), smsbox_start(), smsbox_thread(), smsboxc_run(), smsc2_start(), smsc_emu_create(), smsc_http_create(), smsc_smasi_create(), smsc_smpp_create(), smscconn_create(), start_http_thread(), start_wap(), start_wapbox(), store_file_init(), store_file_load(), udp_addwdp_from_client(), udp_addwdp_from_server(), unlock(), unlock_in_real(), unlock_out_real(), unpack_accept_language_general_form(), unpack_cache_directive(), unpack_field_name(), unpack_parameter(), wait_for_client(), wap_event_create_real(), wap_event_destroy(), wap_event_duplicate(), wap_event_name(), wapbox_start(), wapboxc_run(), write_pid_file(), wsp_pdu_create(), wsp_pdu_destroy(), wsp_pdu_pack(), wsp_unpack_accept_charset_general_form(), wsp_unpack_accept_general_form(), wsp_unpack_well_known_field(), and wtp_pdu_pack().

Enumeration Type Documentation

enum excl_state
Enumerator
GW_NON_EXCL 
GW_EXCL 

Definition at line 73 of file log.h.

73  {
75 };
Definition: log.h:74
Enumerator
GW_DEBUG 
GW_INFO 
GW_WARNING 
GW_ERROR 
GW_PANIC 
GW_BACKTRACE 

Definition at line 68 of file log.h.

68  {
70 };
Definition: log.h:69
Definition: log.h:69
Definition: log.h:69
Definition: log.h:69
Definition: log.h:69

Function Documentation

void void void void debug ( const char *  ,
int  ,
const char *  ,
  ... 
)
void error ( int  ,
const char *  ,
  ... 
)
void void gw_backtrace ( void **  ,
size_t  ,
int   
)

Definition at line 563 of file log.c.

References gw_native_free(), and size.

Referenced by fatal_handler(), and gw_panic().

564 {
565 #if HAVE_BACKTRACE
566  void *frames[50];
567  size_t i;
568  char **strings;
569 
570  if (stack_frames == NULL) {
571  stack_frames = frames;
572  size = backtrace(stack_frames, sizeof(frames) / sizeof(void*));
573  }
574 
575  strings = backtrace_symbols(stack_frames, size);
576 
577  if (strings) {
578  for (i = 0; i < size; i++)
579  gw_panic_output(0, "%s", strings[i]);
580  }
581  else { /* hmm, no memory available */
582  for (i = 0; i < size; i++)
583  gw_panic_output(0, "%p", stack_frames[i]);
584  }
585 
586  /*
587  * Note: we must call gw_native_free directly because if gw_free points to gw_check_free we could
588  * panic's and we have endless loop with SEGFAULT at the end.
589  */
590  gw_native_free(strings);
591 #endif
592 }
int size
Definition: wsasm.c:84
void gw_native_free(void *ptr)
Definition: gwmem-native.c:123
void gw_panic ( int  ,
const char *  ,
  ... 
)
void void void info ( int  ,
const char *  ,
  ... 
)
void log_close_all ( void  )

Definition at line 305 of file log.c.

References closelog(), file, filename, gw_rwlock_unlock(), gw_rwlock_wrlock(), logfiles, and num_logfiles.

Referenced by get_and_set_debugs(), log_shutdown(), and main().

306 {
307  /*
308  * Writer lock.
309  */
311 
312  while (num_logfiles > 0) {
313  --num_logfiles;
314  if (logfiles[num_logfiles].file != stderr && logfiles[num_logfiles].file != NULL) {
315  int i;
316  /* look for the same filename and set file to NULL */
317  for (i = num_logfiles - 1; i >= 0; i--) {
318  if (strcmp(logfiles[num_logfiles].filename, logfiles[i].filename) == 0)
319  logfiles[i].file = NULL;
320  }
321  fclose(logfiles[num_logfiles].file);
322  logfiles[num_logfiles].file = NULL;
323  }
324  }
325 
326  /*
327  * Unlock writer.
328  */
330 
331  /* close syslog if used */
332  if (dosyslog) {
333  closelog();
334  dosyslog = 0;
335  }
336 }
static struct @66 logfiles[MAX_LOGFILES]
static int dosyslog
Definition: log.c:175
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
FILE * file
Definition: log.c:133
static RWLock rwlock
Definition: log.c:168
static int num_logfiles
Definition: log.c:138
static void closelog(void)
Definition: log.c:122
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
char filename[FILENAME_MAX+1]
Definition: log.c:135
void log_init ( void  )

Definition at line 194 of file log.c.

References add_stderr(), gw_rwlock_init_static(), thread_to, and THREADTABLE_SIZE.

Referenced by gwlib_init().

195 {
196  unsigned long i;
197 
198  /* Initialize rwlock */
200 
201  /* default all possible thread to logging index 0, stderr */
202  for (i = 0; i < THREADTABLE_SIZE; i++) {
203  thread_to[i] = 0;
204  }
205 
206  add_stderr();
207 }
#define THREADTABLE_SIZE
Definition: log.c:145
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:146
static RWLock rwlock
Definition: log.c:168
static void add_stderr(void)
Definition: log.c:180
void gw_rwlock_init_static(RWLock *lock)
Definition: gw-rwlock.c:96
int log_open ( char *  filename,
int  level,
enum excl_state  excl 
)

Definition at line 339 of file log.c.

References error(), gw_rwlock_unlock(), gw_rwlock_wrlock(), info(), logfiles, MAX_LOGFILES, and num_logfiles.

Referenced by get_and_set_debugs(), init_bearerbox(), init_smsbox(), init_wapbox(), main(), and smscconn_create().

340 {
341  FILE *f = NULL;
342  int i;
343 
345 
346  if (num_logfiles == MAX_LOGFILES) {
348  error(0, "Too many log files already open, not adding `%s'",
349  filename);
350  return -1;
351  }
352 
353  if (strlen(filename) > FILENAME_MAX) {
355  error(0, "Log filename too long: `%s'.", filename);
356  return -1;
357  }
358 
359  /*
360  * Check if the file is already opened for logging.
361  * If there is an open file, then assign the file descriptor
362  * that is already existing for this log file.
363  */
364  for (i = 0; i < num_logfiles && f == NULL; ++i) {
365  if (strcmp(logfiles[i].filename, filename) == 0)
366  f = logfiles[i].file;
367  }
368 
369  /* if not previously opened, then open it now */
370  if (f == NULL) {
371  f = fopen(filename, "a");
372  if (f == NULL) {
374  error(errno, "Couldn't open logfile `%s'.", filename);
375  return -1;
376  }
377  }
378 
379  logfiles[num_logfiles].file = f;
380  logfiles[num_logfiles].minimum_output_level = level;
381  logfiles[num_logfiles].exclusive = excl;
382  strcpy(logfiles[num_logfiles].filename, filename);
383  ++num_logfiles;
384  i = num_logfiles - 1;
386 
387  info(0, "Added logfile `%s' with level `%d'.", filename, level);
388 
389  return i;
390 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
static struct @66 logfiles[MAX_LOGFILES]
#define MAX_LOGFILES
Definition: log.c:131
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
static RWLock rwlock
Definition: log.c:168
static int num_logfiles
Definition: log.c:138
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
char filename[FILENAME_MAX+1]
Definition: log.c:135
void log_reopen ( void  )

Definition at line 261 of file log.c.

References error(), file, filename, found, gw_rwlock_unlock(), gw_rwlock_wrlock(), logfiles, and num_logfiles.

Referenced by main(), and signal_handler().

262 {
263  int i, j, found;
264 
265  /*
266  * Writer lock.
267  */
269 
270  for (i = 0; i < num_logfiles; ++i) {
271  if (logfiles[i].file != stderr) {
272  found = 0;
273 
274  /*
275  * Reverse seek for allready reopened logfile.
276  * If we find a previous file descriptor for the same file
277  * name, then don't reopen that duplicate, but assign the
278  * file pointer to it.
279  */
280  for (j = i-1; j >= 0 && found == 0; j--) {
281  if (strcmp(logfiles[i].filename, logfiles[j].filename) == 0) {
282  logfiles[i].file = logfiles[j].file;
283  found = 1;
284  }
285  }
286  if (found)
287  continue;
288  if (logfiles[i].file != NULL)
289  fclose(logfiles[i].file);
290  logfiles[i].file = fopen(logfiles[i].filename, "a");
291  if (logfiles[i].file == NULL) {
292  error(errno, "Couldn't re-open logfile `%s'.",
293  logfiles[i].filename);
294  }
295  }
296  }
297 
298  /*
299  * Unlock writer.
300  */
302 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static struct @66 logfiles[MAX_LOGFILES]
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
FILE * file
Definition: log.c:133
static struct pid_list * found
static RWLock rwlock
Definition: log.c:168
static int num_logfiles
Definition: log.c:138
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
char filename[FILENAME_MAX+1]
Definition: log.c:135
void void void void void log_set_debug_places ( const char *  places)

Definition at line 710 of file log.c.

References MAX_LOGGABLE_PLACES.

Referenced by get_and_set_debugs().

711 {
712  char *p;
713 
714  p = strtok(gw_strdup(places), " ,");
715  num_places = 0;
716  while (p != NULL && num_places < MAX_LOGGABLE_PLACES) {
718  p = strtok(NULL, " ,");
719  }
720 }
static int num_places
Definition: log.c:162
static char * loggable_places[MAX_LOGGABLE_PLACES]
Definition: log.c:161
#define MAX_LOGGABLE_PLACES
Definition: log.c:160
void log_set_log_level ( enum output_level  level)

Definition at line 229 of file log.c.

References file, filename, info(), logfiles, and num_logfiles.

Referenced by config_reload(), and httpd_loglevel().

230 {
231  int i;
232 
233  /* change everything but stderr */
234  for (i = 0; i < num_logfiles; ++i) {
235  if (logfiles[i].file != stderr) {
236  logfiles[i].minimum_output_level = level;
237  info(0, "Changed logfile `%s' to level `%d'.", logfiles[i].filename, level);
238  }
239  }
240 }
void info(int err, const char *fmt,...)
Definition: log.c:636
static struct @66 logfiles[MAX_LOGFILES]
FILE * file
Definition: log.c:133
static int num_logfiles
Definition: log.c:138
char filename[FILENAME_MAX+1]
Definition: log.c:135
void log_set_output_level ( enum output_level  level)

Definition at line 217 of file log.c.

References file, logfiles, and num_logfiles.

Referenced by get_and_set_debugs(), and main().

218 {
219  int i;
220 
221  for (i = 0; i < num_logfiles; ++i) {
222  if (logfiles[i].file == stderr) {
223  logfiles[i].minimum_output_level = level;
224  break;
225  }
226  }
227 }
static struct @66 logfiles[MAX_LOGFILES]
FILE * file
Definition: log.c:133
static int num_logfiles
Definition: log.c:138
void log_set_syslog ( const char *  ident,
int  syslog_level 
)

Definition at line 248 of file log.c.

References debug(), LOG_PID, and openlog().

Referenced by get_and_set_debugs(), init_bearerbox(), init_smsbox(), init_wapbox(), and remove_pid_file().

249 {
250  if (ident == NULL)
251  dosyslog = 0;
252  else {
253  dosyslog = 1;
254  sysloglevel = syslog_level;
255  openlog(ident, LOG_PID, syslogfacility);
256  debug("gwlib.log", 0, "Syslog logging enabled.");
257  }
258 }
static int dosyslog
Definition: log.c:175
static void openlog(const char *ident, int option, int facility)
Definition: log.c:114
static int sysloglevel
Definition: log.c:173
Definition: log.c:106
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
static int syslogfacility
Definition: log.c:174
void log_set_syslog_facility ( char *  facility)

Definition at line 242 of file log.c.

References decode().

Referenced by init_bearerbox(), init_smsbox(), and init_wapbox().

243 {
244  if (facility != NULL)
245  syslogfacility = decode(facility);
246 }
static int decode(char *name)
Definition: log.c:109
static int syslogfacility
Definition: log.c:174
void log_shutdown ( void  )

Definition at line 209 of file log.c.

References gw_rwlock_destroy(), and log_close_all().

Referenced by gwlib_shutdown().

210 {
211  log_close_all();
212  /* destroy rwlock */
214 }
void gw_rwlock_destroy(RWLock *lock)
Definition: gw-rwlock.c:112
static RWLock rwlock
Definition: log.c:168
void log_close_all(void)
Definition: log.c:305
void log_thread_to ( int  idx)

Definition at line 723 of file log.c.

References filename, info(), logfiles, minimum_output_level, thread_slot, thread_to, and warning().

Referenced by at2_device_thread(), cgw_listener(), cgw_sender(), emi2_listener(), emi2_sender(), fake_listener(), httpsmsc_receiver(), httpsmsc_send_cb(), httpsmsc_sender(), io_thread(), smasi_thread(), wrapper_receiver(), and wrapper_sender().

724 {
725  long thread_id = thread_slot();
726 
727  if (idx > 0) {
728  info(0, "Logging thread `%ld' to logfile `%s' with level `%d'.",
729  thread_id, logfiles[idx].filename, logfiles[idx].minimum_output_level);
730  thread_to[thread_id] = idx;
731  } else if (idx != 0 && num_logfiles > 0) {
732  warning(0, "Logging thread `%ld' to logfile `%s' with level `%d'.",
733  thread_id, logfiles[0].filename, logfiles[0].minimum_output_level);
734  }
735 }
void info(int err, const char *fmt,...)
Definition: log.c:636
static struct @66 logfiles[MAX_LOGFILES]
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:146
int minimum_output_level
Definition: log.c:134
static int num_logfiles
Definition: log.c:138
void warning(int err, const char *fmt,...)
Definition: log.c:624
char filename[FILENAME_MAX+1]
Definition: log.c:135
#define thread_slot()
Definition: log.c:153
void void warning ( int  ,
const char *  ,
  ... 
)
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.