Writes a log line to the location specified by the current Nginx
configuration block’s error_log directive, with the notice level (similar
to print()).
The Nginx error_log directive is set via the log_level, proxy_error_log
and admin_error_log Kong configuration properties.
Arguments given to this function are concatenated similarly to
ngx.log(), and the log line reports the Lua file and line number from
which it was invoked. Unlike ngx.log(), this function prefixes error
messages with [kong] instead of [lua].
Arguments given to this function can be of any type, but table arguments
are converted to strings via tostring (thus potentially calling a
table’s __tostring metamethod if set). This behavior differs from
ngx.log() (which only accepts table arguments if they define the
__tostring metamethod) with the intent to simplify its usage and be more
forgiving and intuitive.
Produced log lines have the following format when logging is invoked from
within the core:
[kong] %file_src:%line_src %message
In comparison, log lines produced by plugins have the following format:
[kong] %file_src:%line_src [%namespace] %message
Where:
-
%namespace: The configured namespace (in this case, the plugin name).
-
%file_src: The filename the log was called from.
-
%line_src: The line number the log was called from.
-
%message: The message, made of concatenated arguments given by the caller.
For example, the following call:
kong.log("hello ", "world")
would, within the core, produce a log line similar to:
2017/07/09 19:36:25 [notice] 25932#0: *1 [kong] some_file.lua:54 hello world, client: 127.0.0.1, server: localhost, request: "GET /log HTTP/1.1", host: "localhost"
If invoked from within a plugin (for example, key-auth) it would include the
namespace prefix:
2017/07/09 19:36:25 [notice] 25932#0: *1 [kong] some_file.lua:54 [key-auth] hello world, client: 127.0.0.1, server: localhost, request: "GET /log HTTP/1.1", host: "localhost"
Phases
- init_worker, certificate, rewrite, access, header_filter, response, body_filter, log
Parameters
-
… : All params will be concatenated and stringified before being sent to the log.
Returns
- Nothing. Throws an error on invalid inputs.
Usage
kong.log("hello ", "world") -- alias to kong.log.notice()