Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift logging #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions library/Swift/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,25 @@ class Swift_Server {
private $_config;
private $_version;
private $_current_modules;

private $_logger = false;
private $_log_debug = false;

/**
* @param Array $_config The swift configuration array (see documentation for details)
*/
public function __construct($_config){
$this->_config = $_config;

if(!empty($_config['logger']) &&
is_object($_config['logger']) &&
method_exists($_config['logger'], 'log')){

$this->_logger = $_config['logger'];
$this->_log_debug = $_config['debug_log_enabled'];

}

}

public function setCode($code){
Expand Down Expand Up @@ -49,14 +65,17 @@ public function serve(){
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;


if (isset($this->_config['debug_minify_logger'])) {
if (isset($this->_config['debug_minify_logger'])) { //@TODO: Deprecate?
require_once 'Minify/Logger.php';
if (true === $this->_config['debug_minify_logger']) {
require_once 'FirePHP.php';
Minify_Logger::setLogger(FirePHP::getInstance(true));
} else {
Minify_Logger::setLogger($this->_config['debug_minify_logger']);
}
} elseif($this->_logger){ //Fall back to generic logger as alternative
require_once 'Minify/Logger.php';
Minify_Logger::setLogger($this->_logger);
}


Expand All @@ -71,10 +90,19 @@ public function serve(){
$min_serveOptions['swift']['files'] = array();

foreach($this->_current_modules AS $module){

if(!empty($this->_config['debug_use_alt_resources']) && !empty($this->_config['modules'][$module]['debug_path'])){

$this->log('Using path "'.$this->_config['modules'][$module]['debug_path'].'" for module: "'.$module.'"');
$min_serveOptions['swift']['files'][] = $this->_config['modules'][$module]['debug_path'];

} else {

if(empty($this->_config['modules'][$module]['path'])) throw new Swift_ServerException("No path defined for module {$module}");

$this->log('Using path "'.$this->_config['modules'][$module]['path'].'" for module: "'.$module.'"');
$min_serveOptions['swift']['files'][] = $this->_config['modules'][$module]['path'];

}
}

Expand All @@ -96,8 +124,16 @@ public function serve(){

Minify::serve('Swift', $min_serveOptions);


}

/////////////////////////////////////////////////////////////////////////////

private function log($message){
if($this->_logger && $this->_log_debug){
$this->_logger->log('Swift: '.((string) $message));
}
}

}

require_once 'Minify/Controller/Base.php';
Expand Down Expand Up @@ -135,4 +171,7 @@ public function setupSources($options) {
}
return $options;
}
}
}


class Swift_ServerException extends Exception {}