Git Product home page Git Product logo

telelog's Introduction

telelog

Telegram logger for long experiments.

First, install the dependencies:

Get your Telegram API working:

Set the appropriate environment variables in ~/.bashrc:

export TELELOG_DIR="YOUR_PATH_TO_TELELOG"
export PATH=$TELELOG_DIR:$PATH
export TELEGRAM_API_ID="YOUR API ID"
export TELEGRAM_API_HASH="YOUR API HASH"
export TELEGRAM_BOT_TOKEN="YOUR BOT TOKEN ACQUIRED FROM BOTFATHER"
export TELEGRAM_RECIPIENT="YOUR RECIPIENT'S ID IN TELEGRAM"
export TELEGRAM_REDIS_CHANNEL="telegram_queue"

Make sure the redis server is running:

redis-cli ping

Set the correct permissions:

chmod +x init_telegram_client.py 
chmod +x telelog_worker.py
chmod +x telelog
chmod +w init_telegram_client.py
chmod +w telelog_worker.py

Initialize your telegram session (You will be asked to provide your phone number, password, and a verification code):

python3 init_telegram_client.py

Make sure the telelog worker is running (This step can be skipped since the telelog command will run the worker if it's not already running):

python3 telelog_worker.py &

You might want to use taskset to bind it to a specific processor. In this example, it is binded to the last one.

taskset -c $((`nproc` - 1)) python3 telelog_worker.py & 

Netflix and log :)

From the command line:

telelog "Hello world"

From a python script:

import os
import redis

r = redis.Redis(host='localhost', port=6379, db=0)

channel_name = os.getenv("TELEGRAM_REDIS_CHANNEL")
r.publish(channel_name, "Hello world")

From a python script with proper logging setup:

from telelog_handler import TelelogHandler
import logging 
import os 

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
telelog_handler = TelelogHandler(channel=os.getenv("TELEGRAM_REDIS_CHANNEL"))
telelog_handler.setFormatter(logging.Formatter('%(name)s - %(asctime)s - %(levelname)s\n`%(message)s`'))
log = logging.getLogger(__name__)
log.addHandler(telelog_handler)

log.info("Hello world")

telelog's People

Contributors

mohammadkhalaji avatar

Stargazers

Mahtab (Mattie) Nejati avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.