21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 230 Views |
-
Neat way of adding functionality to debug::log

31 August 2012 at 8:25am Last edited: 31 August 2012 8:35am
Hi,
Out of the box Debug::log writes the date and a specified message to [root]/debug.log. I would like to add the name of the logged-in user and the filename and line number at which the log function was called.
I know how to do this by editing the function. However I want to achieve this by adding code to [my module]/code rather than changing code in sapphire.
Is there a neat way of doing this? Currently I have no idea.
Thanks.
-
Re: Neat way of adding functionality to debug::log

1 September 2012 at 10:38pm Last edited: 1 September 2012 10:54pm
In an attempt to extent debug::log without altering the Version 2.4 framework, I added the following line to mysite/_config.php
Object::add_extension("Debug", "CustomDebug");
created and added the following to mysite\code\CustomDebug.php
<?php
class CustomDebug extends Debug{
// My stuff will go in here
}Then in order to make sure that the object gets built before the object is run I commented out the above line in mysite/_config.php,
ran dev/build,
removed the comment, and finally
re-ran dev/build.However when I re-ran dev/build I got the following message
Fatal error: Object::add_extension() - Extension "CustomDebug" is not a subclass of Extension in [my root]\sapphire\core\Object.php on line 530
I have now spent some time trying to figure out where I screwed up so if anyone can spot anything that would be great. Maybe my line in _config.php is wrong.
-
Re: Neat way of adding functionality to debug::log

1 September 2012 at 11:41pm
OK I have now resorted to directly editing the framework.
Not good and I hate doing this but I was unable to find anything else which worked.
-
Re: Neat way of adding functionality to debug::log

1 September 2012 at 11:50pm
If you want better support than what Debug::log() offers, you should be using SS_Log::log(). Your code doesn't work because Object::add_extension() is used to add extensions to objects, not to replace them. Object::useCustomClass() can be used to replace some classes in some places, but not debug as it is always called statically.
-
Re: Neat way of adding functionality to debug::log

2 September 2012 at 12:10am
Hi Simon,
Thanks for putting me straight about the problem with replacing static classes. I also see that SS_Log::log() takes an extras argument which looks promising. However I am being forced to use Version 2.4 by my client whose hosting service uses PHP 5.2 and I see that this extras argument does not appear to be used by SS_Log::log() in Version 2.4.
I am currently doing some hoovering because I have a guest arriving. However I plan to look at this again a little later today to check that I have not overlooked something here.
| 230 Views | ||
|
Page:
1
|
Go to Top |

