- How do I install gulaandrij/telegram-monolog in Laravel?
- Install it with Composer using composer require gulaandrij/telegram-monolog. Then add a Telegram logging channel to config/logging.php or attach the handler to an existing stack, and provide your bot token and chat ID. In Laravel, keep those values in .env so they are not committed to source control.
- What configuration does the Telegram Monolog handler need?
- At minimum the handler needs a Telegram bot token and the target chat ID. The package also supports message formatting options, so you can adjust how log records appear in the chat. Store credentials in environment variables and reference them from your logging configuration.
- Does this package work with Laravel 10 and Laravel 11?
- Because it is a Monolog handler, it works with Laravel versions that use Monolog for logging, which covers most modern Laravel releases. Check the package's Composer requirements before installing on older or brand-new Laravel versions. If your app already writes logs through Monolog channels, the handler can be attached without changing application code.
- How do I send only errors and exceptions to Telegram?
- Create a dedicated logging channel for Telegram and set its level to error or critical, then add that channel to your stack. This keeps routine debug and info messages out of the chat while still sending exceptions and failures. You can also log custom messages to that channel when you need an alert.
- Can I use telegram-monolog outside Laravel in plain PHP?
- Yes. The handler is Monolog-compatible, so in plain PHP you can create a Monolog logger, push the Telegram handler onto it, and log normally. You still need a bot token and chat ID, and you must load the package through Composer.
- How do I create a Telegram bot and get the chat ID for logging?
- Create a bot by chatting with BotFather in Telegram and copy the token it gives you. Add the bot to the target chat or group, then retrieve the chat ID from the Bot API updates endpoint or a helper bot. Use that token and chat ID in your logging configuration.
- Is it safe to put the Telegram bot token and chat ID in .env?
- Yes, bot tokens and chat IDs should be stored in .env or another secrets manager, never hard-coded or committed. Restrict who can access the bot and rotate the token immediately if it is exposed. The chat ID is less sensitive, but it still identifies where alerts are delivered.
- How can I test Telegram logging without spamming a real chat?
- Use a dedicated test bot and a private test chat rather than your production alert channel. Send a single warning or error log entry and confirm it arrives with the expected formatting. For automated tests, use Monolog's TestHandler or a mocked Telegram client so your test suite does not call the real Bot API.
- What are alternatives to sending Laravel logs to Telegram?
- Alternatives include other Monolog Telegram handlers, Laravel notification packages with a Telegram channel, or a custom handler that calls the Bot API yourself. You could also send alerts to Slack or email if your team already monitors those channels. Choose based on whether you need simple log forwarding or richer notification routing.
- Does telegram-monolog require a queue or external service?
- No. The handler sends records directly through the Telegram Bot API, so you do not need an external logging service or a queue worker. For very high log volume, consider rate limits and use a queue or filtering to avoid flooding the chat.