77class MonologHandler extends RollbarHandler
88{
99 protected $ app ;
10-
10+
1111 public function setApp ($ app )
1212 {
1313 $ this ->app = $ app ;
1414 }
15-
15+
1616 protected function write (array $ record )
1717 {
1818 $ record ['context ' ] = $ this ->addContext ($ record ['context ' ]);
@@ -30,23 +30,34 @@ protected function addContext(array $context = [])
3030 if ($ session = $ this ->app ->session ->all ()) {
3131 $ config = $ this ->rollbarLogger ->extend ([]);
3232
33- if (empty ($ config ['person ' ]) or ! is_array ($ config ['person ' ])) {
33+ if (empty ($ config ['person ' ]) || ! is_array ($ config ['person ' ])) {
3434 $ person = [];
3535 } else {
3636 $ person = $ config ['person ' ];
3737 }
3838
3939 // Merge person context.
40- if (isset ($ context ['person ' ]) and is_array ($ context ['person ' ])) {
40+ if (isset ($ context ['person ' ]) && is_array ($ context ['person ' ])) {
4141 $ person = $ context ['person ' ];
4242 unset($ context ['person ' ]);
43- } else {
44- if (isset ($ config ['person_fn ' ]) && is_callable ($ config ['person_fn ' ])) {
45- $ data = @call_user_func ($ config ['person_fn ' ]);
46- if (isset ($ data ['id ' ])) {
47- $ person = call_user_func ($ config ['person_fn ' ]);
43+ } elseif (isset ($ config ['person_fn ' ]) && is_callable ($ config ['person_fn ' ])) {
44+ $ data = @call_user_func ($ config ['person_fn ' ]);
45+ if (! empty ($ data )) {
46+ if (is_object ($ data )) {
47+ if (isset ($ data ->id )) {
48+ $ person ['id ' ] = $ data ->id ;
49+ if (isset ($ data ->username )) {
50+ $ person ['username ' ] = $ data ->username ;
51+ }
52+ if (isset ($ data ->email )) {
53+ $ person ['email ' ] = $ data ->email ;
54+ }
55+ }
56+ } elseif (is_array ($ data ) && isset ($ data ['id ' ])) {
57+ $ person = $ data ;
4858 }
4959 }
60+ unset($ data );
5061 }
5162
5263 // Add user session information.
@@ -60,7 +71,7 @@ protected function addContext(array $context = [])
6071 if (! isset ($ person ['id ' ])) {
6172 $ person ['id ' ] = $ this ->app ->session ->getId ();
6273 }
63-
74+
6475 $ this ->rollbarLogger ->configure (['person ' => $ person ]);
6576 }
6677
0 commit comments