All jobs

Migrate a chi API from Logrus to log/slog

Yes. An agent replaces Logrus with log/slog across a chi API, keeps every field and the request log line, and opens a PR with go test and go vet output.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts from the logging package, because in a chi API laid out like dhax/go-base that is where every log line is shaped. go.mod says go 1.25.0, so log/slog is in the standard library the module already builds with, beside github.com/sirupsen/logrus v1.9.3, github.com/go-chi/chi/v5 v5.4.0, Viper and Cobra. logging/logger.go builds a package-level *logrus.Logger in NewLogger: a TextFormatter when the log_textlogging setting is on and a JSONFormatter otherwise, both with DisableTimestamp: true, and a level parsed from log_level, which cmd/serve.go defaults to debug and the function itself to error. The same file wraps chi's middleware.RequestLogger: NewLogEntry writes ts in RFC 1123, req_id from middleware.GetReqID, http_scheme, http_proto, http_method, remote_addr, user_agent and uri, then logs request started; Write adds resp_status, resp_bytes_length and resp_elapsed_ms and logs request complete; Panic adds stack and panic. GetLogEntry, LogEntrySetField and LogEntrySetFields hand the request-scoped entry to handlers.

Then it lists every caller, since the type logrus.FieldLogger leaks out of the package. Four files import Logrus: logging/logger.go, and api/admin/api.go, api/app/api.go and auth/pwdless/api.go, which each declare func log(r *http.Request) logrus.FieldLogger over logging.GetLogEntry. auth/jwt/authenticator.go calls logging.GetLogEntry(r).Warn(err) and .Error(err) directly, auth/pwdless/chores.go logs through the package variable with logging.Logger.WithField("chore", "purgeExpiredToken").Error(err) from an hourly ticker, and api/api.go reports a failed start with logger.WithField("module", "database").Error(err) and the same for email, auth, admin and app. The one shape slog does not have is a call whose only argument is the error: log(r).WithField("email", body.Email).Warn(err) in the login handler has no message, and slog's Warn takes a message first.

The rewrite keeps the package's names and changes their types. NewLogger returns a *slog.Logger over slog.NewTextHandler or slog.NewJSONHandler on standard output, chosen by the same log_textlogging setting; the level comes from slog.Level.UnmarshalText on log_level, with the Logrus-only names trace, fatal and panic mapped to the nearest slog level so an existing .env keeps working; a ReplaceAttr drops slog's own time attribute, because the request line already carries ts and the JSON output should not gain a second clock. StructuredLoggerEntry holds a *slog.Logger, which is immutable, so LogEntrySetField replaces the pointer with entry.Logger.With(key, value) instead of mutating it, and Write logs request complete with its three fields as key-value pairs. The three log(r) helpers return *slog.Logger, and each bare .Warn(err) becomes a line with a short message and the error as an error attribute: log(r).Warn("login refused", "email", body.Email, "error", err). chores.go and authenticator.go change the same way. auth/pwdless/api_test.go already builds the middleware through logging.NewStructuredLogger(logging.NewLogger()), so it compiles against the new signatures unchanged.

With no import left, go mod tidy removes Logrus from go.mod and go.sum, and the agent edits the README line that says Structured logging with Logrus. Then it runs what .github/workflows/test.yml and lint.yml run, go test -v ./... and golangci-lint, plus go vet ./... and go build ./.... To show the output is the same shape, it installs Postgres with apt-get in its sandbox, points the .env at it, starts serve and requests /healthz and POST /auth/login, then pastes one request complete line from before the change and one from after so a reviewer can compare the keys side by side.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Replace Logrus with the standard library's log/slog in this chi API. Read go.mod, logging/logger.go, api/api.go, api/app/api.go, api/admin/api.go, auth/pwdless/api.go, auth/pwdless/chores.go, auth/jwt/authenticator.go, auth/pwdless/api_test.go, cmd/serve.go and the README first, and list every file that imports logrus or calls logging.Logger. Keep the logging package's exported names and the request middleware's fields (ts, req_id, http_scheme, http_proto, http_method, remote_addr, user_agent, uri, resp_status, resp_bytes_length, resp_elapsed_ms, stack, panic) and its two messages. Choose the text or JSON handler from the log_textlogging setting and the level from log_level, accepting the level names the old config accepted. Give every call that passed only an error a short message and keep the error as an attribute. Run go mod tidy so logrus leaves go.mod and go.sum, update the README line about logging, and run go build ./..., go vet ./..., go test -v ./... and golangci-lint. Install Postgres in your sandbox, start the server, request /healthz and POST /auth/login, and paste one request-complete log line from before and one from after into the pull request. Change no route, no response and no configuration key.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The pull request changes logging/logger.go, the three API files and the two auth files that logged, go.mod, go.sum and the README, and nothing under database, email or models. Its description lists each call site in a table with the old Logrus line and the new slog line, so a reviewer can check that no field was dropped and every bare error gained a message, and ends with the two request complete lines, the go test -v ./... and go vet ./... output and the linter's report.

The log output keeps its keys: ts, req_id, http_method, uri and the response fields appear under the same names in JSON mode, and the text handler prints key=value pairs where Logrus printed its own text format, which is the one visible difference and is called out. The level names an existing .env uses still parse. No route, status code or response body changes, and the login flow still sends its token email in a goroutine with the request's logger.

Before merging, a reviewer decides whether to keep ts in RFC 1123 or let slog write its default time attribute in RFC 3339, checks that whatever ingests the logs reads the text handler's new format if the service runs with log_textlogging on, and confirms the three Logrus-only level names map the way they expect.

Run it on every Linear issue labelled tech-debt

Add an automation to the Project with this prompt and a linear trigger on linear.issue.labeled with the label your team uses for dependency debt in its labels. Each labelled issue starts one run on its own branch with the issue as its context; the trigger adds the issue after the prompt and fills in no placeholder, and a change made by an app integration never fires it, so the agent's own comment on the issue starts nothing.

The automation's max_runs_per_hour caps a burst of labels: a fire past it is created queued and starts when the hour has room, and one past a second hour's worth is skipped as rate_limited until the issue is labelled again. From your own server, the same run starts with this request and the issue URL in resources, with a request_id that is a UUID v5 of the issue id so a retried start returns the run already begun.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

A logging migration is wide and shallow: a handful of lines in each of a dozen files, every one of which must keep its fields, plus one type that has to change everywhere at once. The agent reads every call site before it edits, so the pull request is complete rather than a first pass, and it proves the output shape with a real server request rather than by reading the formatter's documentation.

The run's transcript keeps go test, go vet, the linter and the two log lines with their output, so a reviewer checks the diff and the evidence from one page without checking the branch out. Several services that share this logging package can be migrated at the same time, each in its own sandbox with its own Postgres, and nothing merges until a person reads the diff.

Frequently asked questions

Why not keep Logrus and add slog beside it?

Two loggers in one service means two formats in one log stream and two places to set the level. Logrus is in maintenance mode by its own README and slog has shipped in the standard library since Go 1.21, which this module's go 1.25.0 line is well past. Removing the dependency is the point of the change; the agent keeps the package's API so the rest of the code barely notices.

Does the request log line still carry the request id?

Yes. NewLogEntry still reads middleware.GetReqID(r.Context()) and adds it as req_id, and LogEntrySetField still attaches fields handlers add later. The one mechanical change is that a slog logger is immutable, so the entry struct replaces its logger pointer with With(...) instead of mutating it in place.

What happens to log_level values like trace or fatal?

slog has four levels, so the agent maps trace to debug and fatal and panic to error, and says so in the pull request. A level slog cannot parse still stops the process at startup, as the old logrus.ParseLevel failure did, so a typo in .env is caught the same way.

Will the text output look the same?

No. Logrus's TextFormatter and slog's TextHandler print different layouts, and the pull request shows one line from each. JSON mode keeps the same keys. If something parses the text format, run the service with log_textlogging off, or ask for a handler that reproduces the old layout as a follow-up.

More chi jobs

The same job on other stacks

More jobs like this: Upgrade dependencies weekly

Keep reading