-
Notifications
You must be signed in to change notification settings - Fork 275
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
Explore logging to a file #1292
Conversation
@adamziel I would appreciate some advice on a few issues with this exploration. Saving to fileThe current implementation isn't fully working because of a mix of sync and async code. Because writing to files must be async we could split the process into log collecting to an array and log saving to a file. Getting the PHP instanceThe logger doesn't need a PHP instance, we currently use it only in the collector, but with saving to files, the file handle needs access to PHP. I see a few options, but they all have pros and cons. Get PHP from collectPhpLogs (not an option)When calling Logger initializerWe could add the php instance to the logger when PHP-wasm starts. This would require yet another initializer function, or updating how we initialize the logger. Moving the logger instance into the PHP instanceWe could consider storing the logger instance in BasePHP. When the logger instance is created, it would have access to the PHP instance. We initially moved away from this because we didn't want to tightly couple the logger with PHP-wasm, but we went in that direction later to support collecting different log types. This would also allow us to expose the logger instance to the Playground client, which is a missing feature for projects that use the Playground JS API and want to get log events. |
I will move forward with storing logs in an array and moving them to a file on This should keep the code simple and avoid frequent file writes. |
a36df97
to
5453638
Compare
I still need to figure out what to do with this before I can continue. |
How would you save a "PHP instance crashed irreperably" log to a file in the PHP filesystem? What are some upsides of doing that? |
I don't think that we can do that. Once PHP crashes we don't have file access, or am I wrong? |
Aha, that makes sense @bgrgicak! I'd love to help, I'm just not sure what's the specific question you're looking an answer for. It seems like a new log handler would solve this? |
Yes, the handler would pull data from the main logger instance and send it to a file on every 'request.end'. This is the easy part. What I'm unsure about is how to pass the PHP instance to the handler because the logger doesn't have access to it today. I was thinking of not initializing the logger automatically and initialize it somewhere in PHP-wasm, for example BasePHP. But I'm not sure if there is a better way to do it. |
Gotcha! I'd avoid intertwining it with BasePHP and offload this to the developers – they could create that handler in their app like this: const php = await myCustomPHPFactoryForMyUniqueApp();
logger.addHandler( createPHPFileLogHandler( php, '/tmp/log.txt' ) ); Or something to that effect |
What is this PR doing?
What problem is it solving?
How is the problem addressed?
Testing Instructions