From 572a4e258b3eeea09f2e82423344cda0a5b9cae3 Mon Sep 17 00:00:00 2001 From: Curtis Kelsey Date: Fri, 26 Feb 2016 22:37:43 -0600 Subject: [PATCH 1/4] Starting the documentation of the Mail writer. --- doc/book/writers.md | 73 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/doc/book/writers.md b/doc/book/writers.md index 27ad07d7..22f6d5e0 100644 --- a/doc/book/writers.md +++ b/doc/book/writers.md @@ -39,7 +39,7 @@ The constructor of `Zend\Log\Writer\Stream` also accepts an existing stream reso ```php $stream = @fopen('/path/to/logfile', 'a', false); if (! $stream) { - throw new Exception('Failed to open stream'); +throw new Exception('Failed to open stream'); } $writer = new Zend\Log\Writer\Stream($stream); @@ -57,7 +57,7 @@ constructing a `Stream` instance; when doing so, the `stream` key is required: ```php $writer = new Zend\Log\Writer\Stream([ - 'stream' => 'php://output', +'stream' => 'php://output', ]); $logger = new Zend\Log\Logger(); $logger->addWriter($writer); @@ -85,9 +85,9 @@ separator for the log array: ```php $dbconfig = [ - // Sqlite Configuration - 'driver' => 'Pdo', - 'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', +// Sqlite Configuration +'driver' => 'Pdo', +'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', ]; $db = new Zend\Db\Adapter\Adapter($dbconfig); @@ -107,16 +107,16 @@ store only to the selected fields in the database: ```php $dbconfig = [ - // Sqlite Configuration - 'driver' => 'Pdo', - 'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', +// Sqlite Configuration +'driver' => 'Pdo', +'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', ]; $db = new Zend\Db\Adapter\Adapter($dbconfig); $mapping = [ - 'timestamp' => 'date', - 'priority' => 'type', - 'message' => 'event', +'timestamp' => 'date', +'priority' => 'type', +'message' => 'event', ]; $writer = new Zend\Log\Writer\Db($db, 'log_table_name', $mapping); $logger = new Zend\Log\Logger(); @@ -164,7 +164,54 @@ $ composer require ccampbell/chromephp ## Writing to Mail -- TODO +`Zend\Log\Writer\Mail` requires a configuration array or `Zend\Mail\Message`. The configuration array accepts: + +```php +[ +'subject_prepend_text' => '', +'transport' => Transport\TransportInterface +'mail' => MailMessage | array +] +``` + +Array Index | Accepted Values | Description +----------- | --------------- | ----------- +`subject_prepend_text` | string | Mail message +`transport` | `Transport\TransportInterface` | +`mail` | `Zend\Mail\Message` | +| array | `Zend\Mail\Message` factory array + +By default `sendmail` is used to send mail messages. + +```php +$writer = new Zend\Log\Writer\Mail($mail); + +$logger = new Zend\Log\Logger(); +$logger->addWriter($writer); + +$logger->info('Informational message'); +``` + +You can provide a Transport configuration during construction. + +```php +$writer = new Zend\Log\Writer\Mail($mail, $transport); +``` + +Mail transports available include: +- Sendmail +- SMTP +- File +- In Memory + +For configuration options checkout the `Zend\Mail\Transport` documentation. + +The following table details all allowed constructor arguments and their corresponding configuration options. + +Constructor Argument | Option Name | Default | Description +-------------------- | ----------- | ------- | ----------- +`$mail` | mail | None; required | Mail message +`$transport` | transport | null | Mail transport to use ## Writing to MongoDB @@ -257,4 +304,4 @@ which means that: - higher integer values indicate higher priority (triggered earliest); - lower integer values (including negative values) have lower priority - (triggered last). +(triggered last). From 054ae8e5aee726a008a85d747181ec0895877be9 Mon Sep 17 00:00:00 2001 From: Curtis Kelsey Date: Fri, 26 Feb 2016 22:58:39 -0600 Subject: [PATCH 2/4] Updated Mail writer documentation formatting. --- doc/book/writers.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/doc/book/writers.md b/doc/book/writers.md index 22f6d5e0..3eae21ac 100644 --- a/doc/book/writers.md +++ b/doc/book/writers.md @@ -168,9 +168,9 @@ $ composer require ccampbell/chromephp ```php [ -'subject_prepend_text' => '', -'transport' => Transport\TransportInterface -'mail' => MailMessage | array + 'subject_prepend_text' => '', + 'transport' => Transport\TransportInterface + 'mail' => MailMessage | array ] ``` @@ -179,7 +179,7 @@ Array Index | Accepted Values | Description `subject_prepend_text` | string | Mail message `transport` | `Transport\TransportInterface` | `mail` | `Zend\Mail\Message` | -| array | `Zend\Mail\Message` factory array + | array | `Zend\Mail\Message` factory array By default `sendmail` is used to send mail messages. @@ -206,13 +206,6 @@ Mail transports available include: For configuration options checkout the `Zend\Mail\Transport` documentation. -The following table details all allowed constructor arguments and their corresponding configuration options. - -Constructor Argument | Option Name | Default | Description --------------------- | ----------- | ------- | ----------- -`$mail` | mail | None; required | Mail message -`$transport` | transport | null | Mail transport to use - ## Writing to MongoDB - TODO From ea4e435c3d75ac99cde9ce4b9f0f63c030921b8e Mon Sep 17 00:00:00 2001 From: Curtis Kelsey Date: Sat, 27 Feb 2016 17:52:58 -0600 Subject: [PATCH 3/4] First draft. --- doc/book/writers.md | 223 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 202 insertions(+), 21 deletions(-) diff --git a/doc/book/writers.md b/doc/book/writers.md index 3eae21ac..e1cbcffc 100644 --- a/doc/book/writers.md +++ b/doc/book/writers.md @@ -164,59 +164,240 @@ $ composer require ccampbell/chromephp ## Writing to Mail -`Zend\Log\Writer\Mail` requires a configuration array or `Zend\Mail\Message`. The configuration array accepts: +`Zend\Log\Writer\Mail` takes a configuration array or `Zend\Mail\Message`. Basic usage looks like + +```php +$message = new \Zend\Mail\Message(); +$message->setTo('email@example.com'); + +$writer = new \Zend\Log\Writer\Mail($message); +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); + +// goes to mail message +$logger->info('Informational message'); +``` + +An email of the logged information will be sent via `sendmail` by default. You may also provide a `Zend\Mail\Transport` +during construction. For configuration options checkout the `Zend\Mail\Transport` documentation. + +```php +$writer = new Zend\Log\Writer\Mail($mail, $transport); +``` + +`Zend\Log\Writer\mail` may also be constructed with a configuration array. The configuration array accepts the following +keys: ```php [ 'subject_prepend_text' => '', - 'transport' => Transport\TransportInterface - 'mail' => MailMessage | array + 'transport' => $transport + 'mail' => $mail, + 'filters' => [], + 'formatter' => [] ] ``` +And expects the following data: + Array Index | Accepted Values | Description ----------- | --------------- | ----------- `subject_prepend_text` | string | Mail message -`transport` | `Transport\TransportInterface` | -`mail` | `Zend\Mail\Message` | - | array | `Zend\Mail\Message` factory array +`transport` | `Transport\TransportInterface` | Transport method +`mail` | `Zend\Mail\Message` | mail message +`mail` | `array` | `Zend\Mail\Message` factory array +`filters` | array, int, string, Zend\Log\Filter\FilterInterface | Log filter(s) +`formatter` | array, string, Zend\Log\Formatter\FormatterInterface | Log formatter(s) -By default `sendmail` is used to send mail messages. +Basic usage of the configuration array looks like: ```php -$writer = new Zend\Log\Writer\Mail($mail); +$transport = new \Zend\Mail\Transport\Smtp(); +// TODO configure the SMTP transport + +$message = new \Zend\Mail\Message(); +// TODO configure the Mail message + +$writer = new \Zend\Log\Writer\Mail( + [ + 'subject_prepend_text' => 'Start of the subject', + 'transport' => $transport, + 'mail' => $mail, + 'filters' => [], + 'formatter' => [] + ] +); + +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); -$logger = new Zend\Log\Logger(); +// goes to mail message +$logger->info('Informational message'); +``` + +To use the `Zend\Mail\Message` factory array construction will look like: + +```php +$transport = new \Zend\Mail\Transport\Smtp(); +// TODO configure the SMTP transport + +$writer = new \Zend\Log\Writer\Mail( + [ + 'subject_prepend_text' => 'Start of the subject', + 'transport' => $transport, + 'mail' => [ + 'to' => 'email@example.com' + ], + 'filters' => [], + 'formatter' => [] + ] +); + +$logger = new \Zend\Log\Logger(); $logger->addWriter($writer); +// goes to mail message $logger->info('Informational message'); ``` -You can provide a Transport configuration during construction. +## Writing to MongoDB + +In this example `Zend\Log\Writer\MongoDB` uses an array for construction. Available keys include: ```php -$writer = new Zend\Log\Writer\Mail($mail, $transport); +[ + 'save_options' => [], + 'collection' => '', + 'database' => '', + 'mongo' => $mongo, + 'filters' => [], + 'formatter' => [] +] ``` -Mail transports available include: -- Sendmail -- SMTP -- File -- In Memory +`collection`, `database`, and `mongo` are required. Each key accepts: + +Array Index | Accepted Values | Description +----------- | --------------- | ----------- +`save_options` | array | MongoDB driver options +`collection` | string | collection name +`database` | string | database name +`mongo` | `Mongo` or `MongoClient` | MongoDB connection object +`filters` | array, int, string, Zend\Log\Filter\FilterInterface | Log filter(s) +`formatter` | array, string, Zend\Log\Formatter\FormatterInterface | Log formatter(s) + +And `Zend\Log\Writer\MongoDB` is used like this: -For configuration options checkout the `Zend\Mail\Transport` documentation. +```php +$mongo = new MongoClient(); + +$writer = new \Zend\Log\Writer\MongoDB( + [ + 'save_options' => [], //MongoDB Driver Options + 'collection' => 'collectionName', + 'database' => 'databaseName', + 'mongo' => $mongo, + 'filters' => [], + 'formatter' => [] + ] +); + +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); -## Writing to MongoDB +// goes to Mongo DB +$logger->info('Informational message'); +``` + +It may also be constructed by passing the arguments directly + +```php +$mongo = new MongoClient(); +$database = 'databaseName'; +$collection = 'collectionName'; +$saveOptions = []; + +$writer = new \Zend\Log\Writer\MongoDB($mongo, $database, $collection, $saveOptions); +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); -- TODO +// goes to Mongo DB +$logger->info('Informational message'); +``` ## Writing to Syslog -- TODO +`Zend\Log\Writer\Syslog` is a writer generates system log messages from the data it receives. + +```php +$writer = new \Zend\Log\Writer\Syslog(); +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); + +// goes to system log +$logger->info('Informational message'); +``` + +The application name and syslog facility may be set + +Array Index | Accepted Values | Description +----------- | --------------- | ----------- +`application` | string | application name +`facility` | string | syslog facility (list of facilities)[http://php.net/openlog] +`filters` | array, int, string, Zend\Log\Filter\FilterInterface | Log filter(s) +`formatter` | array, string, Zend\Log\Formatter\FormatterInterface | Log formatter(s) + +```php +$writer = new \Zend\Log\Writer\Syslog( + [ + 'application' => '', + 'facility' => '', + 'filters' => [], + 'formatter' => [] + ] +); + +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); + +$logger->info('Informational message'); +``` ## Writing to Zend Monitor -- TODO +`Zend\Log\Writer\ZendMonitor` writes log data to the Zend Monitor on a Zend Server. If the web server is not a Zend +Server or Zend Monitor is not enabled it will fail silently. + +```php +$writer = new \Zend\Log\Writer\ZendMonitor(); +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); + +// goes to Zend Monitor +$logger->info('Informational message'); +``` + +`Zend\Log\Writer\AbstractWriter` options are available. + +Array Index | Accepted Values | Description +----------- | --------------- | ----------- +`filters` | array, int, string, Zend\Log\Filter\FilterInterface | Log filter(s) +`formatter` | array, string, Zend\Log\Formatter\FormatterInterface | Log formatter(s) + +```php +$writer = new \Zend\Log\Writer\ZendMonitor( + [ + 'filters' => [], + 'formatter' => [] + ] +); + +$logger = new \Zend\Log\Logger(); +$logger->addWriter($writer); + +// goes to Zend Monitor +$logger->info('Informational message'); +``` ## Stubbing Out the Writer From a110a8f3c981c11d121a8b3f86885be6de5fe4c3 Mon Sep 17 00:00:00 2001 From: Curtis Kelsey Date: Sat, 27 Feb 2016 18:00:52 -0600 Subject: [PATCH 4/4] Adjusted code style. --- doc/book/writers.md | 100 ++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/doc/book/writers.md b/doc/book/writers.md index e1cbcffc..fa5be6a5 100644 --- a/doc/book/writers.md +++ b/doc/book/writers.md @@ -39,7 +39,7 @@ The constructor of `Zend\Log\Writer\Stream` also accepts an existing stream reso ```php $stream = @fopen('/path/to/logfile', 'a', false); if (! $stream) { -throw new Exception('Failed to open stream'); + throw new Exception('Failed to open stream'); } $writer = new Zend\Log\Writer\Stream($stream); @@ -57,7 +57,7 @@ constructing a `Stream` instance; when doing so, the `stream` key is required: ```php $writer = new Zend\Log\Writer\Stream([ -'stream' => 'php://output', + 'stream' => 'php://output', ]); $logger = new Zend\Log\Logger(); $logger->addWriter($writer); @@ -85,9 +85,9 @@ separator for the log array: ```php $dbconfig = [ -// Sqlite Configuration -'driver' => 'Pdo', -'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', + // Sqlite Configuration + 'driver' => 'Pdo', + 'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', ]; $db = new Zend\Db\Adapter\Adapter($dbconfig); @@ -107,16 +107,16 @@ store only to the selected fields in the database: ```php $dbconfig = [ -// Sqlite Configuration -'driver' => 'Pdo', -'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', + // Sqlite Configuration + 'driver' => 'Pdo', + 'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', ]; $db = new Zend\Db\Adapter\Adapter($dbconfig); $mapping = [ -'timestamp' => 'date', -'priority' => 'type', -'message' => 'event', + 'timestamp' => 'date', + 'priority' => 'type', + 'message' => 'event', ]; $writer = new Zend\Log\Writer\Db($db, 'log_table_name', $mapping); $logger = new Zend\Log\Logger(); @@ -218,15 +218,13 @@ $transport = new \Zend\Mail\Transport\Smtp(); $message = new \Zend\Mail\Message(); // TODO configure the Mail message -$writer = new \Zend\Log\Writer\Mail( - [ - 'subject_prepend_text' => 'Start of the subject', - 'transport' => $transport, - 'mail' => $mail, - 'filters' => [], - 'formatter' => [] - ] -); +$writer = new \Zend\Log\Writer\Mail([ + 'subject_prepend_text' => 'Start of the subject', + 'transport' => $transport, + 'mail' => $mail, + 'filters' => [], + 'formatter' => [] +]); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); @@ -241,17 +239,15 @@ To use the `Zend\Mail\Message` factory array construction will look like: $transport = new \Zend\Mail\Transport\Smtp(); // TODO configure the SMTP transport -$writer = new \Zend\Log\Writer\Mail( - [ - 'subject_prepend_text' => 'Start of the subject', - 'transport' => $transport, - 'mail' => [ - 'to' => 'email@example.com' - ], - 'filters' => [], - 'formatter' => [] - ] -); +$writer = new \Zend\Log\Writer\Mail([ + 'subject_prepend_text' => 'Start of the subject', + 'transport' => $transport, + 'mail' => [ + 'to' => 'email@example.com' + ], + 'filters' => [], + 'formatter' => [] +]); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); @@ -291,16 +287,14 @@ And `Zend\Log\Writer\MongoDB` is used like this: ```php $mongo = new MongoClient(); -$writer = new \Zend\Log\Writer\MongoDB( - [ - 'save_options' => [], //MongoDB Driver Options - 'collection' => 'collectionName', - 'database' => 'databaseName', - 'mongo' => $mongo, - 'filters' => [], - 'formatter' => [] - ] -); +$writer = new \Zend\Log\Writer\MongoDB([ + 'save_options' => [], //MongoDB Driver Options + 'collection' => 'collectionName', + 'database' => 'databaseName', + 'mongo' => $mongo, + 'filters' => [], + 'formatter' => [] +]); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); @@ -348,14 +342,12 @@ Array Index | Accepted Values | Description `formatter` | array, string, Zend\Log\Formatter\FormatterInterface | Log formatter(s) ```php -$writer = new \Zend\Log\Writer\Syslog( - [ - 'application' => '', - 'facility' => '', - 'filters' => [], - 'formatter' => [] - ] -); +$writer = new \Zend\Log\Writer\Syslog([ + 'application' => '', + 'facility' => '', + 'filters' => [], + 'formatter' => [] +]); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); @@ -385,12 +377,10 @@ Array Index | Accepted Values | Description `formatter` | array, string, Zend\Log\Formatter\FormatterInterface | Log formatter(s) ```php -$writer = new \Zend\Log\Writer\ZendMonitor( - [ - 'filters' => [], - 'formatter' => [] - ] -); +$writer = new \Zend\Log\Writer\ZendMonitor([ + 'filters' => [], + 'formatter' => [] +]); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer);