Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_LOG_H_INCLUDED_
0009 #define _NGX_LOG_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 #define NGX_LOG_STDERR            0
0017 #define NGX_LOG_EMERG             1
0018 #define NGX_LOG_ALERT             2
0019 #define NGX_LOG_CRIT              3
0020 #define NGX_LOG_ERR               4
0021 #define NGX_LOG_WARN              5
0022 #define NGX_LOG_NOTICE            6
0023 #define NGX_LOG_INFO              7
0024 #define NGX_LOG_DEBUG             8
0025 
0026 #define NGX_LOG_DEBUG_CORE        0x010
0027 #define NGX_LOG_DEBUG_ALLOC       0x020
0028 #define NGX_LOG_DEBUG_MUTEX       0x040
0029 #define NGX_LOG_DEBUG_EVENT       0x080
0030 #define NGX_LOG_DEBUG_HTTP        0x100
0031 #define NGX_LOG_DEBUG_MAIL        0x200
0032 #define NGX_LOG_DEBUG_STREAM      0x400
0033 
0034 /*
0035  * do not forget to update debug_levels[] in src/core/ngx_log.c
0036  * after the adding a new debug level
0037  */
0038 
0039 #define NGX_LOG_DEBUG_FIRST       NGX_LOG_DEBUG_CORE
0040 #define NGX_LOG_DEBUG_LAST        NGX_LOG_DEBUG_STREAM
0041 #define NGX_LOG_DEBUG_CONNECTION  0x80000000
0042 #define NGX_LOG_DEBUG_ALL         0x7ffffff0
0043 
0044 
0045 typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len);
0046 typedef void (*ngx_log_writer_pt) (ngx_log_t *log, ngx_uint_t level,
0047     u_char *buf, size_t len);
0048 
0049 
0050 struct ngx_log_s {
0051     ngx_uint_t           log_level;
0052     ngx_open_file_t     *file;
0053 
0054     ngx_atomic_uint_t    connection;
0055 
0056     time_t               disk_full_time;
0057 
0058     ngx_log_handler_pt   handler;
0059     void                *data;
0060 
0061     ngx_log_writer_pt    writer;
0062     void                *wdata;
0063 
0064     /*
0065      * we declare "action" as "char *" because the actions are usually
0066      * the static strings and in the "u_char *" case we have to override
0067      * their types all the time
0068      */
0069 
0070     char                *action;
0071 
0072     ngx_log_t           *next;
0073 };
0074 
0075 
0076 #define NGX_MAX_ERROR_STR   2048
0077 
0078 
0079 /*********************************/
0080 
0081 #if (NGX_HAVE_C99_VARIADIC_MACROS)
0082 
0083 #define NGX_HAVE_VARIADIC_MACROS  1
0084 
0085 #define ngx_log_error(level, log, ...)                                        \
0086     if ((log)->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__)
0087 
0088 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
0089     const char *fmt, ...);
0090 
0091 #define ngx_log_debug(level, log, ...)                                        \
0092     if ((log)->log_level & level)                                             \
0093         ngx_log_error_core(NGX_LOG_DEBUG, log, __VA_ARGS__)
0094 
0095 /*********************************/
0096 
0097 #elif (NGX_HAVE_GCC_VARIADIC_MACROS)
0098 
0099 #define NGX_HAVE_VARIADIC_MACROS  1
0100 
0101 #define ngx_log_error(level, log, args...)                                    \
0102     if ((log)->log_level >= level) ngx_log_error_core(level, log, args)
0103 
0104 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
0105     const char *fmt, ...);
0106 
0107 #define ngx_log_debug(level, log, args...)                                    \
0108     if ((log)->log_level & level)                                             \
0109         ngx_log_error_core(NGX_LOG_DEBUG, log, args)
0110 
0111 /*********************************/
0112 
0113 #else /* no variadic macros */
0114 
0115 #define NGX_HAVE_VARIADIC_MACROS  0
0116 
0117 void ngx_cdecl ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
0118     const char *fmt, ...);
0119 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
0120     const char *fmt, va_list args);
0121 void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
0122     const char *fmt, ...);
0123 
0124 
0125 #endif /* variadic macros */
0126 
0127 
0128 /*********************************/
0129 
0130 #if (NGX_DEBUG)
0131 
0132 #if (NGX_HAVE_VARIADIC_MACROS)
0133 
0134 #define ngx_log_debug0(level, log, err, fmt)                                  \
0135         ngx_log_debug(level, log, err, fmt)
0136 
0137 #define ngx_log_debug1(level, log, err, fmt, arg1)                            \
0138         ngx_log_debug(level, log, err, fmt, arg1)
0139 
0140 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2)                      \
0141         ngx_log_debug(level, log, err, fmt, arg1, arg2)
0142 
0143 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)                \
0144         ngx_log_debug(level, log, err, fmt, arg1, arg2, arg3)
0145 
0146 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)          \
0147         ngx_log_debug(level, log, err, fmt, arg1, arg2, arg3, arg4)
0148 
0149 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)    \
0150         ngx_log_debug(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
0151 
0152 #define ngx_log_debug6(level, log, err, fmt,                                  \
0153                        arg1, arg2, arg3, arg4, arg5, arg6)                    \
0154         ngx_log_debug(level, log, err, fmt,                                   \
0155                        arg1, arg2, arg3, arg4, arg5, arg6)
0156 
0157 #define ngx_log_debug7(level, log, err, fmt,                                  \
0158                        arg1, arg2, arg3, arg4, arg5, arg6, arg7)              \
0159         ngx_log_debug(level, log, err, fmt,                                   \
0160                        arg1, arg2, arg3, arg4, arg5, arg6, arg7)
0161 
0162 #define ngx_log_debug8(level, log, err, fmt,                                  \
0163                        arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)        \
0164         ngx_log_debug(level, log, err, fmt,                                   \
0165                        arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
0166 
0167 
0168 #else /* no variadic macros */
0169 
0170 #define ngx_log_debug0(level, log, err, fmt)                                  \
0171     if ((log)->log_level & level)                                             \
0172         ngx_log_debug_core(log, err, fmt)
0173 
0174 #define ngx_log_debug1(level, log, err, fmt, arg1)                            \
0175     if ((log)->log_level & level)                                             \
0176         ngx_log_debug_core(log, err, fmt, arg1)
0177 
0178 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2)                      \
0179     if ((log)->log_level & level)                                             \
0180         ngx_log_debug_core(log, err, fmt, arg1, arg2)
0181 
0182 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)                \
0183     if ((log)->log_level & level)                                             \
0184         ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3)
0185 
0186 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)          \
0187     if ((log)->log_level & level)                                             \
0188         ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4)
0189 
0190 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)    \
0191     if ((log)->log_level & level)                                             \
0192         ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5)
0193 
0194 #define ngx_log_debug6(level, log, err, fmt,                                  \
0195                        arg1, arg2, arg3, arg4, arg5, arg6)                    \
0196     if ((log)->log_level & level)                                             \
0197         ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
0198 
0199 #define ngx_log_debug7(level, log, err, fmt,                                  \
0200                        arg1, arg2, arg3, arg4, arg5, arg6, arg7)              \
0201     if ((log)->log_level & level)                                             \
0202         ngx_log_debug_core(log, err, fmt,                                     \
0203                        arg1, arg2, arg3, arg4, arg5, arg6, arg7)
0204 
0205 #define ngx_log_debug8(level, log, err, fmt,                                  \
0206                        arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)        \
0207     if ((log)->log_level & level)                                             \
0208         ngx_log_debug_core(log, err, fmt,                                     \
0209                        arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
0210 
0211 #endif
0212 
0213 #else /* !NGX_DEBUG */
0214 
0215 #define ngx_log_debug0(level, log, err, fmt)
0216 #define ngx_log_debug1(level, log, err, fmt, arg1)
0217 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
0218 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)
0219 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)
0220 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
0221 #define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
0222 #define ngx_log_debug7(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5,    \
0223                        arg6, arg7)
0224 #define ngx_log_debug8(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5,    \
0225                        arg6, arg7, arg8)
0226 
0227 #endif
0228 
0229 /*********************************/
0230 
0231 ngx_log_t *ngx_log_init(u_char *prefix);
0232 void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
0233 void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
0234 u_char *ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err);
0235 ngx_int_t ngx_log_open_default(ngx_cycle_t *cycle);
0236 ngx_int_t ngx_log_redirect_stderr(ngx_cycle_t *cycle);
0237 ngx_log_t *ngx_log_get_file_log(ngx_log_t *head);
0238 char *ngx_log_set_log(ngx_conf_t *cf, ngx_log_t **head);
0239 
0240 
0241 /*
0242  * ngx_write_stderr() cannot be implemented as macro, since
0243  * MSVC does not allow to use #ifdef inside macro parameters.
0244  *
0245  * ngx_write_fd() is used instead of ngx_write_console(), since
0246  * CharToOemBuff() inside ngx_write_console() cannot be used with
0247  * read only buffer as destination and CharToOemBuff() is not needed
0248  * for ngx_write_stderr() anyway.
0249  */
0250 static ngx_inline void
0251 ngx_write_stderr(char *text)
0252 {
0253     (void) ngx_write_fd(ngx_stderr, text, ngx_strlen(text));
0254 }
0255 
0256 
0257 static ngx_inline void
0258 ngx_write_stdout(char *text)
0259 {
0260     (void) ngx_write_fd(ngx_stdout, text, ngx_strlen(text));
0261 }
0262 
0263 
0264 extern ngx_module_t  ngx_errlog_module;
0265 extern ngx_uint_t    ngx_use_stderr;
0266 
0267 
0268 #endif /* _NGX_LOG_H_INCLUDED_ */