coen-hyde / Shanty-Mongo

Shanty Mongo is a mongodb library for the Zend Framework. Its intention is to make working with mongodb documents as natural and as simple as possible. In particular allowing embedded documents to also have custom document classes.
Other
200 stars 52 forks source link

Log writer #34

Closed esslogic-gn closed 8 years ago

esslogic-gn commented 13 years ago

Hi

I've created a log writer for Shanty which is derived from Zend_Log_Writer_Db code (it also supports additional custom fields like Zend_Log_Writer_Db). Are you interested in pulling this into your repo?

https://github.com/GishX/Shanty-Mongo/tree/log-writer/library/Shanty/Log

Thanks. G

Creating the log writer using Zend_Log::factory()

    $logger = Zend_Log::factory(array(
                'timestampFormat' => 'Y-m-d',
                array(
                    'writerName' => 'Mongo',
                    'writerNamespace' => 'Shanty_Log_Writer',
                    'writerParams' => array(
                        'documentClass' => 'My_Log_Document',
                        'columnMap' => array(
                            'priority' => 'priority',
                            'message' => 'message',
                            'timestamp' => 'timestamp',
                            'ip' => 'ip',
                            'username' => 'username'
                        )
                    ),
                )
            ));

    // Custom fields
    $logger->setEventItem('ip', $_SERVER['REMOTE_ADDR']);
    $logger->setEventItem('username', 'GishX');
    $logger->info('Log this message');  

Create the log writer, then register it with Zend_Log()

    $writer = new Shanty_Log_Writer_Mongo(
                    'My_Log_Document',
                    array(
                        'priority' => 'priority',
                        'message' => 'message',
                        'timestamp' => 'timestamp',
                        'ip' => 'ip',
                        'username' => 'username'
                        )
            );

    // Create a logger and register the writer with it
    $logger = new Zend_Log($writer);

    // Custom fields
    $logger->setEventItem('ip', $_SERVER['REMOTE_ADDR']);
    $logger->setEventItem('username', 'GishX');            
    $logger->info('Log this message');
coen-hyde commented 13 years ago

Thanks GishX,

Yes this is a good idea. If you can add some tests then this will get included quicker.

Cheers, Coen

esslogic-gn commented 13 years ago

No problem, leave it with me - i'll work on the tests.

Cheers. G

coen-hyde commented 13 years ago

Fantastic, looking forward to seeing this included!