-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.html
126 lines (88 loc) · 5.18 KB
/
errors.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Errors & Logging</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/ubuntu-font.css">
<script src="vendor/modernizr-2.6.2.min.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/prettify.js"></script>
</head><body><section class="docs-content"><div class="container">
<article class="docs-body"><h1>Errors & Logging</h1>
<p><a name="error-detail"></a></p>
<h2>Error Detail</h2>
<p>By default, error detail is enabled for your application. This means that when an error occurs you will be shown an error page with a detailed stack trace and error message. You may turn off error details by setting the <code>debug</code> option in your <code>app/config/app.php</code> file to <code>false</code>. <strong>It is strongly recommended that you turn off error detail in a production environment.</strong></p>
<p><a name="handling-errors"></a></p>
<h2>Handling Errors</h2>
<p>By default, the <code>app/start/global.php</code> file contains an error handler for all exceptions:</p>
<pre class="prettyprint"><code>App::error(function(Exception $exception)
{
Log::error($exception);
});
</code></pre>
<p>This is the most basic error handler. However, you may specify more handlers if needed. Handlers are called based on the type-hint of the Exception they handle. For example, you may create a handler that only handles <code>RuntimeException</code> instances:</p>
<pre class="prettyprint"><code>App::error(function(RuntimeException $exception)
{
// Handle the exception...
});
</code></pre>
<p>If an exception handler returns a response, that response will be sent to the browser and no other error handlers will be called:</p>
<pre class="prettyprint"><code>App::error(function(InvalidUserException $exception)
{
Log::error($exception);
return 'Sorry! Something is wrong with this account!';
});
</code></pre>
<p>To listen for PHP fatal errors, you may use the <code>App::fatal</code> method:</p>
<pre class="prettyprint"><code>App::fatal(function($exception)
{
//
});
</code></pre>
<p><a name="http-exceptions"></a></p>
<h2>HTTP Exceptions</h2>
<p>Exceptions in respect to HTTP, refer to errors that may occur during a client request. This may be a page not found error (404), an unauthorized error (401) or even a generated 500 error. In order to return such a response, use the following:</p>
<pre class="prettyprint"><code>App::abort(404, 'Page not found');
</code></pre>
<p>The first argument, is the HTTP status code, with the following being a custom message you'd like to show with the error.</p>
<p>In order to raise a 401 Unauthorized exception, just do the following:</p>
<pre class="prettyprint"><code>App::abort(401, 'You are not authorized.');
</code></pre>
<p>These exceptions can be executed at any time during the request's lifecycle.</p>
<p><a name="handling-404-errors"></a></p>
<h2>Handling 404 Errors</h2>
<p>You may register an error handler that handles all "404 Not Found" errors in your application, allowing you to return custom 404 error pages:</p>
<pre class="prettyprint"><code>App::missing(function($exception)
{
return Response::view('errors.missing', array(), 404);
});
</code></pre>
<p><a name="logging"></a></p>
<h2>Logging</h2>
<p>The Laravel logging facilities provide a simple layer on top of the powerful <a href="http://github.com/seldaek/monolog">Monolog</a>. By default, Laravel is configured to create daily log files for your application, and these files are stored in <code>app/storage/logs</code>. You may write information to these logs like so:</p>
<pre class="prettyprint"><code>Log::info('This is some useful information.');
Log::warning('Something could be going wrong.');
Log::error('Something is really going wrong.');
</code></pre>
<p>The logger provides the seven logging levels defined in <a href="http://tools.ietf.org/html/rfc5424">RFC 5424</a>: <strong>debug</strong>, <strong>info</strong>, <strong>notice</strong>, <strong>warning</strong>, <strong>error</strong>, <strong>critical</strong>, and <strong>alert</strong>.</p>
<p>Monolog has a variety of additional handlers you may use for logging. If needed, you may access the underlying Monolog instance being used by Laravel:</p>
<pre class="prettyprint"><code>$monolog = Log::getMonolog();
</code></pre>
<p>You may also register an event to catch all messages passed to the log:</p>
<p><strong>Registering A Log Listener</strong></p>
<pre class="prettyprint"><code>Log::listen(function($level, $message, $context)
{
//
});
</code></pre>
</article><div class="clearfix"></div>
</div>
</section>
<script src="js/jquery.min.js"></script>
<script src="js/plugins.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/run_prettify.js"></script>
</body></html>