Documentation

​
​

Development

User Acquisition

Monetization

Industry

Cloud Code

Scripting API

Services C# SDKs

Services JavaScript SDKs

Admin REST API

Client REST API

Scheduler Admin REST API

Observability REST API

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

Emit logs

Add custom logging statements to your Cloud Code scripts and modules to record debugging information.
Read time 2 minutes
Last updated 5 months ago

You can emit logs from Cloud Code scripts and modules.

Cloud Code C# modules

You can emit logs from Cloud Code C# modules by using the
Microsoft.Extensions.Logging
library
. Cloud Code automatically provides your code with a UGS Logger every time you request an
ILogger
through Dependency Injection.
The following code sample shows everything you need to do to instrument C# modules:
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 scripts

You can emit logs from Cloud Code JavaScript scripts by using the default logger provided automatically as part of the script context.
The following code sample shows everything you need to do to instrument JavaScript scripts:

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});};
The logger provides the following methods:
  • debug(message, ...logAttributes)
  • info(message, ...logAttributes)
  • warning(message, ...logAttributes)
  • error(message, ...logAttributes)
  • fatal(message, ...logAttributes)

Limits

You can pass multiple log attributes per call, however, the following restrictions apply:
  • Each log attribute must be an object with a single key/value pair.
  • The value must be a non-empty primitive (false booleans are allowed).

Copyright © 2026 Unity Technologies
LegalPrivacy PolicyCookiesDocumentation Terms of UseDo Not Sell or Share My Personal InformationYour Privacy Choices (Cookie Settings)

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S and elsewhere (more info here). Other names or brands are trademarks of their respective owners.

Some pages are machine-translated for convenience, and may contain inaccuracies. In the event of conflicting information, the English version is authoritative.

  • On this page
    • Cloud Code C# modules

    • Cloud Code JavaScript scripts

      • JavaScript

      • Limits


Report a problem with this page