Skip to content

Conversation

@saMahmoudzadeh
Copy link
Contributor

@saMahmoudzadeh saMahmoudzadeh commented Jun 13, 2024

This PR, adds topics level to package. With this feature, we can use PHP attributes to categorize logs and exceptions into different topics as specified in the configuration.

Levels:

  • Emergency Exceptions or logs
  • Critical Exceptions or logs
  • Important Exceptions or logs
  • Information Exceptions or logs
  • Debug Exceptions or logs
  • LowPriority Exceptions or logs

Example:

//logging.php

'telegram' => [
    'driver' => 'monolog',
    'level' => 'debug',

    'handler' => TheCoder\MonologTelegram\TelegramBotHandler::class,
    'handler_with' => [
        'token' => env('LOG_TELEGRAM_BOT_TOKEN'),
        'chat_id' => env('LOG_TELEGRAM_CHAT_ID'),
        'topic_id' => env('LOG_TELEGRAM_TOPIC_ID'),
        'topics_level' => [
            EmergencyAttribute::class => env('LOG_TELEGRAM_EMERGENCY'),
            CriticalAttribute::class => env('LOG_TELEGRAM_CRITICAL'),
            ImportantAttribute::class => env('LOG_TELEGRAM_IMPORTANT'),
            LowPriorityAttribute::class => env('LOG_TELEGRAM_LOW_PRIORITY'),
            InformationAttribute::class => env('LOG_TELEGRAM_INFO'),
        ],
        'bot_api' => env('LOG_TELEGRAM_BOT_API', 'https://api.telegram.org/bot'),
        'proxy' => env('LOG_TELEGRAM_BOT_PROXY', null),
    ],

    'formatter' => TheCoder\MonologTelegram\TelegramFormatter::class,
    'formatter_with' => [
        'tags' => env('LOG_TELEGRAM_TAGS', null),
    ],
]

usage

class TestController extends Controller
{
    /**
     * @throws \Exception
     */
    #[ImportantAttribute]
    public function index(Request $request): void
    {
        (new TestService())->test();
    }
}

image

@mbpcoder mbpcoder merged commit 619276d into mbpcoder:master Jun 13, 2024
@saMahmoudzadeh saMahmoudzadeh deleted the feature/topic-levels branch June 13, 2024 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants