You are here

README.txt in File logger 7

Same filename and directory in other branches
  1. 6 README.txt
File Logger Module
------------------------
by Dwight Aspinwall, dwight.aspinwall@gmail.com


Description
-----------
This is a simple module that allows developers to configure a log file from within Drupal and
dumps variables to it from within a running Drupal app.  Its sole function is to support 
debugging, and avoids the awkwardness of dumping variables either to the console or to the 
watchdog table.  Instead, using the unix tail command, a developer can easily view debugging 
output.  This is particularly useful when dumping large data structures such as nodes, menus,
etc.


Installation 
------------
 * Copy the module's directory to your modules directory and activate the module.
 * In Site configuration > File logging (admin/settings/flog), specify the path
   to the log file(s) and the default log file name.
 * (Optionally) Configure the date string to be included with each logged variable.
 * Ensure that the user running the webserver has write permission on the file you specify.
   It may be simpler to create that file in advance using the unix command 'touch' as in
   'touch /var/log/drupal.log'.  Then, set the permissions on the log file so it is writeable
   by the web server user, e.g. 'chmod 777 /var/log/drupal.log'.
 * Enable file logging.  When disabled, no output is written.  You'll probably want to disable 
   file logging in a production environment. It's not necessary to disable the module itself.


Using File logging
------------------------
To dump a variable call the function flog_it() with any variable.  Here is an example:

<?php
...
function my_module_form_alter(&$form, $form_state, $form_id) {
  ...
  // What does the form data structure look like?
  flog_it($form);
  ...
}

You can also add a label to a flog_it() call, which makes it easier to find, especially when
dumping lots of stuff.  The label goes into the second argument:

<?php
...
flog_it($form, 'FORM ID: ' . $form_id);
...

You can optionally provide a filename to flog_it(), which overrides the default log file (but uses 
the configured directory):

<?php
...
flog_it($form, 'FORM ID: ' . $form_id, 'some_other_file_name.txt');
...

Finally, there is one other convenience function, when dumps the php stack at the time of
execution of the statement.  This function takes one optional argument, which is a label:

<?php
...
flog_stack('stack before first call to foo()');
...

On unix systems, the tail command can be used to see output from flog_it() and flog_stack() calls, e.g.:

tail -f /var/log/drupal.log



File

README.txt
View source
  1. File Logger Module
  2. ------------------------
  3. by Dwight Aspinwall, dwight.aspinwall@gmail.com
  4. Description
  5. -----------
  6. This is a simple module that allows developers to configure a log file from within Drupal and
  7. dumps variables to it from within a running Drupal app. Its sole function is to support
  8. debugging, and avoids the awkwardness of dumping variables either to the console or to the
  9. watchdog table. Instead, using the unix tail command, a developer can easily view debugging
  10. output. This is particularly useful when dumping large data structures such as nodes, menus,
  11. etc.
  12. Installation
  13. ------------
  14. * Copy the module's directory to your modules directory and activate the module.
  15. * In Site configuration > File logging (admin/settings/flog), specify the path
  16. to the log file(s) and the default log file name.
  17. * (Optionally) Configure the date string to be included with each logged variable.
  18. * Ensure that the user running the webserver has write permission on the file you specify.
  19. It may be simpler to create that file in advance using the unix command 'touch' as in
  20. 'touch /var/log/drupal.log'. Then, set the permissions on the log file so it is writeable
  21. by the web server user, e.g. 'chmod 777 /var/log/drupal.log'.
  22. * Enable file logging. When disabled, no output is written. You'll probably want to disable
  23. file logging in a production environment. It's not necessary to disable the module itself.
  24. Using File logging
  25. ------------------------
  26. To dump a variable call the function flog_it() with any variable. Here is an example:
  27. ...
  28. function my_module_form_alter(&$form, $form_state, $form_id) {
  29. ...
  30. // What does the form data structure look like?
  31. flog_it($form);
  32. ...
  33. }
  34. You can also add a label to a flog_it() call, which makes it easier to find, especially when
  35. dumping lots of stuff. The label goes into the second argument:
  36. ...
  37. flog_it($form, 'FORM ID: ' . $form_id);
  38. ...
  39. You can optionally provide a filename to flog_it(), which overrides the default log file (but uses
  40. the configured directory):
  41. ...
  42. flog_it($form, 'FORM ID: ' . $form_id, 'some_other_file_name.txt');
  43. ...
  44. Finally, there is one other convenience function, when dumps the php stack at the time of
  45. execution of the statement. This function takes one optional argument, which is a label:
  46. ...
  47. flog_stack('stack before first call to foo()');
  48. ...
  49. On unix systems, the tail command can be used to see output from flog_it() and flog_stack() calls, e.g.:
  50. tail -f /var/log/drupal.log