Пример #1
0
/**
 * Log a message to the server plugin.
 *
 * @param[in] ib_logger The IronBee logger.
 * @param[in] rec The record to use in logging.
 * @param[in] log_msg The user's log message.
 * @param[in] log_msg_sz The user's log message size.
 * @param[out] writer_record Unused. We always return IB_DECLINED.
 * @param[in] cbdata The server plugin module data used for logging.
 *
 * @returns
 * - IB_DECLINED when everything goes well.
 * - IB_OK is not returned.
 * - Other on error.
 */
static ib_status_t logger_format(
    ib_logger_t           *ib_logger,
    const ib_logger_rec_t *rec,
    const uint8_t         *log_msg,
    const size_t           log_msg_sz,
    void                  *writer_record,
    void                  *cbdata
)
{
    assert(ib_logger != NULL);
    assert(rec != NULL);
    assert(log_msg != NULL);
    assert(cbdata != NULL);

    if (cbdata == NULL) {
        return IB_DECLINED;
    }

    module_data_t   *mod_data = (module_data_t *)cbdata;
    TSTextLogObject  logger = mod_data->logger;

    if (logger == NULL) {
        return IB_DECLINED;
    }
    if (log_msg == NULL || log_msg_sz == 0) {
        TSTextLogObjectFlush(logger);
    }
    else {

        ib_logger_standard_msg_t *std_msg = NULL;

        ib_status_t rc = ib_logger_standard_formatter_notime(
            ib_logger,
            rec,
            log_msg,
            log_msg_sz,
            &std_msg,
            NULL);
        if (rc != IB_OK) {
            return rc;
        }

        TSTextLogObjectWrite(
            logger,
            "%s %.*s",
            std_msg->prefix,
            (int)std_msg->msg_sz,
            (const char *)std_msg->msg);

        ib_logger_standard_msg_free(ib_logger, std_msg, cbdata);
    }

    return IB_DECLINED;
}
Пример #2
0
/**
 * Log a message to the server plugin.
 *
 * @param[in] ib_logger The IronBee logger.
 * @param[in] rec The record to use in logging.
 * @param[in] log_msg The user's log message.
 * @param[in] log_msg_sz The user's log message size.
 * @param[out] writer_record Unused. We always return IB_DECLINED.
 * @param[in] cbdata The server plugin module data used for logging.
 *
 * @returns
 * - IB_DECLINED when everything goes well.
 * - IB_OK is not returned.
 * - Other on error.
 */
static ib_status_t logger_format(
    ib_logger_t           *logger,
    const ib_logger_rec_t *rec,
    const uint8_t         *log_msg,
    const size_t           log_msg_sz,
    void                  *writer_record,
    void                  *cbdata
)
{
    assert(logger != NULL);
    assert(rec != NULL);
    assert(log_msg != NULL);
    assert(cbdata != NULL);

    module_data_t            *mod_data = (module_data_t *)cbdata;
    unsigned int              ngx_level;
    ib_status_t               rc;
    ib_logger_standard_msg_t *std_msg;

    if (!mod_data->ib_log_active) {
        return IB_OK;
    }

    /* Translate the log level. */
    switch (rec->level) {
    case IB_LOG_EMERGENCY:
        ngx_level = NGX_LOG_EMERG;
        break;
    case IB_LOG_ALERT:
        ngx_level = NGX_LOG_ALERT;
        break;
    case IB_LOG_CRITICAL:
        ngx_level = NGX_LOG_CRIT;
        break;
    case IB_LOG_ERROR:
        ngx_level = NGX_LOG_ERR;
        break;
    case IB_LOG_WARNING:
        ngx_level = NGX_LOG_WARN;
        break;
    case IB_LOG_NOTICE:
        ngx_level = NGX_LOG_NOTICE;
        break;
    case IB_LOG_INFO:
        ngx_level = NGX_LOG_INFO;
        break;
    case IB_LOG_DEBUG:
    case IB_LOG_DEBUG2:
    case IB_LOG_DEBUG3:
    case IB_LOG_TRACE:
    default:
        ngx_level = NGX_LOG_DEBUG;
        break;
    }

    rc = ib_logger_standard_formatter(
          logger,
          rec,
          log_msg,
          log_msg_sz,
          &std_msg,
          NULL);
    if (rc != IB_OK) {
        return rc;
    }

    if (rec->conn != NULL) {
        ngx_connection_t *conn = (ngx_connection_t *)(rec->conn->server_ctx);
        ngx_log_error(ngx_level, conn->log, 0, "ironbee: %s %*.s",
                      std_msg->prefix, (int)std_msg->msg_sz,
                      (const char *)std_msg->msg);
    }
    else {
        ngx_log_error(ngx_level, mod_data->log, 0, "ironbee: %s %*.s",
                      std_msg->prefix, (int)std_msg->msg_sz,
                      (const char *)std_msg->msg);
    }

    ib_logger_standard_msg_free(std_msg);

    /* since we do all the work here, signal the logger to not
     * use the record function. */
    return IB_DECLINED;
}