Skip to content

Commit

Permalink
Replace own Logger by CakeLog
Browse files Browse the repository at this point in the history
  • Loading branch information
xemle committed May 27, 2013
1 parent ea0f4c3 commit 36b72de
Show file tree
Hide file tree
Showing 68 changed files with 764 additions and 1,118 deletions.
6 changes: 3 additions & 3 deletions Config/Migration/002_fix_unzip_path.php
Expand Up @@ -31,17 +31,17 @@ public function before($direction) {
App::import('Model', 'MyFile');
$MyFile = new MyFile();
$files = $MyFile->find('all', array('conditions' => array('path LIKE' => '%/./')));
Logger::debug("Found " . count($files) . " to migrate");
CakeLog::debug("Found " . count($files) . " to migrate");
$errors = 0;
foreach ($files as $file) {
$file['File']['path'] = substr($file['File']['path'], 0, strlen($file['File']['path']) - 2);
if (!$MyFile->save($file, true, array('path'))) {
Logger::error("Could not save file {$file['id']}");
CakeLog::error("Could not save file {$file['id']}");
$errors++;
}
}
if (count($files)) {
Logger::info("Fix upload path of " . count($files) . " files ($errors errors)");
CakeLog::info("Fix upload path of " . count($files) . " files ($errors errors)");
}
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions Config/Migration/004_multiple_access_groups.php
Expand Up @@ -69,17 +69,17 @@ public function after($direction) {
'recursive' => -1));
$groupCount = count($groups);
if (!$groupCount) {
Logger::info("No groups to migrate");
CakeLog::info("No groups to migrate");
return true;
}

Logger::info("Found $groupCount groups to migrate");
CakeLog::info("Found $groupCount groups to migrate");
$migrated = 0;
foreach ($groups as $group) {
$migrated += $this->migrateGroup($group);
}
if ($migrated) {
Logger::info("Migration of $migrated media from $groupCount groups was successful");
CakeLog::info("Migration of $migrated media from $groupCount groups was successful");
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Config/Migration/006_one_meta_data_table.php
Expand Up @@ -104,7 +104,7 @@ private function migrateModel($name) {
$all = $db->fetchAll(sprintf($query, $limit, ($page - 1) * $limit), array());
}
$names = Inflector::pluralize($name);
Logger::info("Migrated $modelCount $names to fields with $mediaCount media");
CakeLog::info("Migrated $modelCount $names to fields with $mediaCount media");
}

/**
Expand Down
5 changes: 5 additions & 0 deletions Config/bootstrap.php
Expand Up @@ -109,6 +109,11 @@
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
CakeLog::config('full', array(
'engine' => 'FileLog',
'types' => array('debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'logger',
));

/**
* User storage directory
Expand Down
7 changes: 0 additions & 7 deletions Config/core.php
Expand Up @@ -183,13 +183,6 @@
*/
define('LOG_ERROR', LOG_ERR);

/**
* Configuration of phTagr's logger
*/
Configure::write('Logger.enable', true);
Configure::write('Logger.level', 1);
Configure::write('Logger.file', TMP.'logs'.DS.'logger.log');

/**
* Session configuration.
*
Expand Down
3 changes: 0 additions & 3 deletions Console/Command/AppShell.php
Expand Up @@ -16,9 +16,6 @@
*/

App::import('File', 'ShellControllerMock', array('file' => dirname(__FILE__) . DS . 'ShellControllerMock.php'));
if (!class_exists('Logger')) {
App::import('File', 'Logger', array('file' => APP . 'logger.php'));
}

class AppShell extends Shell {
var $uses = array();
Expand Down
10 changes: 5 additions & 5 deletions Console/Command/NotifyShell.php
Expand Up @@ -60,7 +60,7 @@ function _buildImages($media) {
foreach ($media as $m) {
$file = $this->PreviewManager->getPreview($m, 'mini');
if (!$file) {
Logger::err("Could not create preview for media {$m['Media']['id']}");
CakeLog::error("Could not create preview for media {$m['Media']['id']}");
continue;
}
$filename = 'media-' . $m['Media']['id'] . '.jpg';
Expand All @@ -78,12 +78,12 @@ function _sendNotifaction($user, $media) {
->emailFormat("both");
if (!$this->Email->send()) {
$this->out("Could not send new media notification email to {$user['User']['email']}");
Logger::err("Could not send new media notification email to {$user['User']['email']}");
CakeLog::error("Could not send new media notification email to {$user['User']['email']}");
} else {
if ($this->verbose) {
$this->out("Send new media notification email to {$user['User']['email']}");
}
Logger::info("Send new media notification email to {$user['User']['email']}");
CakeLog::info("Send new media notification email to {$user['User']['email']}");
}
}

Expand Down Expand Up @@ -132,8 +132,8 @@ function run() {
$user['User']['last_notify'] = date('Y-m-d h:m:s', $now);
if (!$this->User->save($user['User'], true, array('last_notify'))) {
$this->out("Could not save user data of {$user['User']['username']}");
Logger::err("Could not save user data of {$user['User']['username']}");
Logger::debug($user);
CakeLog::error("Could not save user data of {$user['User']['username']}");
CakeLog::debug($user);
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions Console/Command/UpgradeMediaSchemaShell.php
Expand Up @@ -39,7 +39,7 @@ function main() {
}

function _execute($sql) {
Logger::debug($sql);
CakeLog::debug($sql);
$this->UpgradeSchema->db->execute($sql);
}

Expand Down Expand Up @@ -114,9 +114,9 @@ function _addVideoThumb($media, $file) {
$thumb['File']['media_id'] = $media['Media']['id'];
$thumb['File']['readed'] = date("Y-m-d H:i:s", filemtime($filename));
if (!$this->MyFile->save($thumb)) {
Logger::warn("Could not add thumbnail to database");
CakeLog::warning("Could not add thumbnail to database");
} else {
Logger::verbose("Add thumb file of media {$media['Media']['id']}");
CakeLog::debug("Add thumb file of media {$media['Media']['id']}");
}
}

Expand All @@ -127,9 +127,9 @@ function _migrateMedia($media) {
// create file model
$filename = $media['Media']['path'].$media['Media']['file'];
if (!file_exists($filename)) {
Logger::err("Cannot find media {$media['Media']['id']}: $filename");
CakeLog::error("Cannot find media {$media['Media']['id']}: $filename");
if ($this->deletePolicy == "a") {
Logger::warn("Delete not existing media file {$media['Media']['id']}: $filename");
CakeLog::warning("Delete not existing media file {$media['Media']['id']}: $filename");
$this->out("Auto delete not existing media file {$media['Media']['id']}: $filename");
$this->Media->delete($media['Media']['id']);
return false;
Expand All @@ -139,14 +139,14 @@ function _migrateMedia($media) {
$a = $this->in("Could not find media {$media['Media']['id']}: $filename!\n[d]elete, [s]kip, [r]etry, delete [a]ll, [c]ancel", array("d", "s", "r", "a", "c"), "d");
}
if ($a == "d" || $a == "a") {
Logger::warn("Delete media {$media['Media']['id']}: $filename");
CakeLog::warning("Delete media {$media['Media']['id']}: $filename");
$this->Media->delete($media['Media']['id']);
if ($a == "a") {
$this->deletePolicy = "a";
}
return true;
} elseif ($a == "s") {
Logger::warn("Skip media {$media['Media']['id']}: $filename");
CakeLog::warning("Skip media {$media['Media']['id']}: $filename");
return true;
} elseif ($a == "r") {
clearstatcache();
Expand All @@ -160,8 +160,8 @@ function _migrateMedia($media) {
$file['File']['media_id'] = $media['Media']['id'];
$file['File']['readed'] = date("Y-m-d H:i:s", filemtime($filename));
if (!$this->MyFile->save($file)) {
Logger::debug("Cannot migrate data from media {$media['Media']['id']}");
Logger::warn($file);
CakeLog::debug("Cannot migrate data from media {$media['Media']['id']}");
CakeLog::warning($file);
return false;
}

Expand All @@ -186,14 +186,14 @@ function _migrateMedia($media) {
$this->_addVideoThumb($media, $file);
break;
default:
Logger::warn("Unhandled file type $type");
CakeLog::warning("Unhandled file type $type");
}
// Delete old flag IMAGE_FLAG_ACTIVE
$this->Media->deleteFlag($media, 1);
} else {
// Inactive media will be deleted, data is stored in files
$this->Media->delete($media['Media']['id']);
Logger::debug("Deleted inactive media {$media['Media']['id']}");
CakeLog::debug("Deleted inactive media {$media['Media']['id']}");
}
return true;
}
Expand All @@ -209,7 +209,7 @@ function _migrateData() {
$this->Media->unbindAll();
$media = $this->Media->find('all', array('fields' => array('Media.id', 'Media.path', 'Media.file', 'Media.user_id', 'Media.flag')));
$this->out("Migrate ".count($media)." media...");
Logger::verbose("Found ".count($media)." media to migrade ...");
CakeLog::debug("Found ".count($media)." media to migrade ...");

$errors = 0;
foreach ($media as $m) {
Expand All @@ -219,10 +219,10 @@ function _migrateData() {
}
if ($errors) {
$this->out("Upgrade ".count($media)." media with $errors errors");
Logger::err("Upgrade ".count($media)." media with $errors errors");
CakeLog::error("Upgrade ".count($media)." media with $errors errors");
return true;
} else {
Logger::info("Upgrade ".count($media)." media successfully");
CakeLog::info("Upgrade ".count($media)." media successfully");
return false;
}
}
Expand Down
9 changes: 4 additions & 5 deletions Controller/AppController.php
Expand Up @@ -15,7 +15,6 @@
* @license GPL-2.0 (http://www.opensource.org/licenses/GPL-2.0)
*/

App::uses('Logger', 'Lib');
App::uses('Controller', 'Controller');

class AppController extends Controller
Expand Down Expand Up @@ -154,17 +153,17 @@ public function _checkSession() {
// Fetch User
$user = $this->User->findById($id);
if (!$user) {
Logger::err("Could not find user with given id '$id' (via $authType)");
CakeLog::error("Could not find user with given id '$id' (via $authType)");
return false;
}

if ($this->User->isExpired($user)) {
Logger::warn("User account of '{$user['User']['username']}' (id {$user['User']['id']}) is expired!");
CakeLog::warning("User account of '{$user['User']['username']}' (id {$user['User']['id']}) is expired!");
return false;
}

$this->User->writeSession($user, $this->Session);
Logger::info("User '{$user['User']['username']}' (id {$user['User']['id']}) authenticated via $authType!");
CakeLog::info("User '{$user['User']['username']}' (id {$user['User']['id']}) authenticated via $authType!");

return true;
}
Expand Down Expand Up @@ -275,7 +274,7 @@ public function loadComponent($componentName, &$parent = null) {
}
$component = $this->Components->load($componentName);
if (!$component) {
Logger::warn("Could not load component $componentName");
CakeLog::warning("Could not load component $componentName");
return false;
}
$parent->{$componentName} = $component;
Expand Down

0 comments on commit 36b72de

Please sign in to comment.