# Silly logging questions - I shot myself in the foot

**URL:** <https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999>\
**Category:** General\
**Created:** [9 September 2025 21:11 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999 "2025-09-09T21:11:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [9 September 2025 21:11 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/1 "2025-09-09T21:11:09Z")

</div>

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! 🙂 thanks

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 September 2025 22:39 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/2 "2025-09-09T22:39:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [10 September 2025 01:37 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/3 "2025-09-10T01:37:30Z")

</div>

> [@pconroy328](#):
>
> 9 Sep 15:03:01 - [warn] [function:Convert Uptime Seconds] end of converting uptime seconds  
> _**['17 days', ' 22:42:14.770000']**_

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 September 2025 03:03 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/4 "2025-09-10T03:03:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [10 September 2025 16:26 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/5 "2025-09-10T16:26:33Z")

</div>

Subscribes to an MQTT topic.

---

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [10 September 2025 16:27 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/6 "2025-09-10T16:27:30Z")

</div>

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. 😀

---

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [10 September 2025 16:28 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/7 "2025-09-10T16:28:53Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [10 September 2025 16:43 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/8 "2025-09-10T16:43:57Z")

</div>

FOUND IT! Sheeeeeeeeeeeeeeeeesh…………………….. I knew I was an idiot. 🙂

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!

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [10 September 2025 16:46 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/9 "2025-09-10T16:46:27Z")

</div>

> [@pconroy328](#):
>
> end of converting uptime seconds

Can you share the code in this function ?

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [11 September 2025 08:46 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/10 "2025-09-11T08:46:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [16 September 2025 12:26 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/11 "2025-09-16T12:26:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [16 September 2025 23:52 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/12 "2025-09-16T23:52:44Z")

</div>

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

```auto

// 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;

```

---

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [16 September 2025 23:53 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/13 "2025-09-16T23:53:27Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pconroy328](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pconroy328/32/82550_2.png) [@pconroy328](https://discourse.nodered.org/u/pconroy328)\
**Post date:** [16 September 2025 23:54 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/14 "2025-09-16T23:54:08Z")

</div>

Yes! That's what it was. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 September 2025 23:54 UTC](https://discourse.nodered.org/t/silly-logging-questions-i-shot-myself-in-the-foot/98999/15 "2025-09-30T23:54:32Z")

</div>

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