<p>I'm working with <a href="http://pear.php.net/package/Log" rel="nofollow noreferrer">logging in PHP with Pear</a>, and I get into a standard problem: can I use file-based logging when the DB is not available? I don't mind if it's slow due to concurrency issues, but it cannot fail to work due to multiple, simultaneous hits. </p>

<p>I'm asking this question in general (for other web technologies) and specifically for Pear for PHP.</p>

<p>Thanks!</p>

You can pass an existing database object into the
singleton method of Log
- if you don't have a database you can revert to alternative logging methods (or good old user_error())
```
```
require_once 'DB.php';
$db = &DB::connect('pgsql://jon@localhost+unix/logs');

$conf['db'] = $db;
$logger = &Log::singleton('sql', 'log_table', 'ident', $conf);
```
```