Log the errors of a line on a panel
When a product fails, someone will ask to see it. The Log widget is a whole page of the panel for that: the operator starts and stops the log, chooses between errors only and every product, and reads, filters and downloads the images the line kept, each with its result. The flow saves the images and the Log tells it what to save. In this guide you add a Log page to a biscuit line.
What you will learn
- How the Log and the flow share the work: the Log decides, the flow saves
- How to set up the Log widget
- How an operator reads the errors, logs every product, downloads images and clears the log
Before you start
You need a panel page with one group 12 columns wide for the widget; here the page «Line log» with the group «Log» (pages and groups are explained in Show inspection results on a panel). The flow already inspects the line and saves what the Log asks for:
- A «camera», here a from-dataset node that sends a pack of biscuits every two seconds after «start», and a segmentation model that finds the biscuits.
- «Check the pack», a function node that judges the pack (four biscuits make a good pack, anything else is an error) and writes what the Log shows:
msg.metadatawith the name of the image, its date, its result and its figures, and the boxes of the biscuits. Code at the end of this page. - «What to log», the gate that obeys the Log. See the first step.
rp-resizeand tworp-save-filenodes: a copy of 800 pixels for the screen, saved as<name>_Pack.jpgin/opt/storage/images/log/imageShowDir, and the original, saved as<name>_pack.jpgin/opt/storage/images/log/imageSaveDirfor an upload to a dataset.- «To the log», which tells the Log what was saved.
- Four nodes at the bottom that serve the saved images to the panel (see «Good to know»).
1. See how the flow obeys the Log
Double-click «What to log». The Log widget does not save images: it keeps three flow variables up to date, and this gate reads them before anything is saved.
flow.logModeistruewhile the log is on. The operator turns it on and off from the panel.flow.errorsOnlyistruewhile the operator asks for errors only, andfalsefor every product.flow.diskLowis the low-disk guard:truewhen the disk of the images folder has less than 10 GB free. The gate then saves nothing, and the Log page warns «Low disk space: new images are not being logged.» until there is room again. The controller of this guide has plenty of space, so the warning does not appear in the video.
rp-save-file has a guard of its own, «Disk Limit»: it skips saving when the disk is fuller than that percentage, 90 % by default.

2. Add the Log widget
Click «Cancel». Type ui-log in «filter nodes», drag the «log» node, in the «Renders» category, to the end of the chain and wire «To the log» to it. It is a whole Log page in one widget: the button to start and stop the log, the filter, the storage and a summary on the left, and the images on the right.

3. Choose its group and its folder
Double-click it and choose the group, here «Log». «Images folder» is the folder of the copies for the screen; leave the default, /opt/storage/images/log/imageShowDir, where the flow saves them. The Log keeps one small file per image in a metadata folder inside it, so that the log comes back after a restart, and expects the originals in the folder next to it, imageSaveDir. «Images per page» is how many images it shows before «Load more». Untick «Show mask checkbox» and «Show polygon checkbox»: these images only have boxes.

4. Name the image type and the source
Further down, set «Image types» to 1 and name it «Pack»: the Log shows the file <name>_Pack.jpg as that type. Set «Upload sources» to 1 and name it pack: when the operator uploads images to a dataset, the Log sends the originals <name>_pack.jpg of imageSaveDir. «Upload profiles» limits selecting, uploading and downloading to some users; empty, everyone can.

5. Deploy and start the line
Click «Done» and «Deploy», and press the «start» inject node. The Log starts with the log on and errors only, so the gate lets through only the packs that fail.
6. Open the Log page
Open «Panels» and the page «Line log». On the left, «STOP LOG» and the filter, with «LOGGING · Errors only» and the number of images; «Storage», the free space of the disk and the size of the log (measured every five minutes); and «Summary», the images of the log, NOK and OK, and the time of the last one. On the right, a card per image, newest first, with the boxes, the number of biscuits and the error. The page fits the window: the cards scroll inside it.

7. Open an error
Click a card. The image opens with the box and the confidence of each biscuit, the result, the error, the date and the name of the image; the panel on the right lists what the flow wrote in resume, here the biscuits found and expected. The arrows at the bottom go to the next and previous images, «BBOX» hides the boxes, and the buttons on the image adjust the brightness, rotate, zoom and show it full screen. New images keep arriving behind it: the image stays on screen until you close it.

8. Log every pack
Click «Close» and choose «All images». The Log sets flow.errorsOnly to false, the gate lets every pack through, and the good packs appear in green among the errors. The summary counts both. Errors only keeps the disk for what matters; every product is useful for a while, for example to collect images for a training.

9. Stop the log
Press «STOP LOG». The Log sets flow.logMode to false and the gate stops every pack: the inspection goes on, and the images already logged stay. Starting and stopping the log, and changing the filter, are kept on the controller and survive a restart.

10. Download some images
Drag over the cards you want, or click one with Shift held and then the others. The bar above shows how many are selected. «Download» → «Image» saves the selected images in one ZIP file, named after the time; «Upload» sends them to a dataset (see «Good to know»).

11. Clear the log
Press «Clear log» and confirm with «DELETE». The Log deletes the copies, the originals and their small files from the controller, and the page is empty again, ready for the next «START LOG». It cannot run while an upload is in progress.

The code of the flow
«Check the pack» judges each pack and writes what the Log shows:
// Four biscuits the model is sure of make a good pack; anything else is an error
const biscuits = msg.inference.filter((b) => b.confidence >= 0.5);
const n = biscuits.length;
const error = n < 4 ? "Missing biscuit" : n > 4 ? "Extra biscuit" : null;
const color = error ? "#e53935" : "#2e9e43";
// The name of the image: the time, with no "_" in it
const name = String(Date.now());
msg.metadata = {
name,
date: new Date().toISOString(),
isAnomalous: error !== null,
tag: n === 1 ? "1 biscuit" : n + " biscuits",
result: error ?? "Pack OK",
resume: { biscuits: { result: error ? "NOK" : "OK", found: n, expected: 4 } },
};
// The boxes to draw, with positions from 0 to 1
msg.bbox = biscuits.map((b) => ({
x_rel: b.xywhr.x, y_rel: b.xywhr.y, w_rel: b.xywhr.w, h_rel: b.xywhr.h, tag: "biscuit", score: b.confidence, color,
}));
// <name>_<type>: a copy for the screen, and the original for an upload
msg.showName = name + "_Pack.jpg";
msg.saveName = name + "_pack.jpg";
return msg;msg.metadatabecomes the entry of the log:name(the start of the file names, without_),date,isAnomalous(red whentrue, green whenfalse),tagandresult(the two texts of the card) andresume(the panel on the right of the image).- Boxes take positions from 0 to 1:
{ x_rel, y_rel, w_rel, h_rel, tag, score, color }.
«What to log» obeys the Log:
// The Log page decides what is saved; the flow obeys
// The operator stopped the log
if (!flow.get("logMode")) return null;
// Low disk: less than 10 GB free
if (flow.get("diskLow")) return null;
// Errors only: the good packs go by
const error = msg.metadata.isAnomalous;
if (flow.get("errorsOnly") && !error) return null;
return msg;«To the log» tells the Log which files were saved; the Log reads the type of each one from its name, <name>_<type>.jpg:
// The file saved for the screen, with its boxes; the facts of the pack are in msg.metadata
msg.payload = { imageShow: [{ filename: msg.showName, bbox: msg.bbox }] };
delete msg.image;
delete msg.show;
return msg;Good to know
Low disk space. With less than 10 GB free on the disk of «Images folder», the Log sets
flow.diskLow, warns on the page and colours the storage bar; a gate like «What to log» then saves nothing. The disk is checked every 30 seconds.Images on the panel. The Log loads each image from
/nodered/local/images/<path>and its thumbnail from/nodered/local/fit/400/images/<path>, where<path>is the file's path under/opt/storage/images; the Node-RED of the controller must serve those addresses, and «Images folder» must be under/opt/storage/images. The controller of this guide does not serve them, so the flow does it with four nodes: two «http in» nodes forGET /local/images/log/:dir/:fileandGET /local/fit/400/images/log/:dir/:file, a function node that turns the address into a file of the log, a «file in» node and an «http response» node with the headercontent-type: image/jpeg. The function node refuses any other file:jsconst { dir, file } = msg.req.params; // Only the files of the two folders of the log: no "..", no other folder if (!["imageShowDir", "imageSaveDir"].includes(dir) || !/^[\w.-]+$/.test(file) || file.includes("..")) { msg.statusCode = 404; msg.payload = ""; return [null, msg]; } msg.filename = "/opt/storage/images/log/" + dir + "/" + file; return [msg, null];Upload to a dataset. «Upload» opens a dialog with a dataset and a suffix for each upload source. Wire the first output of the Log to a
dataset-uploadnode with «Config» set tomsg.configTraining, and its output back to the Log; and the third output to alist-datasetnode, whose output goes back to the Log, for the list of datasets. As in Capture images on a panel and save them to a dataset. With «Remove after upload», an image uploaded leaves the log.Who did what. The second output sends
log_start,log_stop,log_show_errors,log_image_upload,log_stop_uploadandlog_clear, with the user of the panel inmsg._client, for an audit trail.After a restart. The log comes back from its
metadatafolder, and the switch and the filter fromlog-storein Node-RED's folder. An image whose files are deleted leaves the log.
Next steps
- Keep an image history on a panel
- Capture images on a panel and save them to a dataset
- Chart inspection results
Recorded on Rosepetal release 1.8.15, Node-RED 5.0.10.