-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log File Name Pattern #758
Comments
Not currently, and I don’t think Craft allows this either. You can create your own logger to catch specific logs and format them however you like using Monolog. I have an article that should help you get started: |
Hi Ben, I got following answer from craft support:
We require the hostname in the log file name because our setup consists of multiple nodes that share a storage folder. This storage folder is an NFS mount that is used by all nodes |
It’s not possible to modify the Blitz log target via config, but you can add your own using a custom plugin/module. if (Craft::getLogger()->dispatcher instanceof Dispatcher) {
Craft::getLogger()->dispatcher->targets[] = new MonologTarget([
'name' => ($_SERVER['HTTP_HOST'] ?? 'localhost') . '-blitz',
'categories' => ['blitz'],
'level' => LogLevel::INFO,
'logContext' => false,
'allowLineBreaks' => false,
'formatter' => new LineFormatter(
format: "[%datetime%] %message%\n",
dateFormat: 'Y-m-d H:i:s',
),
]);
} This is basically a copy of the Let me know if this helps. |
Would that replace the default blitz log file? |
No, that would add a new logger. You could remove the existing Blitz logger using something like this. if (Craft::getLogger()->dispatcher instanceof Dispatcher) {
foreach (Craft::getLogger()->dispatcher->targets as $key => $target) {
if ($target instanceof MonologTarget && $target->getName() === 'blitz') {
unset(Craft::getLogger()->dispatcher->targets[$key]);
}
}
// Add a custom Blitz logger
} |
Hi Ben, is there an event I can hook on to unset the blitz logger? Because my module's code is executed before Blitz is initialized, or rather, the existing logger targets are web, console, & queue at the runtime of my module, so at the time there is no blitz logger present. |
Wrapping your code in this should work. Craft::$app->onInit(function() {
}); |
Support Request
Is it possible to add the Servers Hostname to the filename? Like $HOSTNAME_blitz-2025-01-27.log
We would provide the hostname through the .env file.
Plugin Version
4.23.7
The text was updated successfully, but these errors were encountered: