xref: /PHP-7.4/sapi/fpm/fpm/zlog.h (revision ffcf57fa)
1 	/* (c) 2004-2007 Andrei Nigmatulin */
2 
3 #ifndef ZLOG_H
4 #define ZLOG_H 1
5 
6 #include <stdarg.h>
7 #include <sys/types.h>
8 
9 #define zlog(flags,...) zlog_ex(__func__, __LINE__, flags, __VA_ARGS__)
10 #define zlog_msg(flags, prefix, msg) zlog_msg_ex(__func__, __LINE__, flags, prefix, msg)
11 
12 struct timeval;
13 
14 typedef unsigned char zlog_bool;
15 
16 #define ZLOG_TRUE 1
17 #define ZLOG_FALSE 0
18 
19 void zlog_set_external_logger(void (*logger)(int, char *, size_t));
20 int zlog_set_fd(int new_fd);
21 int zlog_set_level(int new_value);
22 int zlog_set_limit(int new_value);
23 int zlog_set_buffering(zlog_bool buffering);
24 const char *zlog_get_level_name(int log_level);
25 void zlog_set_launched(void);
26 
27 size_t zlog_print_time(struct timeval *tv, char *timebuf, size_t timebuf_len);
28 
29 void vzlog(const char *function, int line, int flags, const char *fmt, va_list args);
30 void zlog_ex(const char *function, int line, int flags, const char *fmt, ...)
31 		__attribute__ ((format(printf,4,5)));
32 
33 void zlog_msg_ex(const char *function, int line, int flags,
34 		const char *prefix, const char *msg);
35 
36 #ifdef HAVE_SYSLOG_H
37 extern const int syslog_priorities[];
38 #endif
39 
40 /* keep this same as FCGI_ERROR */
41 enum {
42 	ZLOG_DEBUG			= 1,
43 	ZLOG_NOTICE			= 2,
44 	ZLOG_WARNING		= 3,
45 	ZLOG_ERROR			= 4,
46 	ZLOG_ALERT			= 5,
47 };
48 
49 #define ZLOG_LEVEL_MASK 7
50 
51 #define ZLOG_HAVE_ERRNO 0x100
52 
53 #define ZLOG_SYSERROR (ZLOG_ERROR | ZLOG_HAVE_ERRNO)
54 
55 #define ZLOG_SYSLOG -2
56 
57 /* STREAM */
58 
59 struct zlog_stream_buffer {
60 	char *data;
61 	size_t size;
62 };
63 
64 struct zlog_stream {
65 	int flags;
66 	unsigned int use_syslog:1;
67 	unsigned int use_fd:1;
68 	unsigned int use_buffer:1;
69 	unsigned int use_stderr:1;
70 	unsigned int prefix_buffer:1;
71 	unsigned int finished:1;
72 	unsigned int full:1;
73 	unsigned int wrap:1;
74 	unsigned int msg_quote:1;
75 	unsigned int decorate:1;
76 	unsigned int is_stdout:1;
77 	int fd;
78 	int line;
79 	int child_pid;
80 	const char *function;
81 	struct zlog_stream_buffer buf;
82 	size_t len;
83 	size_t buf_init_size;
84 	size_t prefix_len;
85 	char *msg_prefix;
86 	size_t msg_prefix_len;
87 	char *msg_suffix;
88 	size_t msg_suffix_len;
89 	char *msg_final_suffix;
90 	size_t msg_final_suffix_len;
91 };
92 
93 void zlog_stream_init(struct zlog_stream *stream, int flags);
94 void zlog_stream_init_ex(struct zlog_stream *stream, int flags, int fd);
95 void zlog_stream_set_decorating(struct zlog_stream *stream, zlog_bool decorate);
96 void zlog_stream_set_wrapping(struct zlog_stream *stream, zlog_bool wrap);
97 void zlog_stream_set_is_stdout(struct zlog_stream *stream, zlog_bool is_stdout);
98 void zlog_stream_set_child_pid(struct zlog_stream *stream, int child_pid);
99 void zlog_stream_set_msg_quoting(struct zlog_stream *stream, zlog_bool quote);
100 zlog_bool zlog_stream_set_msg_prefix(struct zlog_stream *stream, const char *fmt, ...)
101 		__attribute__ ((format(printf,2,3)));
102 zlog_bool zlog_stream_set_msg_suffix(
103 		struct zlog_stream *stream, const char *suffix, const char *final_suffix);
104 #define zlog_stream_prefix(stream) \
105 	zlog_stream_prefix_ex(stream, __func__, __LINE__)
106 ssize_t zlog_stream_prefix_ex(struct zlog_stream *stream, const char *function, int line);
107 ssize_t zlog_stream_format(struct zlog_stream *stream, const char *fmt, ...)
108 		__attribute__ ((format(printf,2,3)));
109 ssize_t zlog_stream_vformat(struct zlog_stream *stream, const char *fmt, va_list args);
110 ssize_t zlog_stream_str(struct zlog_stream *stream, const char *str, size_t str_len);
111 zlog_bool zlog_stream_finish(struct zlog_stream *stream);
112 void zlog_stream_destroy(struct zlog_stream *stream);
113 zlog_bool zlog_stream_close(struct zlog_stream *stream);
114 
115 /* default log limit */
116 #define ZLOG_DEFAULT_LIMIT 1024
117 /* minimum log limit */
118 #define ZLOG_MIN_LIMIT 512
119 /* default log buffering */
120 #define ZLOG_DEFAULT_BUFFERING 1
121 
122 #endif
123