Link to home
Start Free TrialLog in
Avatar of Seham Hammad
Seham Hammad

asked on

Log files in snappy ubuntu core

Hi
I am running Node.js app to check for connectivity and reboot if the timer reaches 0, and I am logging the status on a log file but when I run this code as a snap on ubuntu core, I can not find where the log files are in snap.
here is my code:
#!/usr/bin/env node
const moment = require('moment');
const shutdown = require('electron-shutdown-command');
const electron = require('electron');

const fs = require('fs');

let counter = 0;

function checkInternet(cb) {
    setInterval(function(){
    require('dns').lookup('google.com',function(err) {
        if (err && err.code ===  "ENOTFOUND") {
            cb(false);
        } else {
            cb(true);
        }
    }); }, 30000);
}

function rebootEdgeBox(){
    shutdown.reboot();
    console.log('Shutting down now');
   
}


checkInternet(function (isConnected) {
        if (isConnected) {
            console.log('alive');
             counter =0;
        } else {

            const timeStamp = moment().format('YYYY-MM-DD, HH:mm:ss');
            const status = 'Disconnected at ' + timeStamp;
            console.log(status);
            counter += 1;
            vortexLog(status);
            if (counter === 10){
                counter = 0;
                console.log('ji');
               rebootEdgeBox();


            }
        }

    });

function vortexLog(string) {
    fs.appendFile('./Logs/connectionLog', string + "\r\n", function (err) {
        if (err) throw err;
    });

}
Avatar of noci
noci

You should be able to find the file using:

The file should be in the Log directory in the "current directory"  where the process runs in.
This './Logs/connectionLog' sp[ecifies a file in the Current directory, then go down into Logs then check there for the file
connectionLog.

another option is:
            find / -name connectionLog -ls
or more relevant:
            find / -name connectionLog -ls | grep Logs
Avatar of Seham Hammad

ASKER

I have tried these two options, I can see the log file but its seems that the snap is not writting to the log
thanks
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.