Sharedlog project is very 'developer-friendly'
One of the most important features in a good project is the ease of trouble-shooting.
We made this task extremely easy with comprehensive logging and exception handling.
There are actually 2 distinct logging objects available for developers: Server-side (php) and client-side (javascript)
1. server side logging. This includes the ability to log anything you can possibly want. All you have to do is add one line of code anywhere in the script, for example:
$this->objLogger->log(__METHOD__.' line: '.__LINE__.' the result of the function: '.$result);
This will add the class name, line number and your message to the log.
The objLogger also has the ability to email the developer the log entry that contains the word 'error' (not case-sensitive)
For example, if you change the previous log entry to this:
$this->objLogger->log(__METHOD__.' line: '.__LINE__.' Error. the result of the function: '.$result);
The log entry will still be added but additionally this line will be emailed to you (the developer)
Along with some other server information like the url of page on which this error was triggered, the HTTP referrer, the browser string (useragent), the IP address from where request came from.
For example, this is the copy of email with error that I received:
Error: method does not exist for this action: nntp-thread
-----------------------------------------------------
HTTP_HOST: www.sharedlog.com
SCRIPT_NAME: /index.php
REQUEST_METHOD: GET
REQUEST_URI: /index.php?a=nntp-thread&tid=396094
SCRIPT_FILENAME: /usr/local/apache/sites/imglog.com/htdocs-pre/trunk/index.php
-----------------------------------------------------
HTTP_USER_AGENT: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
HTTP_REFERER: undefined
-----------------------------------------------------
REMOTE_ADDR/IP: 66.249.71.41
-----------------------------------------------------
GEOIP_CITY: undefined
GEOIP_COUNTRY_CODE: US
GEOIP_COUNTRY_NAME:
GEOIP_REGION: undefined
Also any Exception generated by any of the PEAR classes or by our classes is automatically added to the same log with the 'Error' prefix, causing it to be emailed to developer.
This means that as a developer you will also be notified by email whenever an exception is thrown anywhere in the script. The complete back trace message will also be included in the exception email.
One more thing about our exception handling: the exception messages can also be internationalized! How many other projects have you seen that allow this?
Another thing: an exception is displayed in the site template, making it look like a regular error message on the site.
For regular users only a short message is shown, while the developer (based in IP address) will see the complete message with a full back trace info. This makes sense because in most cases regular user should not see a complicated php back trace where full path and other sensitive data may be contained.
2. Second type of logging is the logging inside your javascripts. This feature is also not very common to other projects. The Javascript log is displayed inside the special <div> that is only included when you are visiting the site from your IP address (you must set developer IP in SETTINGS)
With this JS log console you can debug your javascripts very easily.
No longer to you need to add alert('something happened'); when you want to see what's going in your script.
All you do is add $L('something happened');
The regular user will never see this JS log console, the script will not be halted by this call to $L(), unlike with alert() that halts the execution of the script until the 'OK' is clicked.
SQL query view
This is yet another nice feature for developers: all sql queries executed to create a page will be printed at the bottom on the page if you accessing the site from IP address defined as 'developer IP'
For example, you may see something like this:
SQL data:
Total queries in this page: 1
Query 1:
SELECT RS.*,
`RS`.`id` as res_id,
`UI`.`template_id` AS template_id,
`UI`.`userid` as nick,
`UI`.`blog_title`,
`UI`.`blog_description`,
`AL`.`title_album`,
`EQ`.*,
`RL`.*
FROM
ALBUM AL, dbmail_users UI, RESOURCE RS
LEFT JOIN ENCODING_QUEUE EQ ON RS.id = EQ.resource_id
LEFT JOIN RESOURCE_LOCATION RL ON RS.id =
RL.resource_id
WHERE
`RS`.`resource_type_id` = '16'
AND `RS`.`userinfo_id` = `UI`.`user_idnr`
AND `RS`.`deleted` = '0'
AND `EQ`.`status_web` LIKE '1%'
AND `RS`.`album_id` > '0'
AND `RS`.`album_id` = `AL`.`id`
AND `UI`.`user_idnr` = '1496'
AND `AL`.`public_album` = 'Y'
AND `AL`.`xxx` = 'N'
ORDER BY `RS`.`added_time` DESC
LIMIT 10
This can be very useful in trying to improve your code be making fewer requests from the database server.
If you have memcache installed, you will see that many pages have 0 (zero) sql queries. This just shows you how great it is to use memcache and that it's well worth it to have it installed.
Another reason why this project is so developer-friendly is because it is based on PEAR classes. Each pear class usually has a good documentation and good support email lists maintained by pear.
So if you have any questions on any of the pear classes we use you can always find documentation on http://pear.php.net
/>
We are currently trying to base ALL of our javascripts on YUI library.
YUI has a great documentation:
http://developer.yahoo.com/yui/
(one of the best documented JS libraries) and one of the best
Support discussion list: http://tech.groups.yahoo.com/group/ydn-javascript/
Special note: We will be migrating to YUI 3, from now on (as on middle of November 2008) we will use YUI 3 for all javascripts. (unless a specific feature is not yet available on YUI 3, like some widgets)
Lastly, because we host the code on SVN server, you can always get the older versions of files if you want to see what was changed. This is assuming you are familiar with how to use SVN and SVN clients.
We also have developer mailing list here:
http://dev.sharedlog.com/mailman/listinfo/developers
This list can also be access with a newsreader like a regular NNTP group, but you need to register on www.sharedlog.com and use username/password to authenticate on our nntp server.
Address of our nntp server is nntp.sharedlog.com
add this server to your newsreader and look for group dev.sharedlog.developers