JSON Print Statements Not Appearing in Railway Logs Despite Successful Application Functionality
jamesc127
PROOP

6 months ago

Environment:

- Service: Django application on Railway

- Runtime: Python 3.11

- Web Server: Gunicorn

- Branch: development_20250603

Issue Description:

Our Django application is running successfully on Railway, but JSON print statements are not appearing in the Railway logs despite the

application functioning correctly.

What We've Tried:

1. Migrated from Python logging to direct print statements following Railway's JSON logging documentation:

# Info/Debug to stdout

print(json.dumps({"message": "...", "level": "info", ...}))

sys.stdout.flush()

# Warning/Error to stderr

print(json.dumps({"message": "...", "level": "error", ...}), file=sys.stderr)

sys.stderr.flush()

2. Disabled Django LOGGING configuration to prevent interference:

LOGGING = {

'version': 1,

'disable_existing_loggers': False,

'handlers': {'null': {'class': 'logging.NullHandler'}},

'root': {'handlers': ['null']},

}

3. Added explicit flush calls to ensure immediate output

Current Behavior:

- App startup logs appear correctly (JSON format working)

- Initial page load logs appear (user authentication, API initialization)

- AJAX endpoint logs don't appear (api_loading_status, item analysis, etc.)

- User action logs missing (button clicks, form submissions)

Example of Last Visible Log:

{

"message": "Generated auth URL: https://auth.ebay.com/...",

"level": "info",

"user_id": 1,

"username": "ebay_administrator"

}

Key Observation:

The application works perfectly - all user actions complete successfully, databases update correctly, and UI responds properly. The

issue is purely that our JSON print statements aren't reaching Railway's log collector after the initial page load.

Question:

Does Railway's log collection have any limitations with:

- Gunicorn worker processes and stdout/stderr capture?

- AJAX request logging vs initial page load logging?

- Print statement buffering in Django applications?

- JSON format requirements beyond what's documented?

Expected Result: All JSON print statements should appear in Railway logs

Actual Result: Only initial startup and page load logs appear

Any guidance on Railway-specific logging requirements for Django applications would be greatly appreciated.

Solved

1 Replies

sarahkb125
EMPLOYEE

6 months ago

A few things to try:
- use console.log() like here: https://docs.railway.com/reference/logging
- Ensure that Gunicorn is configured to capture stdout and stderr correctly. This can be done by setting the --access-logfile and --error-logfile options to - to redirect logs to stdout and stderr.


Status changed to Awaiting User Response Railway 6 months ago


Railway
BOT

4 months ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 4 months ago


Loading...