All Products
Search
Document Center

Function Compute:Logging

Last Updated:Apr 01, 2026

Function Compute's PHP runtime supports two ways to write logs from your function code: the built-in logger module and standard PHP output functions. This topic explains how to use each approach and how to view logs after a function runs.

Print logs

Use the built-in logger

For functions using a built-in runtime, access the logger through the $GLOBALS['fcLogger'] global variable. Logs are automatically forwarded to the Simple Log Service (SLS) Logstore you specified when creating the service.

Each log entry is structured as:

YYYY-MM-DD HH:MM:SS <requestId> [LEVEL] message

Example:

2024-01-04 10:50:44 1-659xxxxx-16cxxxxx-39659xxxxxx [INFO] hello world

The built-in logger automatically adds a timestamp, request ID, and log level to every entry. Standard PHP output functions (covered in the next section) do not include this metadata.

The following example prints two logs at the default INFO level, then raises the level to CRITICAL (500) so that subsequent INFO logs are suppressed:

<?php

function handler($event, $context) {
  $logger = $GLOBALS['fcLogger'];
  $logger->info('hello world');
  $logger->critical('world hello');

  $logger->setLevel(500);
  $logger->info('hello world 2');    // suppressed -- below CRITICAL threshold
  $logger->critical('world hello 2');
  return 'hello world';
}

Expected output:

FunctionCompute php7.2 runtime inited.
FC Invoke Start RequestId: 1-659xxxxx-16cxxxxx-39659xxxxxx
2024-01-04 10:50:44 1-659xxxxx-16cxxxxx-39659xxxxxx [INFO] hello world
2024-01-04 10:50:44 1-659xxxxx-16cxxxxx-39659xxxxxx [CRITICAL] world hello
2024-01-04 10:50:44 1-659xxxxx-16cxxxxx-39659xxxxxx [CRITICAL] world hello 2
\nFC Invoke End RequestId: 1-659xxxxx-16cxxxxx-39659xxxxxx

hello world 2 does not appear because after setLevel(500), the logger only emits messages at CRITICAL (500) or above.

Log levels

Call $logger->setLevel(<numeric_level>) to control which messages are emitted. Messages below the active level are dropped. The default level is INFO (200).

Log levelNumeric valueInterfaceWhen to use
EMERGENCY600$logger->emergencyThe system is unusable and requires immediate action
ALERT550$logger->alertA critical component is down and action must be taken immediately
CRITICAL500$logger->criticalA serious failure has occurred that requires urgent attention
ERROR400$logger->errorAn operation failed and could not complete
WARNING300$logger->warningAn unexpected situation occurred, but execution continued
NOTICE250$logger->noticeA normal but significant event worth tracking
INFO200$logger->infoGeneral operational messages; default level
DEBUG100$logger->debugDetailed diagnostic information for development and troubleshooting

Use standard PHP output functions

For functions not using a built-in runtime, use standard PHP output functions. Unlike the built-in logger, this approach prints raw content only — no timestamp, request ID, or log level is added.

<?php

function handler($event, $context) {
  var_dump("abcd");
  echo "abcd 2\n";
  fwrite(STDERR, "error\n");
  return 'hello world';
}

Expected output:

FunctionCompute php7.2 runtime inited.
FC Invoke Start RequestId: 1-659xxxxx-165xxxxx-455a04xxxxxx
/code/index.php:4:
string(4) "abcd"
abcd 2
error
\nFC Invoke End RequestId: 1-659xxxxx-165xxxxx-455a04xxxxxx

Any function that writes to standard output or standard error works the same way.

View logs

After a function runs, open the function in the Function Compute console and go to the Logs tab on the Function Details page. To filter and query logs across invocations, see View invocation logs.