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