A simple logger that duplicates console logs to a local file, Dropbox and Telegram. More details in this post.
-
Install package:
pip install cloudlog
-
Import
CloudLog
class:from cloudlog import CloudLog
-
Log text by simply calling a
CloudLog
instance:log = CloudLog(root_path='~/logs') log('Some important stuff happening.') log('And again!') log('Luckily, it\'s all safe now in a local file.')
-
Add
pyplot
plots as images in the same folder:from matplotlib import pyplot # Draw a plot x = range(42) pyplot.plot(x, x) pyplot.xlabel('Amount of logs') pyplot.ylabel('Coolness of your app') pyplot.grid(True) # Call it before calling `pyplot.show()`. log.add_plot() pyplot.show()
In order to sync your logs and plots to Dropbox:
- Create a Dropbox app with
App folder
access 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.
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.