File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change 11<?php
2+
3+ namespace App \Helpers ;
4+
5+ use GuzzleHttp \Client ;
6+ use GuzzleHttp \Exception \GuzzleException ;
7+
8+ class Log
9+ {
10+ /**
11+ * @throws GuzzleException
12+ */
13+ public static function info ($ log ): void
14+ {
15+ self ::handle ("info " , $ log );
16+ }
17+
18+ /**
19+ * @throws GuzzleException
20+ */
21+ public static function debug ($ log ): void
22+ {
23+ self ::handle ("debug " , $ log );
24+ }
25+
26+ /**
27+ * @throws GuzzleException
28+ */
29+ public static function error ($ log ): void
30+ {
31+ self ::handle ("error " , $ log );
32+ }
33+
34+ /**
35+ * @throws GuzzleException
36+ */
37+ private static function send ($ message ): void
38+ {
39+ $ token = config ("telegram.token " );
40+ $ channelUsername = config ("telegram.id " );
41+
42+ $ client = new Client ();
43+ $ url = "https://api.telegram.org/bot {$ token }/sendMessage " ;
44+
45+ $ client ->post ($ url , [
46+ 'form_params ' => [
47+ 'chat_id ' => $ channelUsername ,
48+ 'text ' => $ message ,
49+ ],
50+ ]);
51+ }
52+
53+ /**
54+ * @throws GuzzleException
55+ */
56+ private static function handle ($ type , $ log ): void
57+ {
58+ $ template = "" ;
59+
60+ $ date = date ("Y-m-d H:i:s " );
61+ $ tp = strtoupper ($ type );
62+
63+ $ template .= "[ $ date - $ tp] ===> 🧨🧨 \n" ;
64+
65+ $ template .= $ log ;
66+
67+ self ::send ($ template );
68+ }
69+ }
You can’t perform that action at this time.
0 commit comments