bear
bear•3mo ago

How do I enable console.log?

console.logs, console.infos don't seem to show up in the log in the dashboard, nor when using npx convex dev --tail-logs, am I missing something 🙂 ?
22 Replies
Convex Bot
Convex Bot•3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart•3mo ago
Are the logs inside of a convex function? Logs always print, nothing to enable.
ballingt
ballingt•3mo ago
Maybe you're looking at the wrong deployment in the dashboard?
erquhart
erquhart•3mo ago
Not showing in local dev either
ballingt
ballingt•3mo ago
@bear where are these console.logs, inside of a function that you're running? [edit: oops erquhart already asked this]
bear
bearOP•3mo ago
yep, normal console.log inside the handler and I do see my requests coming in
ballingt
ballingt•3mo ago
What kind of function is it? Could you paste the code for one? Are you using any npm libraries that might be monkeypatching or shadowing console?
bear
bearOP•3mo ago
export const create = mutation({
args: {
data: v.any()
},
handler: async (ctx, { data }) => {
const userId = await getAuthUserId(ctx);
console.warn('adsflkjasldkf');
console.info('PLEASE WORK', userId);
console.log('CHECKIN', userId);
const id = await ctx.db.insert('tasks', { ...data, createdBy: userId });

return id;
}
});
export const create = mutation({
args: {
data: v.any()
},
handler: async (ctx, { data }) => {
const userId = await getAuthUserId(ctx);
console.warn('adsflkjasldkf');
console.info('PLEASE WORK', userId);
console.log('CHECKIN', userId);
const id = await ctx.db.insert('tasks', { ...data, createdBy: userId });

return id;
}
});
no it's very barebones
ballingt
ballingt•3mo ago
What if you npx convex run yourfilename:create '{"data": 1}'
bear
bearOP•3mo ago
random, but any chance this has an effect? I get these on startup and every call, note that the "task" does get created
No description
ballingt
ballingt•3mo ago
Ah! Convex mutations are transactions, if one part doesn't go through then none of it does I don't think your deploys are taking then
bear
bearOP•3mo ago
really my tasks are created though
ballingt
ballingt•3mo ago
If schema validation fails, you can't push On the dashboard of this deployment in the functions tab, what is the code there?
bear
bearOP•3mo ago
OH wait so I have to fix my data to push?
ballingt
ballingt•3mo ago
or change your schema so that it matches your data you're trying to move from one schema to another schema, and the new one doesn't apply
bear
bearOP•3mo ago
I see
ballingt
ballingt•3mo ago
so you'll need to do a migration, or (probably easier for a small project) just change the data to match the new schema
bear
bearOP•3mo ago
makes sense, thank you
ballingt
ballingt•3mo ago
often a two-step proceess, e.g. addinga new field requires making the field optional in the schema, pushing that, then changing the data, then pushing the schema where it's required yeah you can't push your functions separately from your schema, they're always a package deal you can turn off schema enforcement if you want, that's a convenient way to iterate and then clean up later https://docs.convex.dev/database/schemas#schemavalidation-boolean
bear
bearOP•3mo ago
perfect 🙂
ballingt
ballingt•3mo ago
just beware that if you do that your TypeScript types may not be accurate, TypeScript won't know that some of the items in that table don't actually have that field (probably obvious, just making clear for anybody following along)
bear
bearOP•3mo ago
I'll make my fields optional for now, thanks again

Did you find this page helpful?