MY_Log |
[eluser]Chris Newton[/eluser]
I prefer to have more flexibility in the error levels I choose to log than ERROR, DEBUG, and INFO. Additionally, sometimes I don't want to see 1 INFO message amid hundreds of DEBUG messages. To solve this for myself, I created the MY_Log library. It's very simple to set up and use. What my library does is this: Look for a new config item containing an array of Log levels, which could contain, some, all, or none, of the default log levels, as well as allow you to create your own log levels. For instance: Code: $config['show_in_log']= array('ERROR','CUSTOM_LOG_MSG','MY_MESSAGE'); Also, if you add this library and set the array to empty Code: $config['show_in_log']=array(); ***************************** To use this yourself, add this library to your library folder (this assumes 'MY_' is your controller override prefix) and add the config item found way down at the bottom to your primary config file. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); And add this to your config: Code: /*
[eluser]farrelley[/eluser]
I just modified the Logging Lib. you can see it here http://www.kapustabrothers.com/2008/06/0...g-library/
[eluser]Chris Newton[/eluser]
It's not good form to hack the core libraries directly. That makes your code more difficult to port, and makes the CI install more difficult to update quickly. Overriding a core library with your own in the form of MY_Whatever_library will help you in the long run. Where possible you should extend the core libraries or write your own that can augment without interfering.
[eluser]SneakyDave[/eluser]
This class doesn't quite work for me, unless I'm calling the method incorrectly. I'm able to load this new library by autoloading it as 'MY_log', this is confirmed by some echo statements that the custom library has been loaded. But if I use this method to try to log something Code: log_message ('INFO','msg'); It appears the native method is called, and these other guesses didn't work either... Code: $this->MY_Log->log_message ('INFO','msg') // Message: Undefined property: ::$MY_Log Code: $this->log_message ('INFO','msg') // blank page Code: $this->Log->log_message ('INFO','msg') // Message: Undefined property: ::$Log Code: $this->log->log_message ('INFO','msg') // Message: Undefined property: ::$log So I don't know how the method is supposed to be called. I'm running CI 1.6.3
[eluser]SneakyDave[/eluser]
Sonofa... never mind, I got it working, I renamed MY_log.php to MY_Log.php and loaded the correct class, and it works now.
[eluser]sophistry[/eluser]
I just made a similar MY_Log.php file and I think it is less code to maintain should the CI Log.php library change substantially. The class proposed above is fine and it works, but it was too much STUFF to change and adding a config item was not to my taste. Here is an alternative that just uses the MY_Log.php class extension to override the $_levels var. To use it, you just create your own array items. In my case, I needed to log search items in a text file. Config file needs log_threshold set to 1: Code: $config['log_threshold'] = 1; So, my log_message() call looks like this: Code: log_message('SEARCH', $search_term); and the MY_log.php file... Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |