Copyright ©

Mongoose OS Forum


logging output for mJS

It would be very helpful if I can do something like this in mJS and receive the log in my rsyslog machine:

syslog(LOG_LEVEL_DEBUG, "My button handler is triggered.");

Currently I need serial console to see print out of mJS, while the device is in the ceiling :-{

Please let me know if this is already doable.

- Michael


  • rojerrojer Dublin, Ireland

    we actually have a UDP logging feature: mos config-set debug.udp_log_addr= will send STDERR output to
    it's not in syslog format (that seemed too elaborate to implement and i needed something quick), but you can set up nc to catch it.

  • @rojer, I am already using rsyslog to receive log data from mongoose. The point is: I cannot send log data from mJS; there is no print_to_stderr function.

  • SergeySergey Dublin, Ireland

    @michaelfung could you elaborate why @rojer 's suggestion is not working for you?

  • Actually it is trivial to do, I have done it myself. Here's my unpolished code:

    ----------------------- src/main.c -----------------------
    +void jslog(int8_t level ,const char *msg) {
    +   LOG(level, ("%s", msg));
    -------------------- fs/api_custom.js --------------------
    new file mode 100644
    index 0000000..6f9ea0b
    @@ -0,0 +1,16 @@
    +// Custom API.
    +let LL = {
    +   NONE: -1,
    +   ERROR: 0,
    +   WARN: 1,
    +   INFO: 2,
    +   DEBUG: 3,
    +   VERBOSE_DEBUG: 4
    +let Custom = {
    +   // use system logging so that it can go to udp log server
    +   Log: ffi('void jslog(int, char *)')

    Now in mJS I can:

    Custom.Log(LL.ERROR, 'Houston, we have a main B bus undervolt.');

    And view it in my rsyslog server.


Sign In or Register to comment.