All Products
Search
Document Center

Function Compute:Log management

Last Updated:Apr 01, 2026

Function Compute collects all output written to stdout or stderr into the Simple Log Service (SLS) Logstore you specified when creating the service. This topic explains how to print structured logs from a Java function, read the execution summary that Function Compute appends to every invocation, and view logs in the console.

Print logs

Two options are available for printing logs from a Java function:

MethodWhen to use
context.getLogger — provided by the fc-java-core libraryUse this when you need to correlate logs with a specific invocation. Each log entry includes a timestamp, request ID, and log level, so you can filter the Logstore for all output from a single function call.
Third-party logging libraries (for example, logback)Use these when your application already has an established logging setup.
We recommend that you use the context.getLogger method. Logs printed by this method contain request IDs, which you can use to query logs and troubleshoot errors.

Use context.getLogger

The following example writes an INFO-level log entry and returns a response:

package example;

import com.aliyun.fc.runtime.Context;
import com.aliyun.fc.runtime.StreamRequestHandler;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class HelloFC implements StreamRequestHandler {

    @Override
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
        context.getLogger().info("hello world");
        outputStream.write(new String("hello world").getBytes());
    }
}

Running this handler produces the following output in your Logstore:

message:2017-07-05T05:13:35.920Z a72df088-f738-cee3-e0fe-323ad891**** [INFO] hello world

Each log entry contains the time, request ID, and log level followed by your message.

Log levels

context.getLogger supports six log levels. Choose the level that matches the intent of the message:

Log levelMethodStandard usage
TRACEcontext.getLogger().traceFine-grained execution path details; most verbose
DEBUGcontext.getLogger().debugDetailed information for diagnosing system behavior
INFOcontext.getLogger().infoNormal operation messages
WARNcontext.getLogger().warnPotential issues that may cause unexpected behavior if unaddressed
ERRORcontext.getLogger().errorFailures that prevent the code from running as expected
FATALcontext.getLogger().fatalCritical errors that stop the application; least verbose

Understand the execution summary

For every invocation, Function Compute records FC Invoke Start and FC Invoke End marker lines and appends an execution summary to the log. The summary contains the following fields:

FieldDescription
Request IDThe request ID of the invocation.
Code Check ValueThe verification code of the function code package used for this invocation.
Function Execution TimeThe time the function handler actually took to run.
Function Billing TimeThe amount of time you are charged for.
Function MemoryThe memory allocated to the function.
Actual Used MemoryThe maximum memory used during the invocation.

View logs

After a function runs, view its logs on the Logs tab of the Function Details page in the Function Compute console. For step-by-step instructions, see View function invocation logs.