CodeIgniter日志无法在本地浏览器/Git Bash显示,请求技术支持
Let's walk through the most common fixes for when your CodeIgniter logs aren't showing up—this is a super common issue, so we'll get you sorted quickly.
Fix directory permissions first
CodeIgniter needs write access to theapplication/logsfolder to create log files. On Linux/macOS, open Git Bash and run:chmod 755 application/logsIf that doesn't work, temporarily use
chmod 777 application/logsto test (just remember to set it back to 755 afterward for security). On Windows, make sure the user running your web server (like IIS_IUSRS or Apache) has write permissions for the logs folder.Watch the correct log file, not just the directory
Yourtail -f application/logscommand is watching the directory itself, not the actual log file. CodeIgniter names logs likelog-YYYY-MM-DD.phpby default. Use this command instead to watch today's log:tail -f application/logs/log-$(date +%Y-%m-%d).phpAlso, note that the log file won't exist until the first log entry is written—so make sure you trigger the code that calls
log_messagebefore running this command.Double-check your config.php settings
- Confirm
$config['log_threshold'] = 1;isn't commented out and there's no later line in the file overriding this value. A threshold of 1 should log all errors, which matches yourlog_message('error', ...)call. - Verify
$config['log_path']is set correctly (it defaults toAPPPATH.'logs/', but if you changed it, ensure the path exists and is writable).
- Confirm
Test with a simple log message
Yourlog_message('error', print_r($data, true));looks valid, but maybe the code path isn't executing, or$datais causing an unexpected issue. Add a simple test line first:log_message('error', 'TEST: This is a sample error log entry');Run that code, then check if the log file appears. If the test works, your original
$datavariable might have something odd going on—butprint_r($data, true)should handle most cases.Check for server-level error suppression
Open your rootindex.phpfile and make sure error reporting isn't being suppressed. Look for lines likeerror_reporting(0)—if you see that, change it toerror_reporting(E_ALL);temporarily to ensure errors are being captured.Check the server's PHP error log
If CodeIgniter can't write to its own logs, it might log the failure to the server's PHP error log. On Linux, this is usually at/var/log/apache2/error.logor/var/log/nginx/error.log—check here for permission errors related to theapplication/logsfolder.
内容的提问来源于stack exchange,提问作者Jasmin

