Logging
- Introduction
- Configuration
- Writing log messages
- Request context
- Errors and panics
- Framework log lines
- Sending logs elsewhere
Introduction
To help you understand what's happening inside your application when something goes wrong, Laravel provides structured logging out of the box. You may write log messages to standard error, daily log files, or both, formatted as plain text or JSON. Laravel automatically tags every log line with the request, command, or job that wrote it, so you can trace a single operation through busy production logs.
You write log messages with log/slog, Go's structured logger. When your application starts, Laravel makes its logger the default slog logger, so every package you use that logs with slog writes to the same channels in the same format.
Configuration
A new application's .env file configures Laravel to write info messages and above to standard error. Laravel doesn't write log files unless you enable the daily channel.
1LOG_CHANNEL=stderr2LOG_LEVEL=info1LOG_CHANNEL=stderr2LOG_LEVEL=info
Laravel reads these environment variables when configuring logging:
| Variable | What it sets | Default |
|---|---|---|
LOG_LEVEL |
The level of messages to write, with optional per-package overrides such as info,sms=debug |
info |
LOG_FORMAT |
The format: text or json |
text |
LOG_CHANNEL |
The channels to write to, such as stderr,daily |
stderr |
LOG_DAILY_LEVEL, LOG_STDERR_LEVEL, LOG_STDOUT_LEVEL |
A channel's own level | LOG_LEVEL |
LOG_DAILY_FORMAT, LOG_STDERR_FORMAT, LOG_STDOUT_FORMAT |
A channel's own format | LOG_FORMAT |
LOG_DAILY_DAYS |
How many days of files the daily channel keeps, or 0 to keep all of them |
14 |
Log levels
The log level controls which messages Laravel records: debug, info, warning, or error. Laravel writes messages at the configured level and above, so info records info, warning, and error messages, and drops debug messages.
The level applies to your own messages and to Laravel's alike. For example, setting LOG_LEVEL=debug also shows each database query your application runs, along with the other framework log lines that Laravel writes at the debug level.
You may also set a different level for specific packages by appending comma-separated package=level entries to LOG_LEVEL. Each package name matches either a full import path or its trailing path segments. For example, this setting keeps most logs at info, enables debug logs for app/orders, and raises sms to warning:
1LOG_LEVEL=info,app/orders=debug,sms=warning1LOG_LEVEL=info,app/orders=debug,sms=warning
Formats
The text format writes each message as one line of key=value pairs, making it easy to read in your terminal during local development. The json format writes one JSON object per line, which works well in production when a log service collects and indexes your fields:
1LOG_FORMAT=json1LOG_FORMAT=json
Each JSON line starts with the message's time in UTC, its lowercase level (debug, info, warning, or error), and its message, followed by the record's structured fields and any active request, command, job, or task tags. Values you add to the context with log.With appear under context. For example, a handler that logs an order during a request writes this JSON object on a single line (formatted across multiple lines here for readability):
1{2 "time": "2026-11-10T03:53:15.478213Z",3 "level": "info",4 "message": "Order placed.",5 "order": 1042,6 "total": 4999,7 "request_id": "ab42b08da41e7b2ddd21a1bf552b06d7",8 "context": {9 "tenant": "acme"10 }11}1{2 "time": "2026-11-10T03:53:15.478213Z",3 "level": "info",4 "message": "Order placed.",5 "order": 1042,6 "total": 4999,7 "request_id": "ab42b08da41e7b2ddd21a1bf552b06d7",8 "context": {9 "tenant": "acme"10 }11}
On Laravel Cloud, the laravel-cloud-socket channel sends these same JSON lines to Cloud's Logs page. When tracing is enabled and a span is active, JSON lines also include trace_id and span_id so you can jump between logs and traces.
Channels
Channels control where Laravel writes your logs:
| Channel | Destination |
|---|---|
stderr |
Standard error, where process managers and containers collect logs. The default. |
stdout |
Standard output. |
daily |
A file for each day in storage/logs, such as laravel-2026-11-12.log. |
To write to more than one channel at once, separate the channel names with commas in LOG_CHANNEL.
Channel levels and formats
By default, LOG_LEVEL and LOG_FORMAT apply to every channel. To give a specific channel a different minimum level, set LOG_DAILY_LEVEL, LOG_STDERR_LEVEL, or LOG_STDOUT_LEVEL.
If you want to keep a local copy of warnings and errors, add daily to LOG_CHANNEL in your .env file. This configuration keeps info messages and above on standard error but saves only warnings and errors to disk:
1LOG_CHANNEL=stderr,daily2LOG_LEVEL=info3LOG_DAILY_LEVEL=warning1LOG_CHANNEL=stderr,daily2LOG_LEVEL=info3LOG_DAILY_LEVEL=warning
To give a channel its own format, set LOG_DAILY_FORMAT, LOG_STDERR_FORMAT, or LOG_STDOUT_FORMAT. For example, this configuration keeps stderr as text while writing daily files as JSON:
1LOG_CHANNEL=stderr,daily2LOG_FORMAT=text3LOG_DAILY_FORMAT=json1LOG_CHANNEL=stderr,daily2LOG_FORMAT=text3LOG_DAILY_FORMAT=json
Writing log messages
You may write log messages from anywhere in your application using the functions in log/slog. There is one function for each log level:
1slog.DebugContext(ctx, "Looking up the user.")2slog.InfoContext(ctx, "Order placed.")3slog.WarnContext(ctx, "The mail provider is slow.")4slog.ErrorContext(ctx, "The welcome email couldn't be sent.")1slog.DebugContext(ctx, "Looking up the user.")2slog.InfoContext(ctx, "Order placed.")3slog.WarnContext(ctx, "The mail provider is slow.")4slog.ErrorContext(ctx, "The welcome email couldn't be sent.")
Pass the request r as the context in a handler, and the ctx your code receives everywhere else. Each message then automatically includes the context of the active request, command, or job, so you don't need to log the request ID manually. A message logged without a context, such as with slog.Info, doesn't carry it, so always use the functions whose names end in Context.
Structured fields
When a log message refers to a specific record such as an order or a user, pass its details as structured fields rather than formatting them into the message's text. A message whose text never changes is one you can search for and count. Each field is a key followed by its value. For example, this handler logs each order a customer places:
1package orders23import (4 "log/slog"56 "go.laravel.com/web"78 "app/store"9)1011func Store(r *web.Request) *web.Response {12 var form struct {13 Product int `json:"product"`14 }15 if err := r.BindInto(&form); err != nil {16 return web.Fail(err)17 }1819 order, err := store.PlaceOrder(r, form.Product)20 if err != nil {21 return web.Fail(err)22 }2324 slog.InfoContext(r, "Order placed.", "order", order.ID, "total", order.Total)2526 return web.Created(order)27}1package orders23import (4 "log/slog"56 "go.laravel.com/web"78 "app/store"9)1011func Store(r *web.Request) *web.Response {12 var form struct {13 Product int `json:"product"`14 }15 if err := r.BindInto(&form); err != nil {16 return web.Fail(err)17 }1819 order, err := store.PlaceOrder(r, form.Product)20 if err != nil {21 return web.Fail(err)22 }2324 slog.InfoContext(r, "Order placed.", "order", order.ID, "total", order.Total)2526 return web.Created(order)27}
In text format, the fields appear after the message. In json format, each field becomes a JSON key, so your log service can search for every line related to order 1042:
1time=2026-11-10T03:53:15.478Z level=INFO msg="Order placed." order=1042 total=4999 request_id=ab42b08da41e7b2ddd21a1bf552b06d71time=2026-11-10T03:53:15.478Z level=INFO msg="Order placed." order=1042 total=4999 request_id=ab42b08da41e7b2ddd21a1bf552b06d7
To nest several fields that belong together under one key, such as a customer's ID and email address, use slog.Group. In text format, the group's name prefixes each of its keys, as in customer.id=7:
1slog.InfoContext(r, "Order placed.",2 "order", order.ID,3 slog.Group("customer", "id", order.UserID, "email", order.Email),4)1slog.InfoContext(r, "Order placed.",2 "order", order.ID,3 slog.Group("customer", "id", order.UserID, "email", order.Email),4)
Request context
Because your application handles many requests concurrently, log lines from different requests are interleaved. To help you trace a single request, Laravel gives each request an ID and adds it, as request_id, to every message logged with the request's context, whether the message comes from your application or a package:
1time=2026-11-10T03:53:15.478Z level=INFO msg="Looking up the user." request_id=4bf92f3577b34da6a3ce929d0e0e47361time=2026-11-10T03:53:15.478Z level=INFO msg="Looking up the user." request_id=4bf92f3577b34da6a3ce929d0e0e4736
When the request finishes, Laravel also writes a line recording its status and duration.
Request IDs
Every response includes its request ID in the X-Request-Id header, so when a user reports an error, you can search your logs for that ID. If a request already arrives with an X-Request-Id header (for example, from a load balancer), Laravel preserves it. To read the request ID inside a handler, call r.ID():
1func Show(r *web.Request) *web.Response {2 return web.Text("Your request was " + r.ID())3}1func Show(r *web.Request) *web.Response {2 return web.Text("Your request was " + r.ID())3}
In code that receives only a context, such as a service your handler calls, use web.RequestID(ctx) instead.
Commands, jobs, and scheduled tasks
Work running outside an HTTP request is tagged too. Every line logged with a console command's context records the command's name:
1time=2026-11-10T04:00:00.112Z level=INFO msg="Generating the monthly report." command=reports:generate1time=2026-11-10T04:00:00.112Z level=INFO msg="Generating the monthly report." command=reports:generate
Long-running commands such as serve, schedule:work, and queue:work don't tag their lines with their own name. Instead, each individual request, scheduled task, tick, queued job, or workflow they run tags its own lines: a scheduled task records its name as task, a tick records its name as tick, a job records its name and ID as job and job_id, and a workflow records its name and run ID as workflow and workflow_run (plus step and attempt while running a step).
Adding context
Sometimes every log line written during a request should include shared information, such as the current tenant in a multi-tenant application. Any value you add to the request's context with log.With, from Laravel's log package, is automatically attached to every later line logged with that context. A middleware is a good place to add it:
1package middleware23import (4 "strings"56 "go.laravel.com/log"7 "go.laravel.com/web"8)910func IdentifyTenant(r *web.Request, next web.Next) *web.Response {11 tenant, _, _ := strings.Cut(r.Host, ".")1213 return next(r.WithContext(log.With(r, "tenant", tenant)))14}1package middleware23import (4 "strings"56 "go.laravel.com/log"7 "go.laravel.com/web"8)910func IdentifyTenant(r *web.Request, next web.Next) *web.Response {11 tenant, _, _ := strings.Cut(r.Host, ".")1213 return next(r.WithContext(log.With(r, "tenant", tenant)))14}
The value reaches the lines of the code the request calls, the errors the request reports, and the queued jobs the request dispatches. In text format, the value appears after the message's own fields, and in json format it appears under context:
1time=2026-11-10T03:53:15.478Z level=INFO msg="Order placed." order=1042 total=4999 request_id=ab42b08da41e7b2ddd21a1bf552b06d7 tenant=acme1time=2026-11-10T03:53:15.478Z level=INFO msg="Order placed." order=1042 total=4999 request_id=ab42b08da41e7b2ddd21a1bf552b06d7 tenant=acme
Laravel writes the line for each finished request with the context the request started with, so that line carries the request's ID but not a value that a middleware adds. To store a value without writing it to your logs, use log.WithHidden instead. To learn more, check out the context guide's section on values for log lines and jobs.
Errors and panics
The error handler logs every 5xx server failure at the error level, recording the error's message, the request's method and path, and the request context. Because a Go error carries no stack trace, the line also includes a location field with the file and line where your handler or middleware called web.Fail, and a type field with the error's Go type. When a handler panics, the location is the line that panicked, and the line includes the panic's stack, starting at that line:
1time=2026-11-10T03:53:15.478Z level=ERROR msg="charge declined" method=POST path=/orders location=/srv/app/handlers/orders/orders.go:42 type=*errors.errorString request_id=6f1c0a9d2b3e4f5a8c7d9e0f1a2b3c4d2time=2026-11-10T03:54:02.031Z level=ERROR msg="panic: runtime error: index out of range [3] with length 3" method=GET path=/reports location=/srv/app/handlers/reports/reports.go:27 type=*web.PanicError stack="goroutine 34 [running]:\n…" request_id=0b7e2d4c9a1f4e6b8d3c5a7f9e1b2d4c1time=2026-11-10T03:53:15.478Z level=ERROR msg="charge declined" method=POST path=/orders location=/srv/app/handlers/orders/orders.go:42 type=*errors.errorString request_id=6f1c0a9d2b3e4f5a8c7d9e0f1a2b3c4d2time=2026-11-10T03:54:02.031Z level=ERROR msg="panic: runtime error: index out of range [3] with length 3" method=GET path=/reports location=/srv/app/handlers/reports/reports.go:27 type=*web.PanicError stack="goroutine 34 [running]:\n…" request_id=0b7e2d4c9a1f4e6b8d3c5a7f9e1b2d4c
The error handler only logs 5xx failures. Client errors such as a 404 or failed validation are expected outcomes and don't produce error lines. To exclude a specific server error from your logs as well, ignore it.
When you handle an error and carry on, report it rather than logging it yourself. Call r.Report in a handler, or laravel.Report(ctx, err) in other code, and Laravel logs the error and passes it to your error tracker.
Framework log lines
Laravel logs its own activity too. Most of these lines are written at the debug level, so they stay quiet under the default info level. To inspect them, set LOG_LEVEL to debug:
1LOG_LEVEL=debug1LOG_LEVEL=debug
| Message | Level | What it logs |
|---|---|---|
The method, path, and status, such as GET /users/7 200 |
info locally, debug otherwise |
Each completed request, including status and duration_ms. Requests to the health route always log at debug. |
command finished |
debug |
Each completed console command, including exit_code and duration_ms |
| The job's or task's error | error |
Each failed attempt of a queued job, including attempt, and each failed scheduled task |
a workflow step failed and will be tried again |
warning |
Each failed workflow step attempt that will be retried, including workflow, workflow_run, step, attempt, and error |
The method, URL, and status, such as GET https://api.example.com/rates 200 |
debug |
Each completed outgoing request, including status or error and duration_ms |
cache hit, cache missed, cache written, cache forgotten |
debug |
Each key the cache reads, writes, or removes |
mail sent |
debug |
Each email sent by a mailer, including mailer, id, and mailable |
SMS sent |
debug |
Each text message sent by an SMS sender, including sender and id |
Slack message posted |
debug |
Each Slack message posted, including route |
process finished |
debug |
Each process your application runs, including program, exit_code, and duration_ms |
query |
debug |
Each database statement, including sql and duration_ms |
While you develop, with APP_ENV=local and the text format, Laravel shortens the request lines on standard error and standard output to the method, status, path, and duration. The daily files keep every field:
1GET 200 /users/7 1.5ms1GET 200 /users/7 1.5ms
If you'd like to hide the request lines, raise LOG_LEVEL to warning. You'll still see every reported error.
Request lines log at info only while APP_ENV is local. In production, your hosting platform's access logs typically already record each request, so Laravel logs these lines at debug to avoid writing every request twice. If nothing in front of your application keeps access logs, you may turn the lines back on:
1LOG_LEVEL=info,web=debug1LOG_LEVEL=info,web=debug
Sending logs elsewhere
While channels write to standard output or local files, you may also want to forward errors to an external tracker that alerts your team. Any service that provides a slog.Handler can receive your logs through the LogHandler option in bootstrap/app.go. Your function receives the application's own handler as next, and returns a handler that passes each record on to next as well as to the service, as the Sentry example shows.
If you'd rather replace the channels entirely, give your application a logger of its own with the Logger option. Wrap its handler with web.LogHandler, which adds the request ID, the command, job, or task, and the values you added to each line. A logger you supply ignores the LOG_ variables:
1Logger: slog.New(web.LogHandler(slog.NewJSONHandler(os.Stdout, nil))),1Logger: slog.New(web.LogHandler(slog.NewJSONHandler(os.Stdout, nil))),
A package may also add a handler with app.LogHandler in its Register method. To learn more about adding handlers from a package, check out the package development guide's section on logging. If you'd like to export distributed traces instead of log messages, check out the tracing guide.
Sentry
To send errors to Sentry, add Sentry's Go SDK and its slog handler to your application:
1go get github.com/getsentry/sentry-go github.com/getsentry/sentry-go/slog1go get github.com/getsentry/sentry-go github.com/getsentry/sentry-go/slog
Then initialize Sentry and register its handler for errors with the LogHandler option in bootstrap/app.go:
1package bootstrap23import (4 "context"5 "log/slog"6 "time"78 "github.com/getsentry/sentry-go"9 sentryslog "github.com/getsentry/sentry-go/slog"1011 laravel "go.laravel.com"12 "go.laravel.com/config"13 "go.laravel.com/web"14)1516func Options() laravel.Options {17 return laravel.Options{18 LogHandler: errorTracking,1920 // ...21 }22}2324func errorTracking(next slog.Handler, env *config.Env) (slog.Handler, error) {25 transport := sentry.NewHTTPSyncTransport()26 transport.Timeout = 3 * time.Second2728 err := sentry.Init(sentry.ClientOptions{29 Dsn: env.String("SENTRY_DSN", ""),30 Environment: env.String("APP_ENV", "production"),31 Transport: transport,32 })33 if err != nil {34 return nil, err35 }3637 errors := sentryslog.Option{38 LogLevel: []slog.Level{slog.LevelError},39 }.NewSentryHandler(context.Background())4041 return slog.NewMultiHandler(next, web.LogHandler(errors)), nil42}1package bootstrap23import (4 "context"5 "log/slog"6 "time"78 "github.com/getsentry/sentry-go"9 sentryslog "github.com/getsentry/sentry-go/slog"1011 laravel "go.laravel.com"12 "go.laravel.com/config"13 "go.laravel.com/web"14)1516func Options() laravel.Options {17 return laravel.Options{18 LogHandler: errorTracking,1920 // ...21 }22}2324func errorTracking(next slog.Handler, env *config.Env) (slog.Handler, error) {25 transport := sentry.NewHTTPSyncTransport()26 transport.Timeout = 3 * time.Second2728 err := sentry.Init(sentry.ClientOptions{29 Dsn: env.String("SENTRY_DSN", ""),30 Environment: env.String("APP_ENV", "production"),31 Transport: transport,32 })33 if err != nil {34 return nil, err35 }3637 errors := sentryslog.Option{38 LogLevel: []slog.Level{slog.LevelError},39 }.NewSentryHandler(context.Background())4041 return slog.NewMultiHandler(next, web.LogHandler(errors)), nil42}
Initialize Sentry in LogHandler rather than in services.New. Laravel builds your logger before your services, and Sentry's handler sends through the client that exists when the handler is made. The function receives your .env file's values, so SENTRY_DSN is read from there. When SENTRY_DSN is empty, as in development and tests, Sentry sends nothing, and a SENTRY_DSN that isn't valid stops your application from starting.
Because the error handler logs every server failure at the error level, failures arrive in Sentry as log lines alongside errors you log yourself. Wrapping Sentry's handler with web.LogHandler gives each line the request ID, the job or task, and the values you added to the request context.
To also open a Sentry issue with a stack for each server error, send the error from your report hook. Laravel calls the hook with each server error that a request, r.Report, or laravel.Report reports, and with the error that fails a command, a queued job, or a scheduled task. This hook tags the error with the request's ID and the values you added to the request's context:
1package bootstrap23import (4 "context"56 "github.com/getsentry/sentry-go"78 "go.laravel.com/log"9 "go.laravel.com/web"10)1112func reportError(ctx context.Context, err error) {13 sentry.WithScope(func(scope *sentry.Scope) {14 if id := web.RequestID(ctx); id != "" {15 scope.SetTag("request_id", id)16 }17 for _, attr := range log.Attrs(ctx) {18 scope.SetTag(attr.Key, attr.Value.String())19 }2021 sentry.CaptureException(err)22 })23}1package bootstrap23import (4 "context"56 "github.com/getsentry/sentry-go"78 "go.laravel.com/log"9 "go.laravel.com/web"10)1112func reportError(ctx context.Context, err error) {13 sentry.WithScope(func(scope *sentry.Scope) {14 if id := web.RequestID(ctx); id != "" {15 scope.SetTag("request_id", id)16 }17 for _, attr := range log.Attrs(ctx) {18 scope.SetTag(attr.Key, attr.Value.String())19 }2021 sentry.CaptureException(err)22 })23}
Then set the hook in bootstrap/app.go with Errors: web.Errors{Report: reportError}. The sync transport sends each issue before the hook returns, so an error isn't lost when a deploy stops the server right after it. To export traces to Sentry too, check out the tracing guide's section on Sentry.