cloudlog
cloudlog copied to clipboard
A simple logger that duplicates console logs to a file, Dropbox and Telegram.
cloudlog
A simple logger that duplicates console logs to a local file, Dropbox and Telegram. More details in this post.
How to use
-
Install package:
ip install cloudlog -
Import
CloudLogclass:rom cloudlog import CloudLog -
Log text by simply calling a
CloudLoginstance:og = CloudLog(root_path='~/logs') og('Some important stuff happening.') og('And again!') og('Luckily, it\'s all safe now in a local file.') -
Add
pyplotplots as images in the same folder:rom matplotlib import pyplot Draw a plot = range(42) yplot.plot(x, x) yplot.xlabel('Amount of logs') yplot.ylabel('Coolness of your app') yplot.grid(True) Call it before calling `pyplot.show()`. og.add_plot() yplot.show()
Dropbox
In order to sync your logs and plots to Dropbox:
- Create a Dropbox app with
App folderaccess type. - Get your Dropbox access token and provide it in initialiser.
- Call
sync()in order to dispatch log file to your Dropbox app folder.
log = CloudLog(root_path='~/logs', dropbox_token='YOUR_DROPBOX_TOKEN_HERE')
log('Some important stuff happening again.')
log('Luckily, it\'s all safe now. In the cloud!')
log.sync()
Plots are being synced to Dropbox folder by default.
Telegram
You may as well get notifications in a Telegram chat, with logs and plots being sent to you.
- Create a Telegram bot.
- Get your Telegram Bot API access token
- Find out your Telegram chat or user ID.
- Provide both values in the initialiser.
log = CloudLog(root_path='~/logs', telegram_token='YOUR_TELEGRAM_TOKEN', telegram_chat_id='CHAT_ID')
log('Some important stuff once more.')
log('Luckily, it\'s all safe now in a local file. AND you\'re notified — how cool is that?')
log.sync(notify=True, message='I\'m pregnant.')
Specify the same notify flag for plots for them to be sent to a Telegram chat as well:
...
log.add_plot(notify=True)
Since one may be tempted to dispatch a bunch of updates at the same time, the user will not be notified about messages containing files, such as plots and logs — only about the message passed to sync() method.