Skip to content

Commit

Permalink
Remove bot token from debug stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklul committed May 4, 2020
1 parent 6220183 commit 8d02217
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/TelegramLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class TelegramLog
*/
protected static $debug_log_temp_stream_handle;

/**
* Remove bot token from debug stream
*
* @var bool
*/
public static $remove_bot_token = true;

/**
* Initialise logging.
*
Expand Down Expand Up @@ -85,7 +92,13 @@ public static function endDebugLogTempStream($message = '%s')
{
if (is_resource(self::$debug_log_temp_stream_handle)) {
rewind(self::$debug_log_temp_stream_handle);
self::debug(sprintf($message, stream_get_contents(self::$debug_log_temp_stream_handle)));
$stream_contents = stream_get_contents(self::$debug_log_temp_stream_handle);

if (self::$remove_bot_token) {
$stream_contents = preg_replace('/(\d+)\:[\w\-]+/', 'BOT_TOKEN_REMOVED', $stream_contents);
}

self::debug(sprintf($message, $stream_contents));
fclose(self::$debug_log_temp_stream_handle);
self::$debug_log_temp_stream_handle = null;
}
Expand Down

0 comments on commit 8d02217

Please sign in to comment.