Silly logging questions - I shot myself in the foot

So, I’m dumping something to the log and I’ll be dogged if I can figure out where I’m doing it??!?!

Here’s a snippet from the log:

9 Sep 15:01:01 - [warn] [function:Convert Uptime Seconds] end of converting uptime seconds
[ '17 days', ' 22:40:14.700000' ]
9 Sep 15:02:01 - [warn] [function:Convert Uptime Seconds] convertUptimeSecondsToString - start
9 Sep 15:02:01 - [warn] [function:Convert Uptime Seconds] convertUptimeSecondsToString - end
9 Sep 15:02:01 - [warn] [function:Convert Uptime Seconds] end of converting uptime seconds
[ '17 days', ' 22:41:14.730000' ]
9 Sep 15:03:01 - [warn] [function:Convert Uptime Seconds] convertUptimeSecondsToString - start
9 Sep 15:03:01 - [warn] [function:Convert Uptime Seconds] convertUptimeSecondsToString - end
9 Sep 15:03:01 - [warn] [function:Convert Uptime Seconds] end of converting uptime seconds
[ '17 days', ' 22:42:14.770000' ]

It’s the bolded, italicized output I can’t find!?

I recognized the data - it’s the uptime of the router. It’s transmitted in seconds and I have a routine that converts it to days, hours, minutes, etc.

That’s my data!?!? Only for the life of me, I cannot find where it’s being logged! All of my logging (I think) is done with “node.warn()” or “node.error(), node.status()” etc. Hence the log lines start with the date and time. But note the problem line does NOT have the date and time stamp.

Does anyone recognize a possible node-red function I could be calling that would log an entry withOUT the date and time stamp?

This is what I’m using on my Pi4 to dump the logfile: sudo journalctl -f -u nodered -o cat

I’m being a dummy and I’m not sure why! :slight_smile: thanks

How does Node-red obtain the router uptime - what nodes are involved?

Are you sure it's not created by the warn message above it, maybe it's just wrapped to next line, or you have a line break in the message ?

Just comment out that line and run the function to see if the message goes away.

Do you have a debug node attached, if yes, check its settings (where it is logging to).

Subscribes to an MQTT topic.

Ah - that’s a good thought. But I did comment out the line and that one output remains. I’m perplexed. Clearly it’s something I did. I just wish I knew what. :grinning_face:

Will do. I did a “Search” from NR for the word “days” and got hits in what appears to be only code. Var names. I suck at JS, so maybe I (or ChatGPT, that wrote the code) did something.

I’ll keep digging!

FOUND IT! Sheeeeeeeeeeeeeeeeesh…………………….. I knew I was an idiot. :slight_smile:

That data wasn’t router uptime, it was Pi uptime. They’re almost identical since they boot together. I had a “console.log()” in the code. That’s what was writing to the log with no date/time stamp.

Geebus.

It was silly, nothing fatal or even a problem. It was just bugging me.

Thanks all!

1 Like

Can you share the code in this function ?

It could just be a console.log() in a node, anything in the backend can just print to the console.

It looks like it's just printing the content of an array with 2 elements, so tracking it down could be tricky.

1 Like

That's the catch to writing code with chatGPT... make sure you tell it that this is for a node-red function node and not vanilla JS, and it will typically revert to node.warn() or something node-red friendly.

Sure - ChatGPT (or Claude) spit this out. Two ways:


// Example payload coming in:
//
// {"topic":"GL-MT300N-V2","dateTime":"2025-09-04T12:35:01-06:00",
//    "uptime":{"uptime_seconds":1109631.59,"idle_seconds":917449.73,"load1":0.20,"load5":0.21,"load15":0.23},
//    "system":{"hostname":"GL-MT300N-V2"},
//    "connectivity":{"gateway_reachable":true,"gateway":"192.168.43.1"},
//    "interfaces":{
//          "ra0":{ "interface":"ra0","ESSID":"fooblatz",
//                  "AccessPoint":"94:83:C4:64:0A:EE","Mode":"Client",
//                  "Channel":"1","Frequency":"(2.412 GHz)",
//                  "HTMode":"Channel:","BitRate":"300.0 MBit/s",
//                  "Encryption":"unknown","Type":"mtk",
//                  "HWMode":"HW","PHY":"no"},
//          "apcli0":{"interface":"apcli0","ESSID":"fooblatz2","AccessPoint":"C0:17:4D:66:12:9A","Mode":"Client","Channel":"1","Frequency":"(2.412 GHz)","HTMode":"Channel:","BitRate":"300.0 MBit/s","Encryption":"unknown","Type":"mtk","HWMode":"HW","PHY":"no"}}}
//
//

function convertUptimeSeconds(jsonData) {
    // Parse JSON if it's a string
    const data = typeof jsonData === 'string' ? JSON.parse(jsonData) : jsonData;
    
    // Get the uptime seconds value
    const uptimeSeconds = data.uptime.uptime_seconds;
    
    // Convert to days, hours, minutes, seconds
    const days = Math.floor(uptimeSeconds / 86400);
    const hours = Math.floor((uptimeSeconds % 86400) / 3600);
    const minutes = Math.floor((uptimeSeconds % 3600) / 60);
    const seconds = Math.floor(uptimeSeconds % 60);
    
    // Create the formatted uptime object
    const formattedUptime = {
        days: days,
        hours: hours,
        minutes: minutes,
        seconds: seconds,
        total_seconds: uptimeSeconds // Keep original value for reference
    };
    
    // Replace uptime_seconds with the formatted uptime
    data.uptime.uptime_seconds = formattedUptime;
    return data;
}

// Example usage:
//const jsonInput = {"topic":"GL-MT300N-V2","dateTime":"2025-09-04T12:35:01-06:00","uptime":{"uptime_seconds":1109631.59,"idle_seconds":917449.73,"load1":0.20,"load5":0.21,"load15":0.23},"system":{"hostname":"GL-MT300N-V2"},"connectivity":{"gateway_reachable":true,"gateway":"192.168.43.1"},"interfaces":{"ra0":{"interface":"ra0","ESSID":"fooblatz","AccessPoint":"94:83:C4:64:0A:EE","Mode":"Client","Channel":"1","Frequency":"(2.412 GHz)","HTMode":"Channel:","BitRate":"300.0 MBit/s","Encryption":"unknown","Type":"mtk","HWMode":"HW","PHY":"no"},"apcli0":{"interface":"apcli0","ESSID":"fooblatz2","AccessPoint":"C0:17:4D:66:12:9A","Mode":"Client","Channel":"1","Frequency":"(2.412 GHz)","HTMode":"Channel:","BitRate":"300.0 MBit/s","Encryption":"unknown","Type":"mtk","HWMode":"HW","PHY":"no"}}};

//const result = convertUptimeSeconds(jsonInput);
//console.log(JSON.stringify(result, null, 2));

// Alternative version that returns a string format instead of object:
function convertUptimeSecondsToString(jsonData) {
    const data = typeof jsonData === 'string' ? JSON.parse(jsonData) : jsonData;
    const uptimeSeconds = data.uptime.uptime_seconds;
    
    const days = Math.floor(uptimeSeconds / 86400);
    const hours = Math.floor((uptimeSeconds % 86400) / 3600);
    const minutes = Math.floor((uptimeSeconds % 3600) / 60);
    const seconds = Math.floor(uptimeSeconds % 60);
    
    // Replace with formatted string
    //data.uptime.uptime_seconds = `${days}d ${hours}:${minutes}:${seconds}`;

    data.uptime.uptime_formatted = `${days}d ${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
    return data;
}

const newPayload = convertUptimeSecondsToString(msg.payload);
msg.payload = newPayload;
return msg;

Good to know. I wasn't sure how much NR the AI engines knew. I'll try adding it to my prompts next time. Thank you!

Yes! That's what it was. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.