static ngx_int_t
ngx_rtmp_log_flush(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
                   ngx_chain_t *in)
{
    ngx_rtmp_log_app_conf_t    *lacf;
    ngx_rtmp_log_t             *log;
    ngx_rtmp_log_op_t          *op;
    ngx_uint_t                  n, i;
    u_char                     *line, *p;
    size_t                      len;

    if (s->auto_pushed || s->relay) {
        return NGX_OK;
    }

    lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_log_module);
    if (lacf == NULL || lacf->off || lacf->logs == NULL) {
        return NGX_OK;
    }

    log = lacf->logs->elts;
    for (i = 0; i < lacf->logs->nelts; ++i, ++log) {

        if (ngx_time() == log->disk_full_time) {
            /* FreeBSD full disk protection;
             * nginx http logger does the same */
            continue;
        }

        len = 0;
        op = log->format->ops->elts;
        for (n = 0; n < log->format->ops->nelts; ++n, ++op) {
            len += op->getlen(s, op);
        }

        len += NGX_LINEFEED_SIZE;

        line = ngx_palloc(s->connection->pool, len);
        if (line == NULL) {
            return NGX_OK;
        }

        p = line;
        op = log->format->ops->elts;
        for (n = 0; n < log->format->ops->nelts; ++n, ++op) {
            p = op->getdata(s, p, op);
        }

        ngx_linefeed(p);

        ngx_rtmp_log_write(s, log, line, p - line);
    }

    return NGX_OK;
}
static void
ngx_rtmp_log_pre_write(ngx_rtmp_session_t *s, ngx_rtmp_log_t *log)
{
    ngx_rtmp_log_op_t          *op;
    u_char                      line[MAX_ACCESS_LOG_LINE_LEN], *p;
    size_t                      len;
    ngx_uint_t                  n;

    if (ngx_time() == log->disk_full_time) {
        /* FreeBSD full disk protection;
         * nginx http logger does the same */
        return;
    }

    len = 0;
    op = log->format->ops->elts;
    for (n = 0; n < log->format->ops->nelts; ++n, ++op) {
        len += op->getlen(s, op);
    }
    len += NGX_LINEFEED_SIZE;

    if (len > MAX_ACCESS_LOG_LINE_LEN) {
        ngx_log_error(NGX_LOG_ERR, s->log, 0,
                "Access line len %z greater than %d",
                len, MAX_ACCESS_LOG_LINE_LEN);
        ngx_rtmp_finalize_session(s);

        return;
    }

    p = line;
    op = log->format->ops->elts;
    for (n = 0; n < log->format->ops->nelts; ++n, ++op) {
        p = op->getdata(s, p, op);
    }

    ngx_linefeed(p);

    ngx_rtmp_log_write(s, log, line, p - line);
}