Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save janzikmund/c3b9fe28230cc9742993d146fe767ac2 to your computer and use it in GitHub Desktop.
Save janzikmund/c3b9fe28230cc9742993d146fe767ac2 to your computer and use it in GitHub Desktop.
Simple WordPress logging function
/**
* Logs output into wp-content/logs/asana-api-debug.log
*/
protected function log($message)
{
$line = '[' . date('Y-m-d H:i:s') . '] ' . $message . "\n";
file_put_contents($this->logFile, $line, FILE_APPEND);
}
/**
* Make sure log dir exists and is writable
*/
protected function prepareLogFile()
{
$logDir = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR;
if(!file_exists($logDir)) {
mkdir($logDir);
}
$logFile = $logDir . DIRECTORY_SEPARATOR . 'asana-api-debug.log';
if(!file_exists($logFile)) {
touch($logFile);
}
$this->logFile = $logFile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment