Skip to content
Snippets Groups Projects
Commit 2a9bc986 authored by Dyszczo's avatar Dyszczo
Browse files

Merge branch 'bugfix/tests' into 'master'

tests fix + custom file

See merge request !10
parents 3989dae4 f82d7f5d
No related branches found
No related tags found
1 merge request!10tests fix + custom file
Pipeline #6536 failed
## [1.5.1] - 2019-04-23
### Changed
- Two files for custom loggers (default+custom)
### Fixed
- Tests
## [1.5.0] - 2019-04-18
### Changed
- Log file is unified with old way logger and all is logged in /wp-content/uploads/wpdesk-logs/wpdesk_debug.log
......
......@@ -6,6 +6,8 @@ class WPCapture {
/** @var string */
private $filename;
const LOG_DIR = 'wpdesk-logs';
public function __construct($filename) {
$this->filename = $filename;
}
......@@ -115,7 +117,7 @@ class WPCapture {
* @return string
*/
private function get_log_dir() {
return trailingslashit( $this->get_uploads_dir() ) . 'wpdesk-logs';
return trailingslashit( $this->get_uploads_dir() ) . self::LOG_DIR;
}
/**
......
......@@ -84,30 +84,44 @@ class WPDeskLoggerFactory extends BasicLoggerFactory
return Registry::getInstance($name);
}
$logger = $this->createLogger($name);
$wpCapture = $this->captureWPLog($name);
$this->captureWooCommerce($logger);
$this->appendMainLog($logger);
if ($name !== self::DEFAULT_LOGGER_CHANNEL_NAME) {
$this->appendFileLog($logger, $this->getFileName($name));
}
return $logger;
}
/**
* @param $logger
*/
private function appendMainLog($logger) {
$wpCapture = $this->captureWPLog();
$this->appendFileLog($logger, $wpCapture->get_log_file());
}
/**
* @param Logger $logger
*/
private function appendFileLog($logger, $filename) {
try {
$this->pushFileHandle($wpCapture->get_log_file(), $logger);
$this->pushFileHandle($filename, $logger);
} catch (InvalidArgumentException $e) {
$logger->emergency('File log could not be created - invalid filename.');
$logger->emergency('Main log file could not be created - invalid filename.');
} catch (Exception $e) {
$logger->emergency('File log could not be written.');
$logger->emergency('Main log file could not be written.');
}
return $logger;
}
/**
* @param $name
*
* @return WPCapture
*/
private function captureWPLog($name) {
private function captureWPLog() {
static $wpCapture;
if (!$wpCapture) {
$wpCapture = new WPCapture($this->getFileName($name));
$wpCapture = new WPCapture(basename($this->getFileName()));
$wpCapture->init_debug_log_file();
}
......@@ -162,7 +176,8 @@ class WPDeskLoggerFactory extends BasicLoggerFactory
*/
public function getFileName($name = self::DEFAULT_LOGGER_CHANNEL_NAME)
{
return $name . '_debug.log';
$upload_dir = wp_upload_dir();
return trailingslashit( untrailingslashit( $upload_dir['basedir'] ) ) . WPCapture::LOG_DIR . DIRECTORY_SEPARATOR . $name . '_debug.log';
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment