Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Logs with username

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 836 Views
  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Logs with username Link to this post

    Hi,

    I am using the...

    SS_Log::add_writer(new SS_LogEmailWriter('myemail@somedomain.com', SS_Log::ERR);

    and I get emails for my errors sent to me - however what would be pure gold is if I could also get the name of the user (assuming someone is logged in) in that email so I know who to ask for when I want more information about what they were doing... any advice is much appreciated.

    Barry

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Logs with username Link to this post

    I think maybe something along the line of (see the documentation in the header of class SS_Log):

    $logEmailWriter = new SS_LogEmailWriter('my@email.com');
    $myEmailFormatter = new MyLogEmailFormatter();
    $logEmailWriter->setFormatter($myEmailFormatter);

    SS_Log::add_writer($logEmailWriter, SS_Log::ERR);

    Have MyLogEmailFormatter extend the SS_LogErrorEmailFormatter class. Then have it add Member::currentUser() somewhere?

    No idea if this will work though, haven't tried

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Logs with username Link to this post

    I was hoping it was a setting - but that is very close I should have followed the code a little more... I am going to set this up now and I'll report back what has worked.

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Logs with username Link to this post

    Maybe I've overlooked a setting - don't think so though... Very interested in what you'll come up with

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Logs with username Link to this post

    All working....

    _config.php

       $logEmailWriter = new SS_LogEmailWriter('some@email.com');
       $myEmailFormatter = new MyLogErrorEmailFormatter();
       $logEmailWriter->setFormatter($myEmailFormatter);
       SS_Log::add_writer($logEmailWriter, SS_Log::ERR);

    MyLogErrorEmailFormatter.php

    class MyLogErrorEmailFormatter extends SS_LogErrorEmailFormatter {
       public function format($event) {
          $arr = parent::format($event);

          $member=Member::currentUser();
          $arr['data'] .= 'Member='.$member->ID.','.$member->FirstName.','.$member->Surname."\r\n\r\n";

          $browser = new Browser();
          $arr['data'] .= $browser."\r\n\r\n";

          if (count($_POST)) {
             ob_start();
             print_r($_POST);
             $arr['data'] .= ob_get_contents();
             ob_end_clean();
          }

          if (count($_GET)) {
             ob_start();
             print_r($_GET);
             $arr['data'] .= ob_get_contents();
             ob_end_clean();
          }

          return $arr;
       }
    }

    As you can see I've also included the get/post and browser in this too...
    http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Logs with username Link to this post

    Nice! Together we're strong

    836 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.