ドキュメント

​
​

Development

User Acquisition

Monetization

産業

Cloud Code

Open Unity Dashboard

Cloud Code

LiveOps
​
​
Cloud Code
  • Overview
  • Get started
  • Server authority
  • Cloud Code C# modules
  • Cloud Code JavaScript scripts
  • Logging
    • Overview
    • Concepts
    • Tutorials
      • Emit logs
      • Retrieve logs
  • Use-case samples
  • Privacy and consent
  1. Cloud Code

ログの発行

Add custom logging statements to your Cloud Code scripts and modules to record debugging information.
読み終わるまでの所要時間 3 分
最終更新 9ヶ月前

Cloud Code スクリプト と モジュール からログを発行できます。

Cloud Code C# モジュール

Microsoft.Extensions.Logging
ライブラリ
を使用して、Cloud Code C# モジュール からログを発行できます。Cloud Code は、依存性注入 を通じて
ILogger
をリクエストするたびに、UGS Logger にコードを自動的に提供します。
以下のコードサンプルは、C# モジュールをインストルメント化するために行う必要があるすべてのことを示します。
using Microsoft.Extensions.Logging;using Unity.Services.CloudCode.Core;namespace CloudCodeModules;public class LoggingExample{ // Setting up the Dependency Injection. Cloud Code will inject a UGS Logger // into "_logger" which can then be used by all methods in this class private readonly ILogger<LoggingExample> _logger; public LoggingExample(ILogger<LoggingExample> logger) { _logger = logger; } [CloudCodeFunction("SayHello")] public string SayHello(IExecutionContext ctx, string name) { // Logging out a standard message _logger.LogDebug("received a request to SayHello"); // Logging out a templated message. The template variable "name" // will be available as a key-value pair inside the log attributes map. // Templated keys cannot use dot notation for namespacing. _logger.LogInformation("saying hello to {name}", name); // A scope can be used to share sets of attributes between multiple log // entries. Attribute keys in a scope can use dot notation for namespacing // purposes. using (_logger.BeginScope(new Dictionary<string, object> { {"example.someInteger", 7 }, {"example.someString", "frog blast the vent core!" } })) { _logger.LogInformation("logging within a scope"); _logger.LogInformation("logging again with the same attributes"); } return $"Hello, {name}!"; }}

Cloud Code JavaScript スクリプト

スクリプトコンテキストの一部として自動的に提供されるデフォルトロガーを使用して、Cloud Code JavaScript スクリプト からログを発行できます。
以下のコードサンプルは、JavaScript スクリプトをインストルメント化するために行う必要があるすべてのことを示します。

JavaScript

module.exports = async ({ params, context, logger }) => { logger.info("script executing", {"example.someString": "frog blast the vent core!"}); logger.warning("this is a serious warning that the cheese is about to run out."); logger.error("out of cheese :(", {"example.foo": 42}, {"example.bar": 7});};
ロガーでは以下のメソッドが提供されています。
  • debug(message, ...logAttributes)
  • info(message, ...logAttributes)
  • warning(message, ...logAttributes)
  • error(message, ...logAttributes)
  • fatal(message, ...logAttributes)

制限

呼び出しごとに複数のログ属性を渡すことができますが、以下の制限が適用されます。
  • 各ログ属性は、単一のキー/値のペアを持つオブジェクトである必要があります。
  • 値は空ではないプリミティブである必要があります (false ブーリアンが許可されます)。

Copyright © 2026 Unity Technologies
法規事項プライバシーポリシークッキーDocumentation Terms of Use私の個人情報を販売または共有しないプライバシーに関する選択 (クッキー設定)

"Unity" の名称、Unity のロゴ、およびその他の Unity の商標は、米国およびその他の国における Unity Technologies またはその関係会社の商標または登録商標です (詳しくはこちら)。その他の名称またはブランドは該当する所有者の商標です。

一部のページは利便性向上のため機械翻訳を使用しており、内容に不正確な表現が含まれる場合があります。内容に齟齬または不一致が生じた場合は、英語版を正本とします。

  • このページ
    • Cloud Code C# モジュール

    • Cloud Code JavaScript スクリプト

      • JavaScript

      • 制限


このページの問題を報告する