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

asked on

Log files in snappy ubuntu core

Hello
where is the logs files are stored in the snap that runs on edge boxes with ubuntu core 16.04
Thanks  in advance
Avatar of dfke
dfke

Hi,

You can use journalctl for this.

read up here .

Cheers
Avatar of Seham Hammad

ASKER

I have tried that but it gives me the live logs and I am looking for the logs should include the status where the system has been disconnected.
Thanks very much for your reply.
Likely...

/var/log

Open in new window


And any software can log anywhere, so if you're looking for a specific log (sometimes logs end up the oddest places), mention the exact log you're missing + likely someone can pass along where it lives.
here is my code, the connectionLog.txt in the Logs folder, but the snap doesn't find the file location, how will let it know the location of the file

#!/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;
    });

}
You're using a relative path (./Logs/connectionLog) which will never work... unless you have your code switch to /var/log as it's working directory at runtime. A very bad idea.

Just change your path to /var/log/connection/foo.log or whatever you name your log.

Also not, you should use lowercase log rather than Logs, else you'll be storing your logs completely outside the system log area.
Thanks very much fro your reply, will try this right now and will let you know
Just tried your solution but this what I  keep getting:
 Disconnected at 2019-02-19, 14:31:39
Feb 19 14:31:39 seham-VirtualBox ping-check-microservice.ping-check-microservice[7892]: /snap/ping-check-microservice/x11/lib/node_modules/checkconnectivity/checkConnectivity.js:57
Feb 19 14:31:39 seham-VirtualBox ping-check-microservice.ping-check-microservice[7892]:         if (err) throw err;
Feb 19 14:31:39 seham-VirtualBox ping-check-microservice.ping-check-microservice[7892]:                  ^
Feb 19 14:31:39 seham-VirtualBox ping-check-microservice.ping-check-microservice[7892]: Error: ENOENT: no such file or directory, open '/var/log/mylogs/connection.log'
Feb 19 14:31:39 seham-VirtualBox systemd[1]: snap.ping-check-microservice.ping-check-microservice.service: Main process exited, code=exited, status=1/FAILURE
Feb 19 14:31:39 seham-VirtualBox systemd[1]: snap.ping-check-microservice.ping-check-microservice.service: Failed with result 'exit-code'.
Feb 19 14:31:39 seham-VirtualBox systemd[1]: snap.ping-check-microservice.ping-check-microservice.service: Service hold-off time over, scheduling restart.
Feb 19 14:31:39 seham-VirtualBox systemd[1]: snap.ping-check-microservice.ping-check-microservice.service: Scheduled restart job, restart counter is at 1.
Feb 19 14:31:39 seham-VirtualBox systemd[1]: Stopped Service for snap application ping-check-microservice.ping-check-microservice.
Feb 19 14:31:39 seham-VirtualBox systemd[1]: Started Service for snap application ping-check-microservice.ping-check-microservice.
Feb 19 14:31:41 seham-VirtualBox ping-check-microservice.ping-check-microservice[8518]: Disconnected at 2019-02-19, 14:31:41
Feb 19 14:31:41 seham-VirtualBox ping-check-microservice.ping-check-microservice[8518]: /snap/ping-check-microservice/x11/lib/node_modules/checkconnectivity/checkConnectivity.js:57
Feb 19 14:31:41 seham-VirtualBox ping-check-microservice.ping-check-microservice[8518]:         if (err) throw err;
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.