How Cloud Run sends container output to Cloud Logging, the JSON fields that set severity and link logs to requests, Logs Explorer queries that find one request's lines, retention and exclusion filters, and a TypeScript service whose logs arrive structured without extra setup.

Cloud Run sends everything your container prints to Cloud Logging without any agent, which makes the first console.log feel free. The cost shows up during an incident, when every plain-text line has the same severity and one request's lines are scattered among everyone else's.
This guide covers what Cloud Run logs, structured lines for severity and request correlation, the queries worth saving, and the bill.
For every service, the Cloud Run logging docs describe two kinds of entries:
httpRequest field.Both are tagged with the cloud_run_revision resource and labels for the service, revision and location, so resource.labels.service_name is the first filter in almost every query. Jobs log under cloud_run_job instead, with the execution and task index as labels.
Write one JSON object per line, and Cloud Logging turns it into a jsonPayload and reads a few special fields from it: severity sets the level, message becomes the summary line, and logging.googleapis.com/trace links the entry to a request. A small logger for an Express or plain Node.js service looks like this:
// logger.ts
import type { IncomingMessage } from "node:http";
const project = process.env.GOOGLE_CLOUD_PROJECT ?? "";
type Severity = "DEBUG" | "INFO" | "WARNING" | "ERROR";
export function requestLogger(req: IncomingMessage) {
const header = req.headers["x-cloud-trace-context"];
const traceId = typeof header === "string" ? header.split("/")[0] : "";
const trace = project && traceId ? `projects/${project}/traces/${traceId}` : undefined;
return (severity: Severity, message: string, fields: Record<string, unknown> = {}) => {
console.log(
JSON.stringify({
severity,
message,
...fields,
...(trace ? { "logging.googleapis.com/trace": trace } : {}),
}),
);
};
}
With the trace field set, Logs Explorer nests each line under its request log entry, so expanding one slow request shows every line it produced. Multi-line output such as a stack trace printed with console.error(err) becomes several separate entries, which is another reason to put the stack inside a JSON field instead.
The logging query language filters on resource labels, severity and any jsonPayload field. These cover most debugging sessions:
resource.type="cloud_run_revision" resource.labels.service_name="orders" severity>=ERROR resource.type="cloud_run_revision" jsonPayload.orderId="o-1001" resource.type="cloud_run_revision" httpRequest.status>=500 httpRequest.latency>"2s"
The first finds errors in one service, the second follows one order across every service that logs its ID, and the third lists slow failing requests from the request log. For alerting, turn a filter into a log-based metric, such as a counter on severity>=ERROR per service, and alert on its rate rather than on single entries.
Cloud Logging charges for ingestion above a monthly free allotment per project, and for retention beyond the default, as the Google Cloud Observability pricing page lists. The _Default bucket keeps logs for 30 days, and the retention period can be changed per bucket. To reduce volume:
_Default sink for noise you never read, such as DEBUG entries from production or health check request logs.Excluded logs are never stored, so they are also unavailable when you need them, and it is safer to exclude by severity or path than by service.
Encore brings infrastructure from code, and when it deploys an app to Cloud Run in your own GCP project, each service runs with permission to write to Cloud Logging, and the logs it writes go there. The structured logger is built in, so fields are passed as fields rather than formatted into strings, and each line is also recorded in the request's trace.
Run in your terminal to get started locally.
The orders service uses encore.dev/log, with a child logger carrying the order ID on every line:
// orders/encore.service.ts
import { Service } from "encore.dev/service";
export default new Service("orders");
// orders/fulfil.ts
import { api, APIError } from "encore.dev/api";
import log from "encore.dev/log";
interface FulfilParams {
orderId: string;
warehouse: string;
}
export const fulfil = api(
{ expose: true, method: "POST", path: "/orders/:orderId/fulfil" },
async ({ orderId, warehouse }: FulfilParams): Promise<{ status: string }> => {
const logger = log.with({ orderId, warehouse });
const start = Date.now();
if (!["ams-1", "fra-2"].includes(warehouse)) {
logger.warn("unknown warehouse");
throw APIError.invalidArgument("unknown warehouse");
}
try {
const status = await reserveStock(orderId, warehouse);
logger.info("order fulfilled", { status, durationMs: Date.now() - start });
return { status };
} catch (err) {
logger.error(err, "fulfilment failed", { durationMs: Date.now() - start });
throw APIError.unavailable("fulfilment failed");
}
},
);
async function reserveStock(orderId: string, warehouse: string): Promise<string> {
// Call the warehouse system here.
return "reserved";
}
Locally, the lines print in the terminal and show up in the request's trace in the development dashboard, so you see them next to the API call that produced them. On Cloud Run in your GCP project, the same lines are in Cloud Logging with their fields, next to Cloud Run's own request logs, and encore logs --env=prod streams them to your terminal. The TypeScript logging docs explain why encore.dev/log should replace console.log, and the GCP infrastructure docs cover what is set up per service.
When a coding agent debugs a failing fulfilment, it can reproduce the request with encore run and read the trace and log lines locally, or stream production logs with the CLI, instead of needing access to the Logs Explorer.
Best fit: teams running on Cloud Run in their own GCP project who want structured, queryable logs and per-request traces from the first deploy.
severity and message.logging.googleapis.com/trace from X-Cloud-Trace-Context to link lines to requests._Default sink and route long-term logs to a sink.Cloud Run sends everything a container writes to stdout and stderr to Cloud Logging, under the cloud_run_revision resource for services. It also writes a request log entry for every HTTP request, so each request appears once in the request log and again in any lines your code writes.
Write each log line as a single JSON object with a severity field such as INFO, WARNING or ERROR and the text in message. Cloud Logging parses the object into jsonPayload and uses severity as the entry's level, while plain text lines get the default severity.
Read the trace ID from the X-Cloud-Trace-Context header and add a logging.googleapis.com/trace field with the value projects/PROJECT_ID/traces/TRACE_ID to every JSON log line. Logs Explorer then nests those lines under the request log entry and can filter on the trace.
Logs in a project's _Default bucket are kept for 30 days unless you configure a different retention period for that bucket. Retaining logs longer than the default adds retention charges, and logs you need for years are cheaper exported to Cloud Storage or BigQuery with a sink.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.