Created
July 1, 2019 05:03
-
-
Save janzikmund/c3b9fe28230cc9742993d146fe767ac2 to your computer and use it in GitHub Desktop.
Simple WordPress logging function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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