log.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* $OpenBSD: log.h,v 1.24 2019/09/06 04:53:27 djm Exp $ */
  2. /*
  3. * Author: Tatu Ylonen <ylo@cs.hut.fi>
  4. * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  5. * All rights reserved
  6. *
  7. * As far as I am concerned, the code I have written for this software
  8. * can be used freely for any purpose. Any derived versions of this
  9. * software must be clearly marked as such, and if the derived work is
  10. * incompatible with the protocol description in the RFC file, it must be
  11. * called by a name other than "ssh" or "Secure Shell".
  12. */
  13. #ifndef SSH_LOG_H
  14. #define SSH_LOG_H
  15. #include <stdarg.h> /* va_list */
  16. /* Supported syslog facilities and levels. */
  17. typedef enum {
  18. SYSLOG_FACILITY_DAEMON,
  19. SYSLOG_FACILITY_USER,
  20. SYSLOG_FACILITY_AUTH,
  21. #ifdef LOG_AUTHPRIV
  22. SYSLOG_FACILITY_AUTHPRIV,
  23. #endif
  24. SYSLOG_FACILITY_LOCAL0,
  25. SYSLOG_FACILITY_LOCAL1,
  26. SYSLOG_FACILITY_LOCAL2,
  27. SYSLOG_FACILITY_LOCAL3,
  28. SYSLOG_FACILITY_LOCAL4,
  29. SYSLOG_FACILITY_LOCAL5,
  30. SYSLOG_FACILITY_LOCAL6,
  31. SYSLOG_FACILITY_LOCAL7,
  32. SYSLOG_FACILITY_NOT_SET = -1
  33. } SyslogFacility;
  34. typedef enum {
  35. SYSLOG_LEVEL_QUIET,
  36. SYSLOG_LEVEL_FATAL,
  37. SYSLOG_LEVEL_ERROR,
  38. SYSLOG_LEVEL_INFO,
  39. SYSLOG_LEVEL_VERBOSE,
  40. SYSLOG_LEVEL_DEBUG1,
  41. SYSLOG_LEVEL_DEBUG2,
  42. SYSLOG_LEVEL_DEBUG3,
  43. SYSLOG_LEVEL_NOT_SET = -1
  44. } LogLevel;
  45. typedef void (log_handler_fn)(LogLevel, const char *, void *);
  46. void log_init(const char *, LogLevel, SyslogFacility, int);
  47. void log_init_handler(const char *, LogLevel, SyslogFacility, int, int);
  48. LogLevel log_level_get(void);
  49. int log_change_level(LogLevel);
  50. int log_is_on_stderr(void);
  51. void log_redirect_stderr_to(const char *);
  52. SyslogFacility log_facility_number(char *);
  53. const char * log_facility_name(SyslogFacility);
  54. LogLevel log_level_number(char *);
  55. const char * log_level_name(LogLevel);
  56. void fatal(const char *, ...) __attribute__((noreturn))
  57. __attribute__((format(printf, 1, 2)));
  58. void error(const char *, ...) __attribute__((format(printf, 1, 2)));
  59. void sigdie(const char *, ...) __attribute__((noreturn))
  60. __attribute__((format(printf, 1, 2)));
  61. void logdie(const char *, ...) __attribute__((noreturn))
  62. __attribute__((format(printf, 1, 2)));
  63. void logit(const char *, ...) __attribute__((format(printf, 1, 2)));
  64. void verbose(const char *, ...) __attribute__((format(printf, 1, 2)));
  65. void debug(const char *, ...) __attribute__((format(printf, 1, 2)));
  66. void debug2(const char *, ...) __attribute__((format(printf, 1, 2)));
  67. void debug3(const char *, ...) __attribute__((format(printf, 1, 2)));
  68. void set_log_handler(log_handler_fn *, void *);
  69. void do_log2(LogLevel, const char *, ...)
  70. __attribute__((format(printf, 2, 3)));
  71. void do_log(LogLevel, const char *, va_list);
  72. void cleanup_exit(int) __attribute__((noreturn));
  73. #endif