Log getting flooded with unnecessary/wrong log debug.
Bug description
So, I'm using full measure static caching and my log files are getting FLOODED by this:
"Log::debug('Static cache loaded ['.$url.'] If you are seeing this, your server rewrite rules have not been set up correctly.');"
Looking for the code that does this I found out that there is a conditional that checks if we have a "lqs" in our $path Line 80 - see file on GitHub. , however there is another conditional to ADD that "lqs" that is not being checked to add the log message Line 167 - see file on GitHub.
What happens when the "lqs" is not added simply because it's not long? in this case we have a flooded log file without any error.
Everything is working fine except for the fact that I have huge log files with unnecessary messages.
How to reproduce
Fresh install.
Enable full measure static cache.
Warm the cache.
Put a nocache tag anywhere.
Visit any URL and check the log.
Logs
No response
Environment
Environment
Application Name: statamic_local
Laravel Version: 9.52.16
PHP Version: 8.2.7
Composer Version: 2.5.8
Environment: local
Debug Mode: ENABLED
URL: s11-statamic.test
Maintenance Mode: OFF
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 3
Antlers: runtime
Stache Watcher: Enabled
Static Caching: full
Version: 4.28.0 PRO
Installation
Fresh statamic/statamic site via CLI
Antlers Parser
runtime (new)
Additional details
No response
If full measure hits your PHP application, your rewrite rules indeed haven't been set up correctly.
The full measure static cache puts rendered html files into the folder public/static. Your server should try to fetch the file according to the requested URL if it finds it. If not, it will hit your PHP application.
Can you share your nginx/Apache config?
Full measure will hit the PHP application to make the replacements it needs to (nocache tags), that's when the log gets flooded.
Here you have my config:
server { listen 443 ssl http2; listen [::]:443 ssl http2;
index index.html index.htm index.php;
location / {
try_files /static${uri}_${args}.html $uri /index.php?$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
I have edit the issue to put the nocache tag as a step to reproduce this.
Can't confirm this. Your rewrite rules don't seem to take affect. The nocache tag doesn't hit the usual page routes, it injects JS that fetches only the parts needed and replaces them.
What environment are you at? Are you using valet (cause of the .test domain)?
Cause if so, I myself haven't successfully managed to adjust the nginx config of valet (v4) to first use the static generated files as there is a rewrite rule in place of the location /.
But to summarize: it's a nginx problem you are facing. This is not a bug, it has to do with your nginx config. I can confirm it working on a separate server.
I understand that you think it's an nginx issue, but I can confirm it's not. I have it on my production server and it's serving the HTML files and the issue occurs when the nocache tag is loaded.
If you read the outlined lines that I put there on statamic core, you will see that the code doesn't seem to be right.
This is happening on my production server and it's causing my logs files to be huge and I'm 100% sure that I'm serving HTML files because if not my website wouldn't be that fast.
You can try it locally, put a nocache tag inside any antlers view, warm the cache and hit that page, after the nocache tag loads, it's going to log it. (using full measure).
Doesn't matter if the HTML file was served or not, the issue is related with the nocache tag.
The issue happens when the nocache tags get replaced, try to focus on that, forget the static cache.
We are also having this issue on our production sites.
HTML pages are definitely being loaded from the static cache.
In our case we are not using any nocache tags on the site.
HTML pages are definitely being loaded from the static cache.
The html page will still be read, but it will be read by PHP.
@jasonvarga The nocache tags will fetch the content through PHP and that's when the error occurs.
Got rid of this. Ty
@stanbridge-wcorrea What did you do in order to resolve the issue?
The nocache tags aren't firing the debug message, I basically forced nginx to load the static cache without query string since I'm using the config "ignore_query_strings" set to TRUE it doesn't make sense to pass $args to NGINX, with that, I'm always loading the static file never passing by PHP at all, in the end I don't have this log message anymore.
However, if I pass $args to NGINX and pass the query string and it goes through PHP, I have the message.