Skip to content
This repository
Browse code

better error checking on log setup

  • Loading branch information...
commit 0d0483c371357db115db6ac519746ec13a614df7 1 parent d5d1648
Demian Turner authored May 13, 2010

Showing 1 changed file with 37 additions and 29 deletions. Show diff stats Hide diff stats

  1. 66  src/lib/SGL2/Bootstrap.php
66  src/lib/SGL2/Bootstrap.php
@@ -5,30 +5,30 @@ class SGL2_Bootstrap extends SGL2_Bootstrap_Abstract
5 5
 	public function __construct()
6 6
 	{
7 7
 		$config = new Zend_Config_Ini(PROJECT_PATH.'/var/config.ini', 'staging');
8  
-		$registry = SGL2_Registry::createInstance($config);	
9  
-		$this->registry = $registry;	
10  
-	}				
  8
+		$registry = SGL2_Registry::createInstance($config);
  9
+		$this->registry = $registry;
  10
+	}
11 11
 
12 12
 	public function initEnv()
13 13
 	{
14 14
 		define('SGL2_THEME_DIR', PROJECT_PATH.'/www/themes');
15  
-		define('SGL2_CACHE_DIR', PROJECT_PATH.'/var/cache');		
16  
-		define('SGL2_MOD_DIR', PROJECT_PATH.'/modules');	
17  
-		
18  
-		$config = $this->registry->getConfig();		
  15
+		define('SGL2_CACHE_DIR', PROJECT_PATH.'/var/cache');
  16
+		define('SGL2_MOD_DIR', PROJECT_PATH.'/modules');
  17
+
  18
+		$config = $this->registry->getConfig();
19 19
         date_default_timezone_set($config->app->timezone);
20  
-        error_reporting(E_ALL);			
  20
+        error_reporting(E_ALL);
21 21
 	}
22  
-	
  22
+
23 23
 	public function initRouter()
24 24
 	{
25 25
 		$this->registry->set('request', 	new SGL2_Request());
26 26
 		$this->registry->set('response', 	new SGL2_Response());
27 27
 		$config = $this->registry->getConfig();
28  
-		$this->registry->set('router', 		new SGL2_Router($config->routing->adapter, 
  28
+		$this->registry->set('router', 		new SGL2_Router($config->routing->adapter,
29 29
 			$config->routing->toArray()));
30  
-	}	
31  
-	
  30
+	}
  31
+
32 32
 	public function initLogger()
33 33
 	{
34 34
 		$config = $this->registry->getConfig();
@@ -36,43 +36,51 @@ public function initLogger()
36 36
 		$logDir = dirname($logfile);
37 37
         if (!is_dir($logDir)) {
38 38
             $ok = System::mkDir(array('-p', $logDir));
39  
-            @chmod($logDir, 0777);
40  
-        }	
  39
+            if (!$ok) {
  40
+                throw new Exception(sprintf('Could not create log folder at'.
  41
+                    ' %s, make var dir writable by the webserver', $logDir));
  42
+            } else {
  43
+                chmod($logDir, 0777);
  44
+            }
  45
+        }
41 46
         if (!is_file($logfile)) {
42 47
             $ok = touch($logfile);
43  
-        }	
  48
+            if (!$ok) {
  49
+                throw new Exception(sprintf('Could not create log file at %s', $logfile));
  50
+            }
  51
+        }
44 52
 		if (!is_readable($logfile)) {
45 53
 			throw new Exception(sprintf('Log file not readable at %s', $logfile));
46 54
 		}
47 55
 		$writer = new Zend_Log_Writer_Stream($logfile);
48  
-		$logger = new Zend_Log($writer);		
  56
+		$logger = new Zend_Log($writer);
49 57
 		$this->registry->set('logger', 	$logger);
50 58
 		$this->registry->getEventDispatcher()->addGlobalListener(new SGL2_Plugin_LogMessage());
51 59
 	}
52  
-	
  60
+
53 61
 	public function initView()
54 62
 	{
55  
-		
56  
-	}	
57  
-		
  63
+
  64
+	}
  65
+
58 66
 	public function initDb()
59 67
 	{
60  
-		
61  
-	}	
62  
-	
  68
+
  69
+	}
  70
+
63 71
 	public function initConfig()
64 72
 	{
65  
-		
  73
+
66 74
 	}
67  
-	
  75
+
68 76
 	public function initCache()
69 77
 	{
70  
-		
  78
+
71 79
 	}
72  
-	
  80
+
73 81
 	public function initLocale()
74 82
 	{
75  
-		
76  
-	}	
  83
+
  84
+	}
77 85
 }
78 86
 ?>

0 notes on commit 0d0483c

Please sign in to comment.
Something went wrong with that request. Please try again.