zoukankan      html  css  js  c++  java
  • nginx 日志模块

    ngx_http_log_module.c

    数据结构

    typedef struct {
    void **main_conf;
    void **srv_conf;
    void **loc_conf;
    } ngx_http_conf_ctx_t;

    typedef struct ngx_http_log_op_s ngx_http_log_op_t;

    typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf,
    ngx_http_log_op_t *op);

    typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r,
    uintptr_t data);


    struct ngx_http_log_op_s {
    size_t len;
    ngx_http_log_op_getlen_pt getlen;
    ngx_http_log_op_run_pt run;
    uintptr_t data;
    };


    typedef struct {
    ngx_str_t name;
    ngx_array_t *flushes;
    ngx_array_t *ops; /* array of ngx_http_log_op_t */
    } ngx_http_log_fmt_t;


    typedef struct {
    ngx_array_t formats; /* array of ngx_http_log_fmt_t */
    ngx_uint_t combined_used; /* unsigned combined_used:1 */
    } ngx_http_log_main_conf_t;

    typedef struct {
    u_char *start;
    u_char *pos;
    u_char *last;

    ngx_event_t *event;
    ngx_msec_t flush;
    ngx_int_t gzip;
    } ngx_http_log_buf_t;


    typedef struct {
    ngx_array_t *lengths;
    ngx_array_t *values;
    } ngx_http_log_script_t;


    typedef struct {
    ngx_open_file_t *file;
    ngx_http_log_script_t *script;
    time_t disk_full_time;
    time_t error_log_time;
    ngx_http_log_fmt_t *format;
    } ngx_http_log_t;


    typedef struct {
    ngx_array_t *logs; /* array of ngx_http_log_t */

    ngx_open_file_cache_t *open_file_cache;
    time_t open_file_cache_valid;
    ngx_uint_t open_file_cache_min_uses;

    ngx_uint_t off; /* unsigned off:1 */
    } ngx_http_log_loc_conf_t;

    typedef struct {
    ngx_str_t name;
    size_t len;
    ngx_http_log_op_run_pt run;
    } ngx_http_log_var_t;

    typedef struct {
    ngx_str_t name;
    void *(*create_conf)(ngx_cycle_t *cycle);
    char *(*init_conf)(ngx_cycle_t *cycle, void *conf);
    } ngx_core_module_t;

    typedef struct {
    ngx_int_t (*preconfiguration)(ngx_conf_t *cf);
    ngx_int_t (*postconfiguration)(ngx_conf_t *cf);

    void *(*create_main_conf)(ngx_conf_t *cf);
    char *(*init_main_conf)(ngx_conf_t *cf, void *conf);

    void *(*create_srv_conf)(ngx_conf_t *cf); char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, void *conf);

    void *(*create_loc_conf)(ngx_conf_t *cf);
    char *(*merge_loc_conf)(ngx_conf_t *cf, void *prev, void *conf);
    } ngx_http_module_t;

    static ngx_http_module_t ngx_http_log_module_ctx = {
    NULL, /* preconfiguration */
    ngx_http_log_init, /* postconfiguration */

    ngx_http_log_create_main_conf, /* create main configuration */
    NULL, /* init main configuration */

    NULL, /* create server configuration */
    NULL, /* merge server configuration */

    ngx_http_log_create_loc_conf, /* create location configuration */
    ngx_http_log_merge_loc_conf /* merge location configuration */
    };

    #define NGX_MODULE_V1 0, 0, 0, 0, 0, 0, 1
    #define NGX_MODULE_V1_PADDING 0, 0, 0, 0, 0, 0, 0, 0

    struct ngx_module_s {
    ngx_uint_t ctx_index;
    ngx_uint_t index;

    ngx_uint_t spare0;
    ngx_uint_t spare1;
    ngx_uint_t spare2;
    ngx_uint_t spare3;

    ngx_uint_t version;

    void *ctx;
    ngx_command_t *commands;
    ngx_uint_t type;

    ngx_int_t (*init_master)(ngx_log_t *log);
    ngx_int_t (*init_module)(ngx_cycle_t *cycle);

    ngx_int_t (*init_process)(ngx_cycle_t *cycle);
    ngx_int_t (*init_thread)(ngx_cycle_t *cycle);
    void (*exit_thread)(ngx_cycle_t *cycle);
    void (*exit_process)(ngx_cycle_t *cycle);

    void (*exit_master)(ngx_cycle_t *cycle);

    uintptr_t spare_hook0;
    uintptr_t spare_hook1;
    uintptr_t spare_hook2;
    uintptr_t spare_hook3;
    uintptr_t spare_hook4;
    uintptr_t spare_hook5;
    uintptr_t spare_hook6;
    uintptr_t spare_hook7;
    };

    struct ngx_command_s {
    ngx_str_t name;
    ngx_uint_t type;
    char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
    ngx_uint_t conf;
    ngx_uint_t offset;
    void *post;
    };

    http:

    typedef struct {
    ngx_array_t servers; /* ngx_http_core_srv_conf_t */

    ngx_http_phase_engine_t phase_engine;

    ngx_hash_t headers_in_hash;

    ngx_hash_t variables_hash;
    ngx_array_t variables; /* ngx_http_variable_t */ ngx_uint_t ncaptures;

    ngx_uint_t server_names_hash_max_size;
    ngx_uint_t server_names_hash_bucket_size;

    ngx_uint_t variables_hash_max_size; ngx_uint_t variables_hash_bucket_size;

    ngx_hash_keys_arrays_t *variables_keys;

    ngx_array_t *ports;
    ngx_uint_t try_files; /* unsigned try_files:1 */

    ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
    } ngx_http_core_main_conf_t;

    typedef struct {
    unsigned len:28;

    unsigned valid:1;
    unsigned no_cacheable:1;
    unsigned not_found:1;
    unsigned escape:1;

    u_char *data;
    } ngx_variable_value_t;

    struct ngx_buf_s {
    u_char *pos;
    u_char *last;
    off_t file_pos;
    off_t file_last;

    u_char *start; /* start of buffer */
    u_char *end; /* end of buffer */ ngx_buf_tag_t tag;
    ngx_file_t *file;
    ngx_buf_t *shadow;


    /* the buf's content could be changed */
    unsigned temporary:1;

    /*
    * the buf's content is in a memory cache or in a read only memory
    * and must not be changed
    */
    unsigned memory:1;

    /* the buf's content is mmap()ed and must not be changed */
    unsigned mmap:1;

    unsigned recycled:1;
    unsigned in_file:1;
    unsigned flush:1;
    unsigned sync:1;
    unsigned last_buf:1;
    unsigned last_in_chain:1;

    unsigned last_shadow:1;
    unsigned temp_file:1;

    /* STUB */ int num;
    };

    struct ngx_chain_s {
    ngx_buf_t *buf;
    ngx_chain_t *next;
    };

  • 相关阅读:
    Sharding-JDBC多数据源动态切换
    U 盘安装 CentOS 7 时出现 No Caching mode page found 问题的解决
    sudo 密码直接添加到命令行以方便实现脚本自动化
    Python3 Windows 虚拟环境的若干问题
    20 张图让你彻底弄懂 HTTPS 原理!
    全网写得最好的分库分表之 Sharding-JDBC 中间件介绍
    以为线程池很简单,结果第一道题就被干趴下了!
    以为线程池很简单,没想到第一问就被干趴下了
    分布式事务,看这篇就够了!
    我是一个线程池
  • 原文地址:https://www.cnblogs.com/andyhe/p/3214720.html
Copyright © 2011-2022 走看看