improved logging

This commit is contained in:
zadam 2022-04-19 23:36:21 +02:00
parent 643a5e5b16
commit 3b58b83f8b
8 changed files with 25 additions and 25 deletions

View File

@ -67,7 +67,7 @@ function getNoteTitle(childNoteId, parentNoteId) {
const parentNote = becca.notes[parentNoteId]; const parentNote = becca.notes[parentNoteId];
if (!childNote) { if (!childNote) {
log.info(`Cannot find note in cache for noteId ${childNoteId}`); log.info(`Cannot find note in cache for noteId '${childNoteId}'`);
return "[error fetching title]"; return "[error fetching title]";
} }
@ -162,7 +162,7 @@ function getNotePath(noteId) {
const note = becca.notes[noteId]; const note = becca.notes[noteId];
if (!note) { if (!note) {
console.trace(`Cannot find note ${noteId} in cache.`); console.trace(`Cannot find note '${noteId}' in cache.`);
return; return;
} }

View File

@ -238,7 +238,7 @@ class Note extends AbstractEntity {
setContent(content, ignoreMissingProtectedSession = false) { setContent(content, ignoreMissingProtectedSession = false) {
if (content === null || content === undefined) { if (content === null || content === undefined) {
throw new Error(`Cannot set null content to note ${this.noteId}`); throw new Error(`Cannot set null content to note '${this.noteId}'`);
} }
if (this.isStringNote()) { if (this.isStringNote()) {
@ -260,7 +260,7 @@ class Note extends AbstractEntity {
pojo.content = protectedSessionService.encrypt(pojo.content); pojo.content = protectedSessionService.encrypt(pojo.content);
} }
else if (!ignoreMissingProtectedSession) { else if (!ignoreMissingProtectedSession) {
throw new Error(`Cannot update content of noteId=${this.noteId} since we're out of protected session.`); throw new Error(`Cannot update content of noteId '${this.noteId}' since we're out of protected session.`);
} }
} }

View File

@ -124,7 +124,7 @@ class NoteShort {
return JSON.parse(content); return JSON.parse(content);
} }
catch (e) { catch (e) {
console.log(`Cannot parse content of note ${this.noteId}: `, e.message); console.log(`Cannot parse content of note '${this.noteId}': `, e.message);
return null; return null;
} }

View File

@ -179,7 +179,7 @@ class Froca {
const searchResultNoteIds = await server.get('search-note/' + note.noteId); const searchResultNoteIds = await server.get('search-note/' + note.noteId);
if (!Array.isArray(searchResultNoteIds)) { if (!Array.isArray(searchResultNoteIds)) {
throw new Error(`Search note ${note.noteId} failed: ${searchResultNoteIds}`); throw new Error(`Search note '${note.noteId}' failed: ${searchResultNoteIds}`);
} }
// reset all the virtual branches from old search results // reset all the virtual branches from old search results
@ -254,7 +254,7 @@ class Froca {
return null; return null;
} }
else if (!noteId) { else if (!noteId) {
console.trace(`Falsy noteId ${noteId}, returning null.`); console.trace(`Falsy noteId '${noteId}', returning null.`);
return null; return null;
} }
@ -312,7 +312,7 @@ class Froca {
if (!this.noteComplementPromises[noteId]) { if (!this.noteComplementPromises[noteId]) {
this.noteComplementPromises[noteId] = server.get('notes/' + noteId) this.noteComplementPromises[noteId] = server.get('notes/' + noteId)
.then(row => new NoteComplement(row)) .then(row => new NoteComplement(row))
.catch(e => console.error(`Cannot get note complement for note ${noteId}`)); .catch(e => console.error(`Cannot get note complement for note '${noteId}'`));
// we don't want to keep large payloads forever in memory so we clean that up quite quickly // we don't want to keep large payloads forever in memory so we clean that up quite quickly
// this cache is more meant to share the data between different components within one business transaction (e.g. loading of the note into the tab context and all the components) // this cache is more meant to share the data between different components within one business transaction (e.g. loading of the note into the tab context and all the components)

View File

@ -138,7 +138,7 @@ function processContent(images, note, content) {
value: imageNote.noteId value: imageNote.noteId
}).save(); }).save();
log.info(`Replacing ${imageId} with ${url} in note ${note.noteId}`); log.info(`Replacing '${imageId}' with '${url}' in note '${note.noteId}'`);
rewrittenContent = utils.replaceAll(rewrittenContent, imageId, url); rewrittenContent = utils.replaceAll(rewrittenContent, imageId, url);
} }

View File

@ -96,7 +96,7 @@ function sortChildNotes(req) {
const noteId = req.params.noteId; const noteId = req.params.noteId;
const {sortBy, sortDirection} = req.body; const {sortBy, sortDirection} = req.body;
log.info(`Sorting ${noteId} children with ${sortBy} ${sortDirection}`); log.info(`Sorting '${noteId}' children with ${sortBy} ${sortDirection}`);
const reverse = sortDirection === 'desc'; const reverse = sortDirection === 'desc';
@ -196,11 +196,11 @@ function changeTitle(req) {
const note = becca.getNote(noteId); const note = becca.getNote(noteId);
if (!note) { if (!note) {
return [404, `Note ${noteId} has not been found`]; return [404, `Note '${noteId}' has not been found`];
} }
if (!note.isContentAvailable()) { if (!note.isContentAvailable()) {
return [400, `Note ${noteId} is not available for change`]; return [400, `Note '${noteId}' is not available for change`];
} }
const noteTitleChanged = note.title !== title; const noteTitleChanged = note.title !== title;
@ -289,10 +289,10 @@ function uploadModifiedFile(req) {
const note = becca.getNote(noteId); const note = becca.getNote(noteId);
if (!note) { if (!note) {
return [404, `Note ${noteId} has not been found`]; return [404, `Note '${noteId}' has not been found`];
} }
log.info(`Updating note ${noteId} with content from ${filePath}`); log.info(`Updating note '${noteId}' with content from ${filePath}`);
noteRevisionService.createNoteRevision(note); noteRevisionService.createNoteRevision(note);

View File

@ -139,7 +139,7 @@ function createNewNote(params) {
triggerNoteTitleChanged(note); triggerNoteTitleChanged(note);
triggerChildNoteCreated(note, parentNote); triggerChildNoteCreated(note, parentNote);
log.info(`Created new note ${note.noteId}, branch ${branch.branchId} of type ${note.type}, mime ${note.mime}`); log.info(`Created new note '${note.noteId}', branch '${branch.branchId}' of type '${note.type}', mime '${note.mime}'`);
return { return {
note, note,
@ -285,10 +285,10 @@ async function downloadImage(noteId, imageUrl) {
imageUrlToNoteIdMapping[imageUrl] = note.noteId; imageUrlToNoteIdMapping[imageUrl] = note.noteId;
log.info(`Download of ${imageUrl} succeeded and was saved as image note ${note.noteId}`); log.info(`Download of '${imageUrl}' succeeded and was saved as image note '${note.noteId}'`);
} }
catch (e) { catch (e) {
log.error(`Download of ${imageUrl} for note ${noteId} failed with error: ${e.message} ${e.stack}`); log.error(`Download of '${imageUrl}' for note '${noteId}' failed with error: ${e.message} ${e.stack}`);
} }
} }
@ -373,7 +373,7 @@ function downloadImages(noteId, content) {
const origNote = becca.getNote(noteId); const origNote = becca.getNote(noteId);
if (!origNote) { if (!origNote) {
log.error(`Cannot find note ${noteId} to replace image link.`); log.error(`Cannot find note '${noteId}' to replace image link.`);
return; return;
} }
@ -394,7 +394,7 @@ function downloadImages(noteId, content) {
scanForLinks(origNote); scanForLinks(origNote);
console.log(`Fixed the image links for note ${noteId} to the offline saved.`); console.log(`Fixed the image links for note '${noteId}' to the offline saved.`);
} }
}); });
}, 5000); }, 5000);
@ -491,7 +491,7 @@ function updateNote(noteId, noteUpdates) {
const note = becca.getNote(noteId); const note = becca.getNote(noteId);
if (!note.isContentAvailable()) { if (!note.isContentAvailable()) {
throw new Error(`Note ${noteId} is not available for change!`); throw new Error(`Note '${noteId}' is not available for change!`);
} }
saveNoteRevision(note); saveNoteRevision(note);
@ -533,7 +533,7 @@ function undeleteNote(noteId, taskContext) {
const note = sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId]); const note = sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId]);
if (!note.isDeleted) { if (!note.isDeleted) {
log.error(`Note ${noteId} is not deleted and thus cannot be undeleted.`); log.error(`Note '${noteId}' is not deleted and thus cannot be undeleted.`);
return; return;
} }

View File

@ -76,7 +76,7 @@ function register(router) {
const note = shaca.getNote(noteId); const note = shaca.getNote(noteId);
if (!note) { if (!note) {
return res.status(404).send(`Note ${noteId} not found`); return res.status(404).send(`Note '${noteId}' not found`);
} }
addNoIndexHeader(note, res); addNoIndexHeader(note, res);
@ -89,7 +89,7 @@ function register(router) {
const note = shaca.getNote(noteId); const note = shaca.getNote(noteId);
if (!note) { if (!note) {
return res.status(404).send(`Note ${noteId} not found`); return res.status(404).send(`Note '${noteId}' not found`);
} }
addNoIndexHeader(note, res); addNoIndexHeader(note, res);
@ -110,7 +110,7 @@ function register(router) {
const image = shaca.getNote(req.params.noteId); const image = shaca.getNote(req.params.noteId);
if (!image) { if (!image) {
return res.status(404).send(`Note ${noteId} not found`); return res.status(404).send(`Note '${req.params.noteId}' not found`);
} }
else if (image.type !== 'image') { else if (image.type !== 'image') {
return res.status(400).send("Requested note is not an image"); return res.status(400).send("Requested note is not an image");
@ -129,7 +129,7 @@ function register(router) {
const note = shaca.getNote(noteId); const note = shaca.getNote(noteId);
if (!note) { if (!note) {
return res.status(404).send(`Note ${noteId} not found`); return res.status(404).send(`Note '${noteId}' not found`);
} }
addNoIndexHeader(note, res); addNoIndexHeader(note, res);