[SOLVED] System notifications from log file

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
theratuk
Level 2
Level 2
Posts: 56
Joined: Mon Feb 05, 2018 6:41 am

[SOLVED] System notifications from log file

Post by theratuk »

Hi all. Long term mint user (>5 years) but never done significant customisation to my system.

I now want to do the following and was wondering if anyone in the community could point me in a good direction.

I have a log file from abraunegg's onedrive client that outputs stuff like this:

Code: Select all

2022-Jan-16 14:40:14.9203443	Starting a sync with OneDrive
2022-Jan-16 14:40:14.9206537	Syncing changes from OneDrive ...
2022-Jan-16 14:40:16.1507118	Sync with OneDrive is complete
2022-Jan-16 14:40:40.7630634	Retry sync count: 1: Cannot open file `./Untitled Document' in mode `rb' (No such file or directory)
2022-Jan-16 14:40:41.4198398	Moving ./Untitled Document to ./linux_mint_is_great.txt
2022-Jan-16 14:40:41.9391852	Uploading new file ./linux_mint_is_great.txt ... done.
2022-Jan-16 14:40:45.4773655	Uploading new file ./linux_mint_is_great (copy).txt ... done.
2022-Jan-16 14:40:47.8734736	Uploading new file ./linux_mint_is_great (another copy).txt ... done.
2022-Jan-16 14:40:48.1857814	Starting a sync with OneDrive
2022-Jan-16 14:40:48.186048	Syncing changes from OneDrive ...
2022-Jan-16 14:40:49.4558493	Sync with OneDrive is complete
2022-Jan-16 14:40:59.2265195	Deleting item from OneDrive: ./linux_mint_is_great (copy).txt
2022-Jan-16 14:40:59.3837201	Deleting item from OneDrive: ./linux_mint_is_great.txt
2022-Jan-16 14:40:59.5461714	Deleting item from OneDrive: ./linux_mint_is_great (another copy).txt
The client is configured to output SOME log events to system notifications, but only very critical ones (e.g. can't connect to onedrive), and there is no option to notify on other issues (and no plans to do so).

What I would like is to configure my systemto display notifications for events in the log file above like "Uploading new file ...", "Deleting item from OneDrive...", and other matters I want to display (the alternative is running -tail on the log... but that displays absolutely everything and I won't even notice what events are going on).

So:

1. Is there a way to run system notifications off the log file? e.g. make it notify on every new line to the file?

2. Assuming that is possible, could I then filter only to display the lines starting with "Deleting", "Uploading" or other beginnings for notifications I want?

Thank you!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
abraunegg
Level 2
Level 2
Posts: 60
Joined: Thu Oct 03, 2019 10:18 pm

Re: System notifications from log file

Post by abraunegg »

and there is no option to notify on other issues (and no plans to do so)
This is not entirely accurate or true.

This is how you can solve this yourself:
1. Clone from github the client source and review the source code
2. Update log.d fileOnly function (line 75) and add 'notify(args);' before the line '// Write to log file' on line 78
3. Rebuild your client using your code change and install that client version
4. Ensure that you have enabled logging to write out a logfile - refer to documentation on how to do this

This should have the following effect:
* For every non verbose log output that should be written to a logfile, everything will also go to be notified ...

Review how this works for you and how much of an impact this is, and report back on GitHub
theratuk
Level 2
Level 2
Posts: 56
Joined: Mon Feb 05, 2018 6:41 am

Re: System notifications from log file

Post by theratuk »

Thanks abraunegg, appreciate the response. Apologies if what I said wasn't strictly true but I (mis)understood from your response on github this functionality wasn't going to be included any time soon... my mistake.

Meanwhile, maybe I'll have a go at this one day but the rebuilding my own client part I don't have time to learn how to do as I need to actually use it. Maybe I'll try on another laptop sometime though in the future, as a test. For now though this is a little beyond my skills (or rather time) which is why I was hoping for a shell script maybe from the actual log file.
abraunegg
Level 2
Level 2
Posts: 60
Joined: Thu Oct 03, 2019 10:18 pm

Re: System notifications from log file

Post by abraunegg »

theratuk wrote: Mon Jan 24, 2022 3:42 pm For now though this is a little beyond my skills (or rather time) which is why I was hoping for a shell script maybe from the actual log file.
You will spend more time futzing around with a shell script (modifying it, editing it, making it work) that you would by adding 1 or 2 lines into the place I have advised, then rebuilding your client and installing your modified version. You probably already have spent more time searching for that solution than it would take to make the code changes suggested.
theratuk
Level 2
Level 2
Posts: 56
Joined: Mon Feb 05, 2018 6:41 am

Re: System notifications from log file

Post by theratuk »

Haha, you might be right there... though the 'rebuilding your client' part is something I wouldn't even know where to start with, hence fear of unknown.

I now have this solution... shell script as:

Code: Select all

tail -n -0 -f <log file> | grep --line-buffered -e ^Deleting -e ^Uploading | while read line; do notify-send "Notification from <log file>" "$line"; done
If I run this on the log file it does the job for now :)
Locked

Return to “Software & Applications”