I saw the already committed issue #570964: Log clear function
and I wonder if a feature like shown in attached image would fit into the scope of this module
it consist in a handful set of links to clear logs

PS: I'm just posting a screenshot and even though marking this issue with "needs review" since it would be nothing to upload the code but nothing would be more illustrative than a picture, please review it and let me know, since I would be glad to contribute it

Comments

nancydru’s picture

Yes, I was thinking about doing parts of that any way, although not as "pretty." "Clear all" is already handled by not filtering on anything. I would like to see settings for "recent" and "old." Another thing I was thinking of, but am not sure can be done without a hack is to filter on user.

Submit a patch, please.

arhak’s picture

then..
do you encourage me to go for it?
I wouldn't like to spend time cleaning code if it won't be even considered for possible commit

BTW, wouldn't be the same to filter on anything than clearing the log, when I have some tricky bug dumping errors into my logs I use to clear all logs to see what's new, and I'm talking about the same message, so it wouldn't be possible to filter.. unless having a date/time filter I guess
Nevertheless, on development I prefer to delete than filter logs, that's why I use those criterias
which, by the way, aren't fixed, since the callback would handle any integer argument passed (it could have a textfield for the minutes or logs amount but would require a submit button then, I thought links are handier)

what for the "recent" and "old"? kind of quick-links to filter?
I could add that feature..

let me know if there is any change to get this features into this module and I will provide patches

PS: do you prefer patches against dev? being so decoupled it wouldn't be necessary right?

nancydru’s picture

If it is an enhancement to the current feature, then yes, it should be a patch against the current -dev. Plus, the base util.module has an improvement to its settings page and menu to make adding new features easier. Otherwise, just package the code up with a .info file and a CSS and/or .install (if needed).

Yes, go for it.

As for "recent" and "old": some people might consider "recent" to be the last half hour or last 5 minutes and "recent" to be the last hour or two; that's why I suggest settings.

Links or buttons aren't a whole lot different, except for the amount of text you can put on them.

nancydru’s picture

Status: Needs review » Active
arhak’s picture

well, having filters for recent/old and a "clear" button makes the whole functionality of what I initially proposed
though, I made a module for recent/old

but... it needs a minor collaboration from dblog module
actually I made a home version which duplicated dblog functionality, but that wouldn't be necessary if dblog would have a hook for its filters

therefore, I provided a patch for Drupal 7.x-dev
do you think it would be on time?

would you give some feedback on #582622: provide hook for dblog_filters
see the screenshot and tell me if thats what you want

BTW recent/aged times are configurable, just an array with minutes amounts

arhak’s picture

Title: handful links for log clearance » recent/aged filters for log entries
Assigned: Unassigned » arhak
Status: Active » Needs review

the module dblog_time_filters
the screenshot dblog_time_filters.png

Features:
- optionally offers recent and/or aged filters
- times are configurable as shown in one of the screenshots
- optional integration with util module (otherwise makes its own settings page)

Important:
- I didn't like to duplicate dblog's behavior, thus a patch must be applied for this module to work
this patch is available for both D6 #582672: dblog support filters through a hook (6.x) and D7 #582622: provide hook for dblog_filters

Notes:
- the recent/aged filters appear before due to alphabetical order, changing the weight of the module would make them go bellow
- the "clear" button in the screenshot is from clear_log module bundled with util module
- I needed the "- None -" option for Firefox (not for Chrome), because couldn't unselect (Ctrl+click) the single select, I can with select having multiple="multiple" or multiple="false", but having no "multiple" attribute in FF2 doesn't allow me to unselect

nancydru’s picture

Thanks, I will look at this in detail after I get some other things done. Some initial comments: 1) I don't like duplicating functionality either, but it's not good practice for a contrib to require a patch to core; 2) there doesn't seem to be the user filtering, but it would probably be easy to add with your hook; 3) "-none-" is probably good any way, 4) I wonder if there is a way to add a resizing "grippie" to the lists like Hierarchical Select does.

arhak’s picture

1) I can mirror dblog's functions allowing hooks and use menu_alter to active mines instead. Would it be preferable?

2) no user filtering, but yes, it would be easy with the hooks

3) actually "-none-" is required, since non-multiple selects can't be unselected, same as drop down lists

PS: please, also review the D7 patch (it might get into code freeze)

arhak’s picture

StatusFileSize
new9.19 KB
new23.5 KB
new20.96 KB

the original intention of this post was to provide another module for the util package, but being more flexible and generalizing the use case, it doesn't makes sense to have util module as a dependency, since these modules stand by them self
nevertheless, I declared package=Util in case you like them

dblog_ext - provide hooks for dblog_filters
(the same what the patch does to dblog, thus mimics dblog)

dblog_clear - doesn't requires dblog_ext, but integrates really good with dblog_filters
(old log_clear in util package, making its name consistent with what it actually does)

dblog_filters - requires dblog_ext or the patch (available for D6 and D7)

dblog_time_filters - (pending date/time filter, but has recent/aged filter)
dblog_user_filter - (with autocompletion)
dblog_host_filter - (without autocompletion but support contains/starts/ends/exact matches)

three last modules relies on dblog_filters
and taking advantage of that they don't have to do much
as an example, I post bellow the WHOLE module

/**
 * Implementation of hook_log_filters_settings().
 */
function dblog_user_filter_log_filters_settings() {
  $settings['username'] = array(
    'title' => 'Username',
    'description'    => 'Filters by username with autocompletion.',
    //'page arguments' => array('dblog_user_filter_settings'),
    //'file'           => 'dblog_filters.user.admin.inc',
  );
  return $settings;
}

/**
 * Implementation of hook_log_filters() on behalf of dblog.
 */
function dblog_user_filter_log_filters() {
  if (!dblog_filters_is_enabled('username')) return array();
  
  $filters['username'] = array(
    'title' => t('Username'),
    'where' => "u.name = '%s'",
    'conjunction' => FALSE,
  );
  $filters['username']['widget'] = array(
    '#type' => 'textfield',
    '#autocomplete_path' => 'user/autocomplete',
    '#maxlength' => USERNAME_MAX_LENGTH,
    '#size' => 27, // fit the same with than <select>
  );

  return $filters;
}
arhak’s picture

Title: recent/aged filters for log entries » recent/aged/username/hostname filters for log entries
nancydru’s picture

Status: Needs review » Needs work

While requiring a core patch is not without precedent, I don' like having to do that, so please go ahead and reproduce dblog's function.

There were several flags by the Coder module.

Regards your @TODO about MySql's NOW() function: it won't work here because it creates a datetime format value rather than a Unix timestamp.

arhak’s picture

shoot! didn't I uploaded the dblog_ext module already?
I already implemented a module to provide the required functionality without the D6 patch.
I though I posted it here, but seems like I forgot.

Now attaching it.
Note that this would be the alternative to the patch, so no patch would be required and dependent modules are incompatible with the ones relaying on the D6 patch.

Please forgive the coder's flags for now, I will clean up the code once functionality gets reviewed and approved by a couple of users.

PS: taking note about NOW() vs Unix timestamp. Nevertheless, the uploaded version dates from September 21, so the @TODO comment is still there.

arhak’s picture

Status: Needs work » Needs review
StatusFileSize
new13.57 KB

I hit "Save" instead of "Attach", I shouldn't miss it twice..

arhak’s picture

modules attached at #13 are described at #9

nancydru’s picture

System_settings_form requires the form element name to be the same as the variable name:

function dblog_host_filter_settings() {
  $form['dblog_host_filter:comparison'] = array(
nancydru’s picture

StatusFileSize
new97.54 KB
function dblog_host_filter_log_filters() {
  if (!dblog_filters_is_enabled('hostname')) return array();
  
  $comparison = variable_get('dblog_host_filter:comparison', DBLOG_HOST_FILTER__DEFAULT_COMPARISON);
  if ($comparison == DBLOG_HOST_FILTER__COMPARISON_EQUALS) {
    $op = '=';
    $placeholder = "'%s'";
    $host_list = array();
    $result = db_query("SELECT DISTINCT(hostname) FROM {watchdog}");
    while ($row = db_fetch_array($result)) {
      $host_list[$row['hostname']] = $row['hostname'];
    }
  }
  else {
    $op = 'LIKE';
    switch($comparison) {
      case DBLOG_HOST_FILTER__COMPARISON_STARTS: 
        $placeholder = "'%s%%'";
        break;
      case DBLOG_HOST_FILTER__COMPARISON_ENDS: 
        $placeholder = "'%%%s'";
        break;
      case DBLOG_HOST_FILTER__COMPARISON_CONTAINS:
      default: 
        $placeholder = "'%%%s%%%'";
        break;
    }
  } 
  $filters['hostname'] = array(
    'title' => t('Hostname'),
    'where' => "w.hostname $op $placeholder",
    'conjunction' => FALSE,
  );
  if ($comparison == DBLOG_HOST_FILTER__COMPARISON_EQUALS) {
    if (count($host_list) > 1) {
      $filters['hostname']['widget'] = array(
        '#type' => 'select', 
        '#options' => $host_list,
        );
    }
    else {
      $filters['hostname']['widget'] = array(
        '#type' => 'textfield', 
        '#default_value' => current($host_list),
        '#size' => 27,
        );
    }
  }
  else {
    $filters['hostname']['widget'] = array(
      '#type' => 'textfield', 
      '#size' => 27, // fit the same width as <select>
      );
  }

  return $filters;
}

I don't know if the count > 1 is a great idea. When there is only one, it is always filtering on that, which doesn't actually change the results. Perhaps a "-none-" should be used here too

nancydru’s picture

function dblog_user_filter_log_filters() {
  if (!dblog_filters_is_enabled('username')) {
    return array();
  }
  
  $filters['username'] = array(
    'title' => t('Username'),
    'where' => "u.name = '%s'",
    'conjunction' => FALSE,
    );

  $user_list = array();
  $use_realname = module_exists('realname');
  $result = db_query("SELECT DISTINCT(w.uid) AS x, u.* FROM {watchdog} w INNER JOIN {users} u ON u.uid = w.uid");
  while ($row = db_fetch_object($result)) {
    $user_list[$row->name] = $use_realname ? theme('username', $row, array('plain' => TRUE)) : $row->name;
  }

  $filters['username']['widget'] = array(
    '#type' => 'select',
    '#options' => $user_list,
    );

  return $filters;
}
nancydru’s picture

BTW, these are just suggestions.

arhak’s picture

thanks a lot for your detailed review

the TODO list would be:
1- the coder's flags (@#11)
2- change @TODO comment to document why PHP time over MySQL NOW (@#11)
3- settings form bug: array index doesn't match variable name (@#15)
4- feature: add "- None -" option to host filter (@#16)
5- usability: non-sense condition count($host_list) > 1 (@#16)
6- revamp user filter: use select list instead of autocomplete (@#17)

about the above list
5- I think I meant (but didn't do it) a select under certain threshold and a textfield if the count excedes the threshold (configurable threshold?). Note that the textfield might be used (configurable settings) to match starts/ends/contains/exact, nevertheless it might be implemented with autocompletion as well.
6- Are you sure about always having a select? It might be a huge select! I think it should be a select or autocomplete according to certain threshold (again: configurable threshold?)

nancydru’s picture

5) I did a select list because a) the column is not shown (maybe should be), so how do they know? b) more consistent with core filters. On my sites I have never seen more than one hostname in the log, and I suspect for the vast majority, that's the way it will be. In production, I would never need to implement this filter.

6) One big problem here is that when modules like RealName are installed, the user's "realname" is displayed rather than their user name. People who use this type of facility don't want user names displayed - ever. While it could potentially be a huge list, I doubt that, in practice, it will be that large.

arhak’s picture

6) If there is a log entry for every session opened/closed then the list of users would be as long as registered users exists in the site. am I wrong? am I missing something?
Yes I noticed you were looking realname support, but autocompletion would be the same than provided by core every where user autocompletion is used. right?

5) I never though about it. I implemented it because it was requested in some other issue marked as "won't fix". I though it would had some use case. But I think you are right.

nancydru’s picture

5) Of course I'm right - I'm a woman! ;-) It is possible in a multi-site with shared tables that it could contain multiple values, but I think there are very few of them. I have not looked to see if the "syslog" implementation changes any of this.

6) Yes, on very busy sites with many, many users, this list could get long. However there aren't that many sites that really have that much traffic and that don't allow session data to persist over re-connections (for example, I only log in to DO once a day, even though I am "here" most of the time). Remember there is also a setting to limit how much data can exist in watchdog.

Autocompletion with RealName is a "sticky wicket" in its own right. AC will actually show the underlying username once the selection is done. ATM, we have not found a way around that. Core will not be providing alternate (or display) user names any time soon - the core developers are opposed to it. It is possible that proper display of username will get into D7, and that will allow a better intercept for substituting display names.

In the end, this is your baby, so do what you want.

arhak’s picture

removed double post

(I couldn't remove #24, so removing #23 instead, http://drupal.org/comment/edit/2128522 keeps giving me 503 Service Unavailable)

arhak’s picture

Status: Needs review » Needs work

truly right

5) multi-sites won't have too much hostnames, it should be a select

6) users would be limited by the watchdog limit.

thanks a lot for sticking on this.

Note:
for users that might intend to test these modules, they are in acceptable condition
I encourage testing them and leave feedback
read the current TODO list at #19

PS: I'll bring another release as soon as I get ride of a couple of deadlines

nancydru’s picture

Status: Needs work » Fixed

I committed what I have, so now you can post patches in new issues. Feel free to revert the user and hostname changes.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

arhak’s picture

for the updated TODO list of these modules refer to #623740: dblog_ext/dblog_filters TODO list

arhak’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev
Component: User interface » Dblog_extension