|
| 1 | +# 🚀 telegram-logger-client: Your Log's New Best Friend |
| 2 | + |
| 3 | +Welcome to the telegram-logger-client - where your logs go to become stars! |
| 4 | + |
| 5 | +## 🛠 Prerequisites |
| 6 | + |
| 7 | +Before you dive in, make sure you've got your backstage pass ready: |
| 8 | + |
| 9 | +1. You'll need to set up and run the telegram-logger service. It's like the bouncer at the club - without it, your logs aren't getting in. |
| 10 | + |
| 11 | +2. Head over to [https://github.com/psyb0t/telegram-logger](https://github.com/psyb0t/telegram-logger) for the VIP instructions on setting up the telegram-logger service. |
| 12 | + |
| 13 | +3. Once you've got that service up and running, come back here and let's make some noise! |
| 14 | + |
| 15 | +## 🎭 Installation (No Secret Handshake Required) |
| 16 | + |
| 17 | +Install this badass as a module and executable: |
| 18 | + |
| 19 | +```shell |
| 20 | +pip install telegram-logger-client |
| 21 | +``` |
| 22 | + |
| 23 | +Go with `pipx` to just use it as an executable: |
| 24 | + |
| 25 | +```shell |
| 26 | +pipx install telegram-logger-client |
| 27 | +``` |
| 28 | + |
| 29 | +## 🕹️ Usage (AKA How to Make Some Noise) |
| 30 | + |
| 31 | +### 🐍 As a Python Module |
| 32 | + |
| 33 | +Summon the TelegramLoggerClient in your Python code: |
| 34 | + |
| 35 | +```python |
| 36 | +from telegram_logger_client import TelegramLoggerClient |
| 37 | + |
| 38 | +# Create your logger |
| 39 | +logger = TelegramLoggerClient("https://your-logger-url.com", "your-secret-token") |
| 40 | + |
| 41 | +# Send a log (it's like tweeting, but geekier) |
| 42 | +logger.send_log( |
| 43 | + caller="CoffeeBot", |
| 44 | + level="warning", |
| 45 | + message="Coffee levels critically low!", |
| 46 | + error="Caffeine deficiency detected", |
| 47 | + request_id="coffee-run-42", |
| 48 | + trace_id="from-bed-to-coffee-machine", |
| 49 | + span_id="mug-to-mouth", |
| 50 | + data={"coffee_type": "Espresso", "sugar": False, "milk": "Oat"} |
| 51 | +) |
| 52 | +``` |
| 53 | + |
| 54 | +### 🖥️ Command Line Magic |
| 55 | + |
| 56 | +First, set up your secret lair: |
| 57 | + |
| 58 | +```shell |
| 59 | +export TELEGRAM_LOGGER_BASE_URL=https://your-logger-url.com |
| 60 | +export TELEGRAM_LOGGER_X_ID=your-secret-token |
| 61 | +``` |
| 62 | + |
| 63 | +Now, shout into the void (or just send a log): |
| 64 | + |
| 65 | +```shell |
| 66 | +telegram-logger-client \ |
| 67 | + --caller "WeatherBot" \ |
| 68 | + --level "info" \ |
| 69 | + --message "It's raining cats and dogs!" \ |
| 70 | + --error "Umbrella malfunction" \ |
| 71 | + --request-id "weather-101" \ |
| 72 | + --trace-id "cloud-to-ground" \ |
| 73 | + --span-id "drop-to-splash" \ |
| 74 | + --data '{"temperature": "chilly", "wind": "breezy"}' |
| 75 | +``` |
| 76 | + |
| 77 | +Want to see every little detail? Add the `--debug` flag: |
| 78 | + |
| 79 | +```shell |
| 80 | +telegram-logger-client \ |
| 81 | + --debug \ |
| 82 | + --caller "WeatherBot" \ |
| 83 | + --level "info" \ |
| 84 | + --message "It's raining cats and dogs!" |
| 85 | +``` |
| 86 | + |
| 87 | +## 🎭 Logging Levels (Choose Your Adventure) |
| 88 | + |
| 89 | +The client itself has two modes: |
| 90 | + |
| 91 | +- Normal Mode (default): "Just the highlights" mode |
| 92 | +- Debug Mode: "I can hear a pin drop" mode |
| 93 | + |
| 94 | +Your logs, on the other hand, can be as dramatic as you want: |
| 95 | + |
| 96 | +- "info": "Just FYI" level |
| 97 | +- "warning": "Hmm, that's interesting" level |
| 98 | +- "error": "Houston, we have a problem" level |
| 99 | + |
| 100 | +## 🧙♂️ API Reference (The Boring but Important Bit) |
| 101 | + |
| 102 | +### 🔮 TelegramLoggerClient |
| 103 | + |
| 104 | +#### `__init__(base_url: str, x_id: str)` |
| 105 | + |
| 106 | +Create your logger. Feed it URLs and tokens. |
| 107 | + |
| 108 | +#### `send_log(...)` |
| 109 | + |
| 110 | +Send your log on a grand adventure. Pack its bags with: |
| 111 | + |
| 112 | +- `caller`: Who's making all this noise? |
| 113 | +- `level`: How important is this, really? |
| 114 | +- `message`: What's the scoop? |
| 115 | +- `error`: What went boom? |
| 116 | +- `request_id`: A unique ID for this particular escapade |
| 117 | +- `trace_id`: For retracing your steps |
| 118 | +- `span_id`: A slice of time in the grand timeline |
| 119 | +- `data`: Any extra bits and bobs |
| 120 | + |
| 121 | +Returns a `requests.Response` object (a postcard from your log's journey). |
| 122 | + |
| 123 | +## 🗝️ Environment Variables (Your Logger's Secret Code) |
| 124 | + |
| 125 | +- `TELEGRAM_LOGGER_BASE_URL`: Where your logs call home |
| 126 | +- `TELEGRAM_LOGGER_X_ID`: Your logger's super-secret identity |
| 127 | + |
| 128 | +## 🎲 Command Line Arguments (For When You're Feeling Bossy) |
| 129 | + |
| 130 | +- `--debug`: Unleash the full power of logging (optional) |
| 131 | +- `--base-url`: A new home for your logs |
| 132 | +- `--x-id`: A new secret identity |
| 133 | +- `--caller`: Who's calling? |
| 134 | +- `--level`: On a scale of "meh" to "THE WORLD IS ENDING!" |
| 135 | +- `--message`: Your log's 15 minutes of fame |
| 136 | +- `--error`: What's gone sideways? |
| 137 | +- `--request-id`: This log's personal serial number |
| 138 | +- `--trace-id`: Breadcrumbs in the digital forest |
| 139 | +- `--span-id`: A moment in time |
| 140 | +- `--data`: Everything else but the kitchen sink |
| 141 | + |
| 142 | +Remember: Command line arguments are the divas of the coding world - they always steal the show from environment variables. |
| 143 | + |
| 144 | +## 📜 License (The Fine Print) |
| 145 | + |
| 146 | +This project is unleashed under the WTFPL License – Do What The F\*\*k You Want To Public License. Your imagination is the only limit, push it to the boundaries! |
| 147 | + |
| 148 | +Now go forth and log like there's no tomorrow! May your errors be few and your insights be plentiful. Happy logging! 📝🚀 |
0 commit comments