diff options
| author | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
|---|---|---|
| committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
| commit | 3060a6f662da66008d57a461bf1c9b5b4aa2b002 (patch) | |
| tree | 442fd290505817efc0324f2af6e01805cb7396aa /system/libraries/Kohana_Log.php | |
| parent | 1cd6a615bb47a33794e4a4f690c87a348ab752d7 (diff) | |
| parent | 32d25dafd5b033338b6a9bb8c7c53edab462543a (diff) | |
Merge branch 'master' into talmdal_dev
Conflicts:
modules/gallery/controllers/albums.php
modules/gallery/controllers/movies.php
modules/gallery/controllers/photos.php
Diffstat (limited to 'system/libraries/Kohana_Log.php')
| -rw-r--r-- | system/libraries/Kohana_Log.php | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/system/libraries/Kohana_Log.php b/system/libraries/Kohana_Log.php new file mode 100644 index 00000000..44ef8af8 --- /dev/null +++ b/system/libraries/Kohana_Log.php @@ -0,0 +1,90 @@ +<?php defined('SYSPATH') OR die('No direct access allowed.'); +/** + * Logging class. + * + * $Id: Kohana_Log.php 4679 2009-11-10 01:45:52Z isaiah $ + * + * @package Core + * @author Kohana Team + * @copyright (c) 2007-2009 Kohana Team + * @license http://kohanaphp.com/license + */ +class Kohana_Log_Core { + + // Configuration + protected static $config; + + // Drivers + protected static $drivers; + + // Logged messages + protected static $messages; + + /** + * Add a new message to the log. + * + * @param string type of message + * @param string message text + * @return void + */ + public static function add($type, $message) + { + // Make sure the drivers and config are loaded + if ( ! is_array(Kohana_Log::$config)) + { + Kohana_Log::$config = Kohana::config('log'); + } + + if ( ! is_array(Kohana_Log::$drivers)) + { + foreach ( (array) Kohana::config('log.drivers') as $driver_name) + { + // Set driver name + $driver = 'Log_'.ucfirst($driver_name).'_Driver'; + + // Load the driver + if ( ! Kohana::auto_load($driver)) + throw new Kohana_Exception('Log Driver Not Found: %driver%', array('%driver%' => $driver)); + + // Initialize the driver + $driver = new $driver(array_merge(Kohana::config('log'), Kohana::config('log_'.$driver_name))); + + // Validate the driver + if ( ! ($driver instanceof Log_Driver)) + throw new Kohana_Exception('%driver% does not implement the Log_Driver interface', array('%driver%' => $driver)); + + Kohana_Log::$drivers[] = $driver; + } + + // Always save logs on shutdown + Event::add('system.shutdown', array('Kohana_Log', 'save')); + } + + Kohana_Log::$messages[] = array('date' => time(), 'type' => $type, 'message' => $message); + } + + /** + * Save all currently logged messages. + * + * @return void + */ + public static function save() + { + if (empty(Kohana_Log::$messages)) + return; + + foreach (Kohana_Log::$drivers as $driver) + { + // We can't throw exceptions here or else we will get a + // Exception thrown without a stack frame error + try + { + $driver->save(Kohana_Log::$messages); + } + catch(Exception $e){} + } + + // Reset the messages + Kohana_Log::$messages = array(); + } +}
\ No newline at end of file |
