← AI Insights
繁體中文 English 简体中文
Levi · LinkedIn · 2026-09-10

AI Application Log Design: From Console.log to Production Observability

Console.log in production is not a logging system — it is an observability gap

Log DesignObservabilityLLM MonitoringServerlessCost Control

In early AI application development, console.log is almost everyone's first choice — fast, intuitive, no additional configuration. This works perfectly in local development environments, but once in production, it represents a systematic observability gap.

Console.log Is Not Production Logging

In Vercel, AWS Lambda, and other serverless environments, console.log output exists in process standard output, typically retained for only 24–72 hours and not structurally queryable or cross-period aggregatable. You need database records when:

Minimum Fields That Must Be Persisted

FieldPurpose
request_idGlobal unique ID for tracing cross-service request chains
user_idAttribute cost and usage to specific users
modelAnalyse actual usage distribution and cost share per model
input_tokensCost calculation basis
output_tokensCost calculation basis
cost_usdCalculate at call time from token rates — don't wait for billing
latency_msEnd-to-end response time for performance monitoring
statussuccess / error / timeout for error rate tracking
error_codeDistinguish 429 rate limit, 500 server error, timeout
created_atStandardised UTC+8 (Asia/Hong_Kong) storage

Time Zone Standardisation — Often Overlooked

If some fields are stored in UTC and some in local time, cross-period query results will show hard-to-spot distortions — for example, "yesterday's peak period" statistics with the wrong window due to time zone inconsistency. Standardise all timestamps to UTC+8 at the database layer to avoid report calculation errors.

Meaningful Alerts Require Structured Logs

With clearly-fielded log records, meaningful alert rules become possible:

Threshold values should be stored as named constants, not hardcoded numbers scattered through business logic — otherwise every threshold adjustment requires a search-and-replace hunt.

Common Recording Omissions

Failed requests are often more analytically valuable than successful ones, yet they are the most commonly omitted. Another common issue: the cost field is not calculated at call time but reconstructed from API billing statements after the fact — this eliminates real-time cost control, and overspend is only discovered when the bill arrives at month end.

For more on AI production observability, see Silent Failure in AI Applications: Every Error Must Leave a Trace.

Summary

AI application logging is the observability infrastructure of the operation. Its design should be completed alongside the first version of the API call structure. The cost of retrofitting fields is far higher than getting it right at design time. The observability of token costs, model behaviour, and error patterns directly determines whether you can make an effective diagnosis when a problem appears — or are left guessing blindly.

Levi is a Hong Kong-based independent AI engineer building production AI logging and observability infrastructure. Contact for AI application log design consultation.

WhatsApp Free Initial Consultation → More enterprise case studies →

Or email: support@hksoka.com