Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a logger in production

Tags:

php

logging

I am making some changes on the live site and i constantly need to add loggers (print_r) throughout the page for me to test. The problem is the site is healily populated by staff and I need it so I am for sure the only one to see this logger. I heard I can wrap the logger in an if with my Ip address but i thought I while back i tried that and the client still viewed it. Anybody have an ideas or the syntax needed to make this happen. By the way I think the PHP version is an older on

like image 592
Matt Elhotiby Avatar asked Dec 29 '22 08:12

Matt Elhotiby


2 Answers

You could always pass yourself a variable in get and switch on that

http://mysite.com?debug=secret

then:

  if($_GET['debug'] === "secret"){
     print_r($stuff);
  }

Before I used frameworks I used to set a cookie when debug="secret" so that I do not have to put it all the time. And since only you have the cookie set you are ok.

like image 99
Iznogood Avatar answered Jan 05 '23 16:01

Iznogood


This restricts //your debug code to IP 12.34.56.78.

if(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '12.34.56.78'){
   //your debug code
}

You could also store this in a constant:

define('SHOWDEBUG', isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '12.34.56.78');

Somewhere else: SHOWDEBUG && print_r($dumped);

like image 34
Lekensteyn Avatar answered Jan 05 '23 16:01

Lekensteyn