0

I have two PHP scripts. The first script (e.g. local.php) executes the second one (e.g. remote.php) via SSH using the phpseclib. Both scripts are using Monolog to write logs to the console.

Now my problem: How can I filter the log entries from the script executed via SSH in the local.php script?

For example: I only want to see errors and warnings, but the remote script always sends all entries (as other handlers in the local.php script might require a higher log level). So the local.php script must parse the log output of the remote.php script and assign the entries to Monolog records.

Programie
  • 141
  • 6
  • Can you please add the related code where you use Monolog? This would clarify your case. – dlondero Jul 14 '16 at 11:14
  • I created a simple example (not the actual code in my Application as that is getting too complex): remote.php: http://pastebin.com/tAgkyibz local.php: http://pastebin.com/6ZVzH1Ut – Programie Jul 14 '16 at 16:03

2 Answers2

0

I guess you can use Processors, maybe TagProcessor, into the remote script in order to add something useful to identify logs in local and use them accordingly.

dlondero
  • 2,539
  • 1
  • 24
  • 33
0

I might got the solution: Monolog also allows to format the output as JSON using the JsonFormatter. So I could simply format all the logger output in the remote.php script using the JsonFormatter and parse it line-by-line in my local.php script (excluding any line which is not JSON by simply checking the json_decode() output).

Programie
  • 141
  • 6