コンテンツにスキップ
Kong Logo | Kong Docs Logo
  • ドキュメント
    • API仕様を確認する
      View all API Specs すべてのAPI仕様を表示 View all API Specs arrow image
    • ドキュメンテーション
      API Specs
      Kong Gateway
      軽量、高速、柔軟なクラウドネイティブAPIゲートウェイ
      Kong Konnect
      SaaSのエンドツーエンド接続のための単一プラットフォーム
      Kong AI Gateway
      GenAI インフラストラクチャ向けマルチ LLM AI Gateway
      Kong Mesh
      Kuma と Envoy をベースにしたエンタープライズサービスメッシュ
      decK
      Kongの構成を宣言型で管理する上で役立ちます
      Kong Ingress Controller
      Kubernetesクラスタ内で動作し、Kongをプロキシトラフィックに設定する
      Kong Gateway Operator
      YAMLマニフェストを使用してKubernetes上のKongデプロイメントを管理する
      Insomnia
      コラボレーティブAPI開発プラットフォーム
  • Plugin Hub
    • Plugin Hubを探索する
      View all plugins すべてのプラグインを表示 View all plugins arrow image
    • 機能性 すべて表示 View all arrow image
      すべてのプラグインを表示
      AI's icon
      AI
      マルチ LLM AI Gatewayプラグインを使用してAIトラフィックを管理、保護、制御する
      認証's icon
      認証
      認証レイヤーでサービスを保護する
      セキュリティ's icon
      セキュリティ
      追加のセキュリティレイヤーでサービスを保護する
      トラフィック制御's icon
      トラフィック制御
      インバウンドおよびアウトバウンドAPIトラフィックの管理、スロットル、制限
      サーバーレス's icon
      サーバーレス
      他のプラグインと組み合わせてサーバーレス関数を呼び出します
      分析と監視's icon
      分析と監視
      APIとマイクロサービストラフィックを視覚化、検査、監視
      変革's icon
      変革
      Kongでリクエストとレスポンスをその場で変換
      ログ記録's icon
      ログ記録
      インフラストラクチャに最適なトランスポートを使用して、リクエストと応答データをログに記録します
  • サポート
  • コミュニティ
  • Kongアカデミー
デモを見る 無料トライアルを開始
Kong Gateway
3.9.x
  • Home icon
  • Kong Gateway
  • Plugin Development
  • PDK
  • kong.log
report-issue問題を報告する
  • Kong Gateway
  • Kong Konnect
  • Kong Mesh
  • Kong AI Gateway
  • Plugin Hub
  • decK
  • Kong Ingress Controller
  • Kong Gateway Operator
  • Insomnia
  • Kuma

  • ドキュメント投稿ガイドライン
  • 3.10.x (latest)
  • 3.9.x
  • 3.8.x
  • 3.7.x
  • 3.6.x
  • 3.5.x
  • 3.4.x (LTS)
  • 3.3.x
  • 2.8.x (LTS)
  • アーカイブ (2.6より前)
  • Introduction
    • Overview of Kong Gateway
    • Support
      • Version Support Policy
      • Third Party Dependencies
      • Browser Support
      • Vulnerability Patching Process
      • Software Bill of Materials
    • Stability
    • Release Notes
    • Breaking Changes
      • Kong Gateway 3.9.x
      • Kong Gateway 3.8.x
      • Kong Gateway 3.7.x
      • Kong Gateway 3.6.x
      • Kong Gateway 3.5.x
      • Kong Gateway 3.4.x
      • Kong Gateway 3.3.x
      • Kong Gateway 3.2.x
      • Kong Gateway 3.1.x
      • Kong Gateway 3.0.x
      • Kong Gateway 2.8.x or earlier
    • Key Concepts
      • Services
      • Routes
      • Consumers
      • Upstreams
      • Plugins
      • Consumer Groups
    • How Kong Works
      • Routing Traffic
      • Load Balancing
      • Health Checks and Circuit Breakers
    • Glossary
  • Get Started with Kong
    • Get Kong
    • Services and Routes
    • Rate Limiting
    • Proxy Caching
    • Key Authentication
    • Load-Balancing
  • Install Kong
    • Overview
    • Kubernetes
      • Overview
      • Install Kong Gateway
      • Configure the Admin API
      • Install Kong Manager
    • Docker
      • Using docker run
      • Build your own Docker images
    • Linux
      • Amazon Linux
      • Debian
      • Red Hat
      • Ubuntu
    • Post-installation
      • Set up a data store
      • Apply Enterprise license
      • Enable Kong Manager
  • Kong in Production
    • Deployment Topologies
      • Overview
      • Kubernetes Topologies
      • Hybrid Mode
        • Overview
        • Deploy Kong Gateway in Hybrid mode
      • DB-less Deployment
      • Traditional
    • Running Kong
      • Running Kong as a non-root user
      • Securing the Admin API
      • Using systemd
    • Access Control
      • Start Kong Gateway Securely
      • Programatically Creating Admins
      • Enabling RBAC
    • Licenses
      • Overview
      • Download your License
      • Deploy Enterprise License
      • Using the License API
      • Monitor Licenses Usage
    • Networking
      • Default Ports
      • DNS Considerations
      • Network and Firewall
      • CP/DP Communication through a Forward Proxy
      • PostgreSQL TLS
        • Configure PostgreSQL TLS
        • Troubleshooting PostgreSQL TLS
    • Kong Configuration File
    • Environment Variables
    • Serving a Website and APIs from Kong
    • Monitoring
      • Overview
      • Prometheus
      • StatsD
      • Datadog
      • Health Check Probes
      • Expose and graph AI Metrics
    • Tracing
      • Overview
      • Writing a Custom Trace Exporter
      • Tracing API Reference
    • Resource Sizing Guidelines
    • Blue-Green Deployments
    • Canary Deployments
    • Clustering Reference
    • Performance
      • Performance Testing Benchmarks
      • Establish a Performance Benchmark
      • Improve performance with Brotli compression
    • Logging and Debugging
      • Log Reference
      • Dynamic log level updates
      • Customize Gateway Logs
      • Debug Requests
      • AI Gateway Analytics
    • Configure a gRPC service
    • Use the Expressions Router
    • Upgrade and Migration
      • Upgrading Kong Gateway 3.x.x
      • Backup and Restore
      • Upgrade Strategies
        • Dual-Cluster Upgrade
        • In-Place Upgrade
        • Blue-Green Upgrade
        • Rolling Upgrade
      • Upgrade from 2.8 LTS to 3.4 LTS
      • Migrate from OSS to Enterprise
      • Migration Guidelines Cassandra to PostgreSQL
      • Migrate to the new DNS client
      • Breaking Changes
  • Kong Gateway Enterprise
    • Overview
    • Secrets Management
      • Overview
      • Getting Started
      • Secrets Rotation
      • Advanced Usage
      • Backends
        • Overview
        • Environment Variables
        • AWS Secrets Manager
        • Azure Key Vaults
        • Google Cloud Secret Manager
        • HashiCorp Vault
      • How-To
        • Securing the Database with AWS Secrets Manager
      • Reference Format
    • Dynamic Plugin Ordering
      • Overview
      • Get Started with Dynamic Plugin Ordering
    • Audit Logging
    • Keyring and Data Encryption
    • Workspaces
    • Consumer Groups
    • Event Hooks
    • Configure Data Plane Resilience
    • About Control Plane Outage Management
    • FIPS 140-2
      • Overview
      • Install the FIPS Compliant Package
    • Authenticate your Kong Gateway Amazon RDS database with AWS IAM
    • Verify Signatures for Signed Kong Images
    • Verify Build Provenance for Signed Kong Images
    • Datakit
      • Overview
      • Get Started with Datakit
      • Datakit Configuration Reference
      • Datakit Examples Reference
  • Kong AI Gateway
    • Overview
    • Get started with AI Gateway
    • LLM Provider Integration Guides
      • OpenAI
      • Cohere
      • Azure
      • Anthropic
      • Mistral
      • Llama2
      • Vertex/Gemini
      • Amazon Bedrock
    • LLM Library Integration Guides
      • LangChain
    • AI Gateway Analytics
    • Expose and graph AI Metrics
    • AI Gateway Load Balancing
    • AI Gateway plugins
  • Kong Manager
    • Overview
    • Enable Kong Manager
    • Get Started with Kong Manager
      • Services and Routes
      • Rate Limiting
      • Proxy Caching
      • Authentication with Consumers
      • Load Balancing
    • Authentication and Authorization
      • Overview
      • Create a Super Admin
      • Workspaces and Teams
      • Reset Passwords and RBAC Tokens
      • Basic Auth
      • LDAP
        • Configure LDAP
        • LDAP Service Directory Mapping
      • OIDC
        • Configure OIDC
        • OIDC Authenticated Group Mapping
        • Migrate from previous configurations
      • Sessions
      • RBAC
        • Overview
        • Enable RBAC
        • Add a Role and Permissions
        • Create a User
        • Create an Admin
    • Networking Configuration
    • Workspaces
    • Create Consumer Groups
    • Sending Email
    • Troubleshoot
  • Develop Custom Plugins
    • Overview
    • Getting Started
      • Introduction
      • Set up the Plugin Project
      • Add Plugin Testing
      • Add Plugin Configuration
      • Consume External Services
      • Deploy Plugins
    • File Structure
    • Implementing Custom Logic
    • Plugin Configuration
    • Accessing the Data Store
    • Storing Custom Entities
    • Caching Custom Entities
    • Extending the Admin API
    • Writing Tests
    • Installation and Distribution
    • Proxy-Wasm Filters
      • Create a Proxy-Wasm Filter
      • Proxy-Wasm Filter Configuration
    • Plugin Development Kit
      • Overview
      • kong.client
      • kong.client.tls
      • kong.cluster
      • kong.ctx
      • kong.ip
      • kong.jwe
      • kong.log
      • kong.nginx
      • kong.node
      • kong.plugin
      • kong.request
      • kong.response
      • kong.router
      • kong.service
      • kong.service.request
      • kong.service.response
      • kong.table
      • kong.telemetry.log
      • kong.tracing
      • kong.vault
      • kong.websocket.client
      • kong.websocket.upstream
    • Plugins in Other Languages
      • Go
      • Javascript
      • Python
      • Running Plugins in Containers
      • External Plugin Performance
  • Kong Plugins
    • Overview
    • Authentication Reference
    • Allow Multiple Authentication Plugins
    • Plugin Queuing
      • Overview
      • Plugin Queuing Reference
  • Admin API
    • Overview
    • Declarative Configuration
    • Enterprise API
      • Information Routes
      • Health Routes
      • Tags
      • Debug Routes
      • Services
      • Routes
      • Consumers
      • Plugins
      • Certificates
      • CA Certificates
      • SNIs
      • Upstreams
      • Targets
      • Vaults
      • Keys
      • Filter Chains
      • Licenses
      • Workspaces
      • RBAC
      • Admins
      • Consumer Groups
      • Event Hooks
      • Keyring and Data Encryption
      • Audit Logs
      • Status API
    • Open Source API
  • Reference
    • kong.conf
    • Injecting Nginx Directives
    • CLI
    • Key Management
    • The Expressions Language
      • Overview
      • Language References
      • Performance Optimizations
    • Rate Limiting Library
    • WebAssembly
    • Reserved Entity Names
    • FAQ
enterprise-switcher-icon 次に切り替える: OSS
On this pageOn this page
  • kong.log(…)
  • kong.log.LEVEL(…)
  • kong.log.deprecation(…)
  • kong.log.inspect(…)
  • kong.log.inspect.on()
  • kong.log.inspect.off()
  • kong.log.set_serialize_value(key, value, options)
  • kong.log.serialize()

このページは、まだ日本語ではご利用いただけません。翻訳中です。

旧バージョンのドキュメントを参照しています。 最新のドキュメントはこちらをご参照ください。

kong.log

This namespace contains an instance of a logging facility, which is a table containing all of the methods described below.

This instance is namespaced per plugin. Before executing a plugin, Kong swaps this instance with a logging facility dedicated to the plugin. This allows the logs to be prefixed with the plugin’s name for debugging purposes.

kong.log(…)

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 parameters 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()

kong.log.LEVEL(…)

Similar to kong.log(), but the produced log has the severity given by <level>, instead of notice. The supported levels are:

  • kong.log.alert()
  • kong.log.crit()
  • kong.log.err()
  • kong.log.warn()
  • kong.log.notice()
  • kong.log.info()
  • kong.log.debug()

Logs have the same format as that of kong.log(). For example, the following call:

  kong.log.err("hello ", "world")

would, within the core, produce a log line similar to:

 2017/07/09 19:36:25 [error] 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 [error] 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.warn("something require attention")
kong.log.err("something failed: ", err)
kong.log.alert("something requires immediate action")

kong.log.deprecation(…)

Write a deprecation log line (similar to kong.log.warn).

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). When the last argument is a table, it is considered as a deprecation metadata. The table can include the following properties:

 {
   after = "2.5.0",   -- deprecated after Kong version 2.5.0 (defaults to `nil`)
   removal = "3.0.0", -- about to be removed with Kong version 3.0.0 (defaults to `nil`)
   trace = true,      -- writes stack trace along with the deprecation message (defaults to `nil`)
 }

For example, the following call:

 kong.log.deprecation("hello ", "world")

would, within the core, produce a log line similar to:

 2017/07/09 19:36:25 [warn] 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 [warn] 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"

And with metatable, the following call:

 kong.log.deprecation("hello ", "world", { after = "2.5.0", removal = "3.0.0" })

would, within the core, produce a log line similar to:

 2017/07/09 19:36:25 [warn] 25932#0: *1 [kong] some_file.lua:54 hello world (deprecated after 2.5.0, scheduled for removal in 3.0.0), 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 (if the last param is a table, it is considered as a deprecation metadata)

Returns

  • Nothing; throws an error on invalid inputs.

Usage

kong.log.deprecation("hello ", "world")
kong.log.deprecation("hello ", "world", { after = "2.5.0" })
kong.log.deprecation("hello ", "world", { removal = "3.0.0" })
kong.log.deprecation("hello ", "world", { after = "2.5.0", removal = "3.0.0" })
kong.log.deprecation("hello ", "world", { trace = true })

kong.log.inspect(…)

Like kong.log(), this function produces a log with a notice level and accepts any number of arguments. If inspect logging is disabled via kong.log.inspect.off(), then this function prints nothing, and is aliased to a “NOP” function to save CPU cycles.

This function differs from kong.log() in the sense that arguments will be concatenated with a space(" "), and each argument is pretty-printed:

  • Numbers are printed (e.g. 5 -> "5")
  • Strings are quoted (e.g. "hi" -> '"hi"')
  • Array-like tables are rendered (e.g. {1,2,3} -> "{1, 2, 3}")
  • Dictionary-like tables are rendered on multiple lines

This function is intended for debugging, and usage in production code paths should be avoided due to the expensive formatting operations it can perform. Existing statements can be left in production code but nopped by calling kong.log.inspect.off().

When writing logs, kong.log.inspect() always uses its own format, defined as:

 %file_src:%func_name:%line_src %message

Where:

  • %file_src: The filename the log was called from.
  • %func_name: The name of the function the log was called from.
  • %line_src: The line number the log was called from.
  • %message: The message, made of concatenated, pretty-printed arguments given by the caller.

This function uses the inspect.lua library to pretty-print its arguments.

Phases

  • init_worker, certificate, rewrite, access, header_filter, response, body_filter, log

Parameters

  • … : Parameters are concatenated with spaces between them and rendered as described.

Usage

kong.log.inspect("some value", a_variable)

kong.log.inspect.on()

Enables inspect logs for this logging facility. Calls to kong.log.inspect will be writing log lines with the appropriate formatting of arguments.

Phases

  • init_worker, certificate, rewrite, access, header_filter, response, body_filter, log

Usage

kong.log.inspect.on()

kong.log.inspect.off()

Disables inspect logs for this logging facility. All calls to kong.log.inspect() will be nopped.

Phases

  • init_worker, certificate, rewrite, access, header_filter, response, body_filter, log

Usage

kong.log.inspect.off()

kong.log.set_serialize_value(key, value, options)

Sets a value to be used on the serialize custom table.

Logging plugins use the output of kong.log.serialize() as a base for their logs. This function lets you customize the log output.

It can be used to replace existing values in the output, or to delete existing values by passing nil.

Note: The type-checking of the value parameter can take some time, so it is deferred to the serialize() call, which happens in the log phase in most real-usage cases.

Phases

  • certificate, rewrite, access, header_filter, response, body_filter, log

Parameters

  • key (string): The name of the field.
  • value (number|string|boolean|table): Value to be set. When a table is used, its keys must be numbers, strings, or booleans, and its values can be numbers, strings, or other tables like itself, recursively.
  • options (table): Can contain two entries: options.mode can be set (the default, always sets), add (only add if entry does not already exist) and replace (only change value if it already exists).

Returns

  • table: The request information table.

Usage

-- Adds a new value to the serialized table
kong.log.set_serialize_value("my_new_value", 1)
assert(kong.log.serialize().my_new_value == 1)

-- Value can be a table
kong.log.set_serialize_value("my", { new = { value = 2 } })
assert(kong.log.serialize().my.new.value == 2)

-- It is possible to change an existing serialized value
kong.log.set_serialize_value("my_new_value", 3)
assert(kong.log.serialize().my_new_value == 3)

-- Unset an existing value by setting it to nil
kong.log.set_serialize_value("my_new_value", nil)
assert(kong.log.serialize().my_new_value == nil)

-- Dots in the key are interpreted as table accesses
kong.log.set_serialize_value("my.new.value", 4)
assert(kong.log.serialize().my.new.value == 4)


kong.log.serialize()

Generates a table with useful information for logging.

This method can be used in the http subsystem.

The following fields are included in the returned table:

  • client_ip - client IP address in textual format.
  • latencies - request/proxy latencies.

  • request.id - request id.

  • request.headers - request headers.
  • request.method - request method.
  • request.querystring - request query strings.
  • request.size - size of request.
  • request.url and request.uri - URL and URI of request.
  • response.headers - response headers.
  • response.size - size of response.
  • response.status - response HTTP status code.
  • route - route object matched.
  • service - service object used.
  • started_at - timestamp this request came in, in milliseconds.
  • tries - Upstream information; this is an array and if any balancer retries occurred, will contain more than one entry.
  • upstream_uri - request URI sent to Upstream.

The following fields are only present in an authenticated request (with consumer):

  • authenticated_entity - credential used for authentication.
  • consumer - consumer entity accessing the resource.

The following fields are only present in a TLS/HTTPS request:

  • request.tls.version - TLS/SSL version used by the connection.
  • request.tls.cipher - TLS/SSL cipher used by the connection.
  • request.tls.client_verify - mTLS validation result. Contents are the same as described in $ssl_client_verify.

The following field is only present in requests where a tracing plugin (OpenTelemetry or Zipkin) is executed:

  • trace_id - trace ID.

The following field is only present in requests where the Correlation ID plugin is executed:

  • correlation_id - correlation ID.

Warning: This function may return sensitive data (e.g., API keys). Consider filtering before writing it to unsecured locations.

All fields in the returned table may be altered using kong.log.set_serialize_value.

The following HTTP authentication headers are redacted by default, if they appear in the request:

  • request.headers.authorization
  • request.headers.proxy-authorization

To see what content is present in your setup, enable any of the logging plugins (e.g., file-log) and the output written to the log file is the table returned by this function JSON-encoded.

Phases

  • log

Returns

  • table: the request information table

Usage

kong.log.serialize()
Thank you for your feedback.
Was this page useful?
情報が多すぎる場合 close cta icon
Kong Konnectを使用すると、より多くの機能とより少ないインフラストラクチャを実現できます。月額1Mリクエストが無料。
無料でお試しください
  • Kong
    APIの世界を動かす

    APIマネジメント、サービスメッシュ、イングレスコントローラーの統合プラットフォームにより、開発者の生産性、セキュリティ、パフォーマンスを大幅に向上します。

    • 製品
      • Kong Konnect
      • Kong Gateway Enterprise
      • Kong Gateway
      • Kong Mesh
      • Kong Ingress Controller
      • Kong Insomnia
      • 製品アップデート
      • 始める
    • ドキュメンテーション
      • Kong Konnectドキュメント
      • Kong Gatewayドキュメント
      • Kong Meshドキュメント
      • Kong Insomniaドキュメント
      • Kong Konnect Plugin Hub
    • オープンソース
      • Kong Gateway
      • Kuma
      • Insomnia
      • Kongコミュニティ
    • 会社概要
      • Kongについて
      • お客様
      • キャリア
      • プレス
      • イベント
      • お問い合わせ
  • 利用規約• プライバシー• 信頼とコンプライアンス
© Kong Inc. 2025