Stream log events from your installed app to your command line to troubleshoot your app. You can see 5,000 logs or up to 7 days of log events.
Use console.log(), console.info(), and console.error() in your server code to create logs. View them with devvit logs for installed apps, or add --verbose to include timestamps.
The following example creates a basic app with a menu action that creates a log when clicked.
{
"$schema": "https://developers.reddit.com/schema/config-file.v1.json",
"name": "app-name",
"server": {
"dir": "dist/server",
"entry": "index.cjs"
},
"permissions": {
"reddit": true
},
"menu": {
"items": [
{
"label": "Create a log!",
"location": "subreddit",
"endpoint": "/internal/log-action",
"forUserType": "moderator"
}
]
}
}router.post("/internal/log-action", async (_req, res): Promise<void> => {
console.log("log-action");
res.json({
showToast: {
text: "Log action",
appearance: "success",
},
});
});To stream logs for an installed app, open a terminal and navigate to your project directory and run:
$ devvit logs <my-subreddit>You can also specify the app name to stream logs for from another folder.
$ devvit logs <my-subreddit> <app-name>You should now see logs streaming onto your console:
=============================== streaming logs for my-app on my-subreddit ================================
[DEBUG] Dec 8 15:55:23 Action called!
[DEBUG] Dec 8 15:55:50 Action called!
[DEBUG] Dec 8 15:57:29 Action called!
[DEBUG] Dec 8 15:57:32 Action called!To exit the streaming logger, enter CTRL + c.
You can view historical logs by using the --since=XX flag. You can use the following shorthand:
Xs: show logs in the past X secondsXm: show logs in the past X minutesXh: show logs in the past X hoursXd: show logs in the past X daysXw: show logs in the past X weeks
The following example will show logs from my-app on my-subreddit in the past day.
$ devvit logs <my-subreddit> --since=1dYou will now see historical logs created by your app on this subreddit:
=============================== streaming logs for my-app on my-subreddit ================================
[DEBUG] Dec 8 15:55:23 Action called!
[DEBUG] Dec 8 15:55:50 Action called!
[DEBUG] Dec 8 15:57:29 Action called!
[DEBUG] Dec 8 15:57:32 Action called!To exit the streaming logger, enter CTRL + c.
While you are running playtest in a subreddit, you will also be streaming logs from that community in your command line.