Welcome Guest, Not a member yet? Register   Sign In
Should CodeIgniter\Log\FileHandler support [schema]://[path]
#4

(This post was last modified: 03-28-2020, 06:58 AM by trkclk.)

(03-27-2020, 02:12 PM)dave friend Wrote: I think a StreamHandler is the way to go. I'm curious about how do you see the "stream" being used?

Everything started with me having a Docker setup in which I collect the stdout from all containers and combine it to one (way of centralizing logs while developing). While looking at the source co of the FileHandler I came across this line:

PHP Code:
$filepath $this->path 'log-' date('Y-m-d') . '.' $this->fileExtension

and realized that setting the path to "php://stdout" is not going to work, because the handler will always append the 'log-'... string as the file name.
That is why there was a need for php://stdout. Looking at the PHP wrapper made me think if some other wrappers would need to be supported.
Supporting  zlib:// or even ssh2:// would also be handy. 

The thing with supporting other wrappers comes with a price and that would be lots of fs, network, ... IO. 
How can we optimize the IO mechanism in a way that we write just once to our configured path (eg. zip://./logs.zip#log_name.log)!?

How about this... 
Logger->log writes to php://temp and the Logger class also registers a shutdown function that reads logs from php://temp and writes to all log handlers in the queue (making some decisions based on the level).

Here is a simple example, to better explain my idea:

PHP Code:
<?php

// Memory file handle would be cached as a property of the Logger shared instance
$fp fopen("php://temp/maxmemory:4096"'a+'); // We can use php://memory or php://temp

// Push our dumper to the shutdown function queue
// Each 
register_shutdown_function(function() use ($fp) {
    
rewind($fp);
    
// Here we can loop trough our log handlers queue
    // and write log messages (with levels handlers are subscribed to) to the handler's open file handles
    
fpassthru($fp); // fpassthru is here just for testing the output :)
    
fclose($fp);    
});

for (
$x 0$x <= 100$x++) {
    
// No need for locking, because the memory file is isolated to only this process
    
fwrite($fpsprintf("ERROR #%d\n"$x));
}


exit(
1); 

Edit: a+ mode would be more appropriate Smile
Reply


Messages In This Thread
RE: Should CodeIgniter\Log\FileHandler support [schema]://[path] - by trkclk - 03-28-2020, 05:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB