Skip to content

Commit

Permalink
Add log and error helpers for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jalendport committed Apr 20, 2021
1 parent 81d6ba6 commit 807d09d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/PreparseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use craft\elements\Asset;
use craft\events\ElementEvent;
use craft\events\MoveElementEvent;
use craft\helpers\FileHelper;
use craft\services\Elements;
use craft\services\Fields;
use craft\events\RegisterComponentTypesEvent;
Expand Down Expand Up @@ -174,6 +175,35 @@ function (MoveElementEvent $event) {
);
}

/**
* @param $msg
* @param string $level
* @param string $file
*/
public static function log($msg, $level = 'notice', $file = 'Preparse')
{
try
{
$file = Craft::getAlias('@storage/logs/' . $file . '.log');
$log = "\n" . date('Y-m-d H:i:s') . " [{$level}]" . "\n" . print_r($msg, true);
FileHelper::writeToFile($file, $log, ['append' => true]);
}
catch(\Exception $e)
{
Craft::error($e->getMessage());
}
}

/**
* @param $msg
* @param string $level
* @param string $file
*/
public static function error($msg, $level = 'error', $file = 'RecurringOrders')
{
static::log($msg, $level, $file);
}

/**
* Fix file uploads being processed twice by craft, which causes an error.
*
Expand Down

0 comments on commit 807d09d

Please sign in to comment.