Technology · Operations

How to log a failed job so you can find it later

A log is useful when you can find the one job that failed. A page of unmarked text is not a log.

By OdooMatrix Published 1 min read

Part of a complete guide

This task is one section of Eight software practices that keep business apps reliable, with 7 related tasks on one page.

1. Add a correlation id

When a job starts, give it an id and write that id on the record the user can see, such as an order or an import.

2. Log a few fields

On failure, log the id, the job name, and the error. Do not log passwords, card numbers, or access keys.

3. Find it once

Trigger one failed test job and search the logs for its id. You should land on that failure, not on an unrelated error.

4. Decide how long logs live

Keep them long enough to investigate a customer report. Do not keep secrets you were not supposed to log in the first place.

5. Frequently asked questions

Is print output enough?

Only if it includes the id and you can search it. A console on a laptop is not a production log.

What if the job failed before it had an id?

Log the failure at the edge that received the request, with whatever id the caller sent.

Should I log the whole request body?

No, if it can contain secrets or personal data. Log the id and the field that failed.

6. Related articles and next steps

How to judge it

Treat the checks below as the acceptance test for the change. Names of libraries can vary; the behavior to prove does not.

Continue learning

Need this built?

See software development or email OdooMatrix.

← Back to all articles