Changeset 180


Ignore:
Timestamp:
Jun 23, 2006 10:00:21 PM (18 years ago)
Author:
scdev
Message:

Q - set limit to the length of logged messages. Added timeElapsed to Utilities.inc.php.

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r177 r180  
    530530            'type'      => $this->logPriorityToString($priority),
    531531            'file:line' => "$file : $line",
    532             'url'       => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''),
     532            'url'       => substr(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '', 0, 128),
    533533            'message'   => $message
    534534        );
     
    537537        if ($this->getParam('log_file_priority') && $priority <= $this->getParam('log_file_priority')) {
    538538            $event_str = '[' . join('] [', $event) . ']';
    539             error_log($event_str . "\n", 3, $this->getParam('log_directory') . '/' . $this->getParam('log_filename'));
     539            error_log(substr($event_str, 0, 1024) . "\n", 3, $this->getParam('log_directory') . '/' . $this->getParam('log_filename'));
    540540        }
    541541
     
    554554        if ($this->getParam('log_sms_priority') && $priority <= $this->getParam('log_sms_priority')) {
    555555            $subject = sprintf('[%s %s]', getenv('HTTP_HOST'), $priority);
    556             $sms_msg = sprintf('%s [%s:%s]', $event['message'], basename($file), $line);
     556            $sms_msg = sprintf('%s [%s:%s]', substr($event['message'], 0, 64), basename($file), $line);
    557557            $headers = "From: codebase@strangecode.com";
    558558            mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
  • trunk/lib/Utilities.inc.php

    r159 r180  
    270270
    271271    return sprintf($format, $size, $units[$i]);
     272}
     273
     274/*
     275* Returns a human readable amount of time elapsed since the given unix timestamp.
     276*
     277* 45 seconds
     278* 12 minutes
     279* 3.5 hours
     280* 2 days
     281* 1 week
     282* 4 months
     283*
     284* Months are calculated using the real number of days in a year: 365.2422 / 12.
     285*
     286* @access   public
     287* @param    int $time Unix timestamp of date to find elapsed from.
     288* @param    string $max_unit Key value from the $units array.
     289* @param    string $format Sprintf formatting string.
     290* @return   string Value of units elapsed.
     291* @author   Quinn Comendant <quinn@strangecode.com>
     292* @version  1.0
     293* @since    23 Jun 2006 12:15:19
     294*/
     295function timeElapsed($time, $max_unit=null, $format='%01.1f')
     296{
     297    if ($time <= time()) {
     298        $elapsed = $time_diff = time() - $time;
     299    } else {
     300        $elapsed = $time_diff = $time - time();
     301    }
     302   
     303    // Units
     304    $units = array(
     305        'second' => array(1, _("second"), _("seconds")),
     306        'minute' => array(60, _("minute"), _("minutes")),
     307        'hour' => array(3600, _("hour"), _("hours")),
     308        'day' => array(86400, _("day"), _("days")),
     309        'week' => array(604800, _("week"), _("weeks")),
     310        'month' => array(2629743.84, _("month"), _("months")),
     311        'year' => array(31556926.08, _("year"), _("years")),
     312        'decade' => array(315569260.8, _("decade"), _("decades")),
     313    );
     314   
     315    // Max unit
     316    $max_unit = isset($units[$max_unit]) ? $max_unit : 'decade';
     317
     318    foreach ($units as $k => $v) {
     319        if ($max_unit != $k && $time_diff >= $v[0]) {
     320            $elapsed = $time_diff / $v[0];
     321            $last_unit = $k;
     322        }
     323    }
     324    $elapsed = sprintf($format, $elapsed);
     325    return sprintf('%s %s', $elapsed, (1 == $elapsed ? $units[$last_unit][1] : $units[$last_unit][2]));   
    272326}
    273327
Note: See TracChangeset for help on using the changeset viewer.