# Another LOG question

**URL:** <https://discourse.nodered.org/t/another-log-question/68608>\
**Category:** General\
**Tags:** function-node\
**Created:** [5 October 2022 20:24 UTC](https://discourse.nodered.org/t/another-log-question/68608 "2022-10-05T20:24:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandmman](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Sandmman](https://discourse.nodered.org/u/Sandmman)\
**Post date:** [5 October 2022 20:24 UTC](https://discourse.nodered.org/t/another-log-question/68608/1 "2022-10-05T20:24:54Z")

</div>

So, I'm building a light function using a logarithmic function, in this case a LOG15, In excel it gives me exactly what I need, a value from 0 to 255 based on an input of 1000 to 1.

So I could use a

```auto
function baselog(x, y) {
     return Math.log(y) / Math.log(x);
    }
newMsg = baselog(1000, 15);
return newMsg;

```

but that returns an error.

---

<div class="post-metadata">

**Author:** ![Sandmman](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Sandmman](https://discourse.nodered.org/u/Sandmman)\
**Post date:** [5 October 2022 21:01 UTC](https://discourse.nodered.org/t/another-log-question/68608/3 "2022-10-05T21:01:16Z")

</div>

Never mind, fixed it.....

```auto
function baselog(x, y) {
  return Math.log(y) / Math.log(x);
} 

msg.payload[2] = baselog(msg.payload[1], msg.payload[0]);
return msg;

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 October 2022 21:01 UTC](https://discourse.nodered.org/t/another-log-question/68608/4 "2022-10-05T21:01:58Z")

</div>

> [@Sandmman](#):
>
> that returns an error.

It returns an error because a function node must return an object, also, I think you have x and y the wrong way round. Try this in a function node

```auto
// returns payload with log base 15 of incoming payload
msg.payload = baseLog(msg.payload, 15)
return msg;

// returns log of x base y
function baseLog(x, y) {
    return Math.log(x) / Math.log(y);
}

```

---

<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:** [4 December 2022 21:02 UTC](https://discourse.nodered.org/t/another-log-question/68608/5 "2022-12-04T21:02:01Z")

</div>

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