Skip to content

Instantly share code, notes, and snippets.

@cballenar
Created January 26, 2023 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cballenar/fc48a6da7a2239c20c5dab2ad76ac444 to your computer and use it in GitHub Desktop.
Save cballenar/fc48a6da7a2239c20c5dab2ad76ac444 to your computer and use it in GitHub Desktop.
<?php
namespace yournamespace\yourplugin;
use Craft;
class MyClass
{
/**
* Basic Logging implementation
*/
protected function log($message): void
{
$logFile = Craft::getAlias('@storage/logs/logname.log');
$log = date('Y-m-d H:i:s').' '.serialize($message)."\n";
\craft\helpers\FileHelper::writeToFile($logFile, $log, ['append' => true]);
}
// usage
self::log([$varToLog]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment