Skip to content

Commit

Permalink
docs update.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Nov 22, 2015
1 parent 20250eb commit 3377bcc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
70 changes: 45 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Event monitor for [pg-promise].

# About

This library takes the flexible event system provided by [pg-promise],
This library takes the flexible event system provided by [pg-promise]
and outputs it on screen, with full details available, and in the most informative way.

It is to give you the full picture of how the database is used in your application,
providing full details with the context, such as tasks and transactions, in which
Its purpose is to give you the full picture of how the database is used in your application,
providing full details with the context, such as tasks and transactions in which
queries are executed.

In addition, it simplifies [event logging](#log) for your application.
Expand Down Expand Up @@ -70,11 +70,11 @@ monitor.attach(options); // attach to all events at once;
Method [attach](#attachoptions-events-override) is to provide the quickest way to start using the library,
by attaching to a set of events automatically.

If, however, you want to have full control over event handling, then use the manual event forwarding instead.
If, however, you want to have full control over event handling, you can use the manual event forwarding.

Example of forwarding events [query](https://github.com/vitaly-t/pg-promise#query) and [error](https://github.com/vitaly-t/pg-promise#error) manually:

```javascript
```js
var options = {
query: function (e) {
/* do some of your own processing, if needed */
Expand All @@ -93,14 +93,14 @@ See the API below for all the methods and options that you have.

# API

## attach(options, [events, override])
## attach(options, [events], [override])

Adds event handlers to object `options` that's used when [initializing pg-promise](https://github.com/vitaly-t/pg-promise#2-initializing) library:
```javascript
var pgp = pgpLib(options);
```

#### events
#### [events]

Optional array of event names to which to attach. Passing `null`/`undefined` will attach
to all known events.
Expand All @@ -113,84 +113,102 @@ monitor.attach(options, ['query', 'error']);
Query-related events supported by pg-promise: `connect`, `disconnect`, `query`, `task`, `transact` and `error`.
See [Initialization Options](https://github.com/vitaly-t/pg-promise#initialization-options).

#### override
#### [override]

By default, the method uses derivation logic - it will call the previously configured
event handler, if you have one, and only then it will call the internal implementation.

If, however, you want to override your own handlers, pass `override` = `true`.

Example of overriding all known event handlers:

```javascript
monitor.attach(options, null, true);
```

## connect(client, [detailed])

Monitors and reports event [connect](https://github.com/vitaly-t/pg-promise#connect).

#### client

Connection object passed to the event.

#### detailed
#### [detailed]

Optional. When set, it reports such connection details as user@database.

When not set, it defaults to the value of [monitor.detailed].

## disconnect(client, [detailed])

Monitors and reports event [disconnect](https://github.com/vitaly-t/pg-promise#disconnect).

#### client

Connection object passed to the event.

#### detailed
#### [detailed]

Optional. When set, it reports such connection details as user@database.

When not set, it defaults to the value of [monitor.detailed].

## query(e, [detailed])

Monitors and reports event [query](https://github.com/vitaly-t/pg-promise#query).

#### e

Context object passed to the event.

#### detailed
#### [detailed]

Optional. When set, it reports details of the task/transaction context in which the query is executing.

When not set, it defaults to the value of [monitor.detailed].

## task(e)

Monitors and reports event [task](https://github.com/vitaly-t/pg-promise#task).

#### e

Context object passed to the event.

## transact(e)

Monitors and reports event [transact](https://github.com/vitaly-t/pg-promise#transact).

#### e

Context object passed to the event.

## error(err, e, [detailed])

Monitors and reports event [error](https://github.com/vitaly-t/pg-promise#error).

#### err

Error message passed to the event.

#### e

Error context passed to the event.

#### detailed
#### [detailed]

Optional. When set, it reports details of the task/transaction context in which the error occurred.

When not set, it defaults to the value of [monitor.detailed].

## detailed

This boolean property provides the default for every method that accepts parameter `detailed`.
This boolean property provides the default for every method that accepts optional parameter `detailed`.

By default, it is set to be `true`. Setting this parameter to `false` will automatically
switch off all details in events that support optional details, unless they have their own
parameter `detailed` set to be `true`, which then overrides this global one.
parameter `detailed` passed in as `true`, which then overrides this global one.

## setTheme(t)

Expand All @@ -204,19 +222,19 @@ For details, see [Color Themes](https://github.com/vitaly-t/pg-monitor/wiki/Colo

## log

This optional event is to let your application save everything that appears on screen
into your log file:
This event is to let your application provide your own log for everything that appears on the screen.

```javascript
monitor.log = function(msg, info){
// save the screen message into your own log file;
// save the screen message into your own log;
};
```

The notification occurs for every single line of text that appears on the screen, so you can
maintain a log file with exactly the same content.

#### msg

New message line, exactly as shown on the screen, with color attributes removed.

#### info
Expand All @@ -225,11 +243,12 @@ Object with additional information about the event:

* `time` - Date object that was used for the screen, or `null` when it is an extra line with
the event's context details;
* `text` - message text without the time in front of it (color attributes removed);
* `text` - message text without the time in front (color attributes removed);
* `event` - name of the event being logged.

If your intent is only to log events, while suppressing any screen output, you can
do so on per-event basis, as shown below:

```js
info.display = false; // suppress screen output for the event;
```
Expand All @@ -247,7 +266,8 @@ If your application uses more than one task or transaction, it is a good idea to
so they provide informative context for every query event that's being logged, i.e.
so your can easily see in which task/transaction context queries are executed.

Tagging a task or transaction with [pg-promise] is very easy, by taking this code:
Tagging a task or transaction with [pg-promise] is very easy, by taking this code:

```javascript
db.task(function (t) {
// task queries;
Expand All @@ -271,15 +291,15 @@ a string that represents the task/transaction name, like this:
db.task("MyTask", function (t) {
// task queries;
});
db.tx("TX-1", function (t) {
db.tx("MyTransaction", function (t) {
// transaction queries;
});
```
But `tag` can be anything, including an object, so you can use it for your own reference
when handling events. And if you want to use it that way, while also allowing this library
to log the task/transaction pseudo-name/alias, then make sure your tag object implements its
own function `toString()` to return such name, which this library will then call to report
the name along with the task/transaction.

The `tag` can be anything, including your custom object, so you can use it for your own reference
when handling events. And if you want to use it as your own object, while also allowing this library
to log the task/transaction pseudo-name/alias, then have your object implement method `toString()`
that returns the tag name.

[pg-promise]:https://github.com/vitaly-t/pg-promise
[monitor.detailed]:https://github.com/vitaly-t/pg-monitor#detailed-4
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-monitor",
"version": "0.3.11",
"version": "0.4.0",
"description": "Event monitor for pg-promise.",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 3377bcc

Please sign in to comment.