1

I'm using Laravel 4.1 to write an application. For some reason I need to disable debug in all environments including production, but I need to provide a means for users to be able to enable debug mode without editing configuration files (app.php) whenever needed (that means at runtime)

Is there a way to do so? I tried to change debug settings in App::before but that does not seem to be the correct solution (exception handlers are already registered at that point)

Update:
In last paragraph I said

exception handlers are already registered at that point

This comment is misleading I think. Exception handlers should be registered anyway.
The actual problem I need to solve is: How to change which displayer (plainDisplayer or debugDisplayer) to use?

This decision is made at runtime (whenever an exception actually occures) based on value of a variable ($debug) in Illuminate\Exception\Handler

Calling app('exception')->setDebug(true) makes exception handler to use debug displayer but I'm not sure if this is the correct way to do it, specially if I'm going to put this code in App::before filter

6
  • We do Config::set('app.debug', true) in App::before based on a session value without any issues. Commented Dec 16, 2014 at 15:47
  • @ceejayoz Thanks. As I said in my question, I already tried this but did not get desired results. If this works for you then I should check and see if there is anything wrong with my code. Commented Dec 17, 2014 at 8:26
  • @ceejayoz Could you please provide more details? This is exactly what I want to do. Commented Dec 17, 2014 at 8:46
  • In app/filters.php we did App::before(function($request) { Config::set('app.debug', Session::get('debug_mode', false)); }); Commented Dec 17, 2014 at 15:19
  • This is what I did before, but the problem is, when you set app.debug to true, when an exception is thrown what is displayed is a simple error page not a full back-trace. This is different from when you enable debugging from within configuration files Commented Dec 17, 2014 at 15:59

2 Answers 2

3

You can edit config settings using the Config class. This will edit the settings for the current request in any enviroment. With this you can set or get the debug value like so:

Config::set('app.debug', true);
Sign up to request clarification or add additional context in comments.

Comments

1

Why would you enable users to see your internal app debugging, that sounds like a security nightmare. Users would be able to force errors and potentially get sensitive information, such as API keys, database information, etc, etc.

Why not, throw/catch errors in your app, display a nice view to the user and log the actual errors somewhere away from the users view?

7 Comments

In fact, errors are already logged by default in app/storage/logs/laravel.log
Only developers will have access to this feature and we can't use log files because developers do not have access to them
@Nima Is there any reason to not use the environment features built-in to Laravel in order to enable debugging for developers? Development / debugging shouldn't be done on the production server.
@John I know this is not a good thing to do, but the decision is not mine. And we actually won't have this feature enabled on production server. But the problem is, developers do not have access to log files on staging server
One thing you could do is set a cron on the staging server to email out the log file then empty it, so you get a periodic email of all the errors that have happened. But really if this is for a staging server then why not just turn errors on in staging?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.