output.php
This commit is contained in:
parent
440daa69fb
commit
9c06f30873
37
php/output.php
Normal file
37
php/output.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Stupidly simple and universal file logger
|
||||||
|
*
|
||||||
|
* @see https://gist.github.com/anthonyaxenov/6eafac478528ac6d300d8f9b4460c286/edit
|
||||||
|
*/
|
||||||
|
function output(...$data)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
foreach ($data as $something) {
|
||||||
|
if ($something instanceof Illuminate\Support\Collection) {
|
||||||
|
$something = $something->toArray();
|
||||||
|
}
|
||||||
|
if (is_array($something)) {
|
||||||
|
$something = var_export($something, true);
|
||||||
|
}
|
||||||
|
if (empty($something)) {
|
||||||
|
$something = '';
|
||||||
|
}
|
||||||
|
if (is_object($something)) {
|
||||||
|
if (method_exists($something, 'toArray')) {
|
||||||
|
$something = $something->toArray();
|
||||||
|
} elseif (method_exists($something, 'jsonSerialize')) {
|
||||||
|
$something = $something->jsonSerialize();
|
||||||
|
} else {
|
||||||
|
$something = var_export($something, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result[] = $something;
|
||||||
|
}
|
||||||
|
file_put_contents(
|
||||||
|
'test_' . date('d.m.Y') . '.log',
|
||||||
|
'[' . date('H:i:s') . '] ' .
|
||||||
|
implode(' ', $result) . PHP_EOL,
|
||||||
|
FILE_APPEND
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user