← Back to Apache Course | Chapter 6: Logging | Lesson 2 of 4

Error Log समझना

Error log problems -- module load failures, crashed scripts, permission errors, और Apache के अपने startup messages -- को ordinary traffic से अलग record करता है, ताकि आप सिर्फ यह न जानें कि कुछ टूटा बल्कि *क्यों* टूटा।

यह कहाँ रहता है

Ubuntu/Debian पर default error log /var/log/apache2/error.log है और RHEL-family systems पर /var/log/httpd/error_log। access log की तरह, individual VirtualHosts अपना खुद ErrorLog से define कर सकते हैं (और single-site server से आगे किसी भी चीज़ के लिए करना चाहिए)।

LogLevel

LogLevel control करता है कि कितनी detail लिखी जाती है, कम से ज़्यादा verbose तक: emerg, alert, crit, error, warn, notice, info, debug। default warn production के लिए एक reasonable baseline है; debug कहीं ज़्यादा noisy है और मुख्य रूप से किसी specific problem को actively troubleshoot करते समय useful है, फिर बाद में वापस नीचे कर दिया जाता है।

वहाँ आपको Actually क्या दिखेगा

Startup problems (एक config syntax error, load होने में fail हुआ module, पहले से इस्तेमाल में एक port), permission errors (Apache का user उसे serve करने को कही गई file पढ़ नहीं सकता), PHP fatal errors और stack traces (अगर display_errors off है, जैसा production में होना चाहिए, तो यही *इकलौती* जगह है जहाँ वे दिखते हैं), और mod_rewrite का अपना rewrite-log-equivalent debug output जब LogLevel में rewrite:trace शामिल हो, यह सब यहीं आता है।

Note: जब browser में कुछ काम तो करे लेकिन एक unexpected 500 error के साथ बिना किसी वजह के, error log पर tail -f करें और page reload करें -- असली underlying error लगभग हमेशा वहीं बैठा होता है।

एक Config Change Debug करने के लिए Error Log इस्तेमाल करना

अगर systemctl restart apache2 fail होता है, systemctl status apache2 अक्सर सिर्फ एक truncated summary दिखाता है -- पूरी detail (कौन सी directive, कौन सी file, कौन सी line) लगभग हमेशा error log की सबसे recent lines में होती है, यही कारण है कि इसे check करना आमतौर पर एक failed restart के बाद का अगला step है।

उदाहरण: Per-site error log and LogLevel

apacheconf
<VirtualHost *:80>
    ServerName example.com
    ErrorLog /var/log/apache2/example.com-error.log
    LogLevel warn
</VirtualHost>
{# Flagged by hand after confirming a runner can't handle this example (a shell command / go.mod file stored as a TopicExample, a language feature the configured runner version doesn't support, or output that blows a runner's sandbox limit) -- see TopicExample.norun. Never render the run button for these, regardless of language, since it would just fail at execute_code (or worse, hang the Judge0 queue on a submission that can never finish cleanly). #}

⚠️ This example can't run in the browser editor. Try it in your own local environment instead.

{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक failed restart के बाद सिर्फ systemctl status check करके रुक जाना, error log में intezar कर रही ज़्यादा detailed explanation miss करते हुए।
  2. production को LogLevel debug पर हमेशा के लिए on छोड़कर चलाना, ज़रूरत से कहीं ज़्यादा noise generate करते हुए और real problems को scan करना मुश्किल बनाते हुए।
  3. यह न समझना कि display_errors off (production के लिए correct) होने पर भी PHP/application errors error log में जाते रहते हैं -- वे browser में सिर्फ invisible हैं, पूरी तरह gone नहीं।
🔒

Chapter Quiz — Complete all 4 topics to unlock

0/4 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.