Logging
View and troubleshoot your app logs.
View logs
Any logs sent to console will be available via the devvit logs CLI on installed apps. For example, console.log(), console.info() and console.error() will produce logs with timestamps as expected.
The following example creates a basic app that simply creates a single log.
import { Context, Devvit } from '@devvit/public-api';
Devvit.addMenuItem({
location: 'post',
label: 'Create a log!',
onPress: (event, context) => {
console.log("Action called!");
context.ui.showToast(`Sucessfully logged!`);
}
});
export default Devvit;
Stream logs
Once you have installed the app, open a terminal to your app directory on your local machine and run devvit logs <subreddit name> [optional: app name]. For example:
devvit logs my-subreddit
You should now see logs streaming onto your console:
=============================== streaming logs for my-app on my-subrredit ================================
[DEBUG] Dec 8 15:55:50 Action called!
Currently, console.log calls will only stream when they are run from the server (not the client).
Custom post apps use a client-side runtime to speed up execution, so console.log calls won't always show up in Devvit logs or Devvit playtest commands. However, these calls will show up in other dev tools (like Chrome) when viewing the app during a playtest.
Historical logs
You can view historical logs by using the --since=XX flag. You can use the following shorthand:
Xh: show logs in the past X hoursXd: show logs in the past X daysXw: show logs in the past X weeksXm: show logs in the past X months
The following example will show logs from my-app on my-subreddit in the past day.
devvit logs my-subreddit --since=1d
You will now see historical logs created by your app on this subreddit:
=============================== streaming logs for my-app on my-subrredit ================================
[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!