Skip to content

Commit 17797c9

Browse files
committed
docs: add oficial docs
1 parent b7e78b5 commit 17797c9

File tree

1 file changed

+162
-1
lines changed

1 file changed

+162
-1
lines changed

README.md

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,163 @@
11
# Cloud Pine
2-
Pino Transport abstraction for Google Cloud Logging.
2+
3+
Pino Transport that abstracts Google Cloud Logging implementation underneath.
4+
5+
## Description
6+
7+
This library executes a thin abstraction of the [`@google-cloud/logging`](https://cloud.google.com/nodejs/docs/reference/logging/latest) client library.
8+
The goal is to provide a clean support over Google Cloud Logging service for the Pino ecosystem using the Transport feature of Pino itself.
9+
10+
### Usage
11+
12+
#### How to use it?
13+
14+
The library can be used either by piping logs using the `pipe` operator on Linux, or programatically by installing it as part of your dependencies in you project.
15+
16+
**Within your Dependencies**
17+
18+
Using it programatically, is easy as just install the library as part for your dependencies in any of the following ways:
19+
20+
- **npm**: `npm install cloud-pine`
21+
22+
- **yarn**: `yarn add cloud-pine`
23+
24+
- **pnpm**: `pnpm install cloud-pine`
25+
26+
Once installed, is necessary to set it up as part of of your Pino transport configuration, an example can be:
27+
28+
```js
29+
const Pino = require('pino')
30+
const logger = Pino({
31+
transport: {
32+
target: 'cloud-pine',
33+
options: {
34+
cloudLoggingOptions: {
35+
skipInit: true,
36+
sync: true,
37+
}
38+
}
39+
}
40+
})
41+
42+
43+
logger.info('hello world')
44+
logger.error({ oops: 'hello!' }, 'error')
45+
```
46+
47+
or in **TypeScript**
48+
49+
```ts
50+
import Pino from ('pino')
51+
52+
const logger = Pino({
53+
transport: {
54+
target: 'cloud-pine',
55+
options: {
56+
cloudLoggingOptions: {
57+
skipInit: true,
58+
sync: true,
59+
}
60+
}
61+
}
62+
})
63+
64+
65+
logger.info('hello world')
66+
logger.error({ oops: 'hello!' }, 'error')
67+
```
68+
69+
**Configuration**
70+
`Cloud-Pine` supports the following configuration:
71+
72+
```js
73+
const cloudPine = {
74+
logName: 'cloud-pine', // Name of the logging agent. Default to 'cloud-pine'
75+
cloudLoggingOptions: {
76+
googleCloudOptions: {}, // Configuration Object for establishing connection with Google Cloud Logging. Default to undefined. Ref: https://cloud.google.com/nodejs/docs/reference/logging/latest/logging/loggingoptions
77+
78+
resourceSettings: {}, // Resource settings hash, default to `{ type: 'global' }`. The hash is persisted across logs and inferred based on the API `Logging#setDetectedResource` result. Ref: https://cloud.google.com/logging/docs/reference/v2/rest/v2/MonitoredResource
79+
80+
defaultLabels: {}, // Labels hash, default to `{ logger: 'pino', agent: 'cloud_pine' }`. The hash is persisted across logs. Ref: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry,
81+
82+
logOptions: {}, // Configuration object that is passed to the Log/LogSync instance. Default to undefined. Ref: https://cloud.google.com/nodejs/docs/reference/logging/latest/logging/log and https://cloud.google.com/nodejs/docs/reference/logging/latest/logging/logsync
83+
84+
skipInit: false, // Indicates wheter to skip the automatic inferr of `projectId` and `MonitoredResource` metadata. Default to `false`.
85+
86+
sync: false, // Indicates wheter to use a Log or LogSync instance. Default to false.
87+
}
88+
}
89+
```
90+
91+
>For more information about the `sync` and `async` diference, please take a look at the section [Sync or Async](#syncorasync)
92+
93+
**CLI**
94+
95+
When using it in CLI mode, all the logs are ingested automatically from `stdin`. In case exists some malformed log, the library will automatically dispatch an log with severity to `error` to Google Cloud Logging.
96+
97+
**Usage**
98+
99+
See the following description for usage:
100+
```
101+
Usage: cat log | cloud-pine --projectid someprojectid -l something=else -l service=http
102+
103+
Flags
104+
-h | --help Display Help
105+
106+
-v | --version Display Version
107+
108+
-n | --name Log Name. Default to Cloud_Pine
109+
110+
-s | --sync Cloud Logging Mode. Sync will print to `stdout`
111+
meanwhile async will forward logs to Cloud Logging.
112+
Default to true.
113+
114+
-p | --projectid Google Cloud Project ID. Default to automatic
115+
detected resource or
116+
`GOOGLE_APPLICATION_CREDENTIALS`
117+
118+
-k | --key Path to key file
119+
120+
-l | --labels Custom labels to be attached to the logging labels.
121+
Should be in the format `label=value`.
122+
Can be used one or more times.
123+
124+
-r | --resource Monitoring Resource type. Default to `type=global`
125+
or Monitored Resource detected.
126+
127+
-rs | --resource-labels Monitoring Resource#Labels that will be attached
128+
to the resource by default.
129+
Follows same pattern as `--labels`.
130+
131+
-i | --skip-init Skips identification of monitored resource, which
132+
will infer things like `project-id` and Monitored
133+
Resource settings. Default to false.
134+
```
135+
136+
**TypeScript Interface**
137+
138+
```ts
139+
type CloudPineOptions = {
140+
logName?: string;
141+
cloudLoggingOptions: {
142+
googleCloudOptions?: LoggingOptions;
143+
resourceSettings?: {
144+
type?: string;
145+
labels: Record<string, string>;
146+
};
147+
defaultLabels?: Record<string, string>;
148+
skipInit?: boolean;
149+
sync?: boolean;
150+
logOptions?: ConstructorParameters<typeof Log> | ConstructorParameters<typeof LogSync>;
151+
};
152+
```
153+
154+
### Sync or Async
155+
<a id="syncorasync"></a>
156+
157+
The library can be used in either of two modes, `sync` or `async`.
158+
159+
The default mode for the CLI usage is `sync` meaning that all logs will be directly streamed to `stdout`, meanwhile the default mode for the Transport usage is `async`, where all the logs will be streamed directly to Google Cloud Logging service.
160+
161+
>For more information about when to use one or another please take a look at the following documentation: [**Writting to `stdout**](https://cloud.google.com/nodejs/docs/reference/logging/latest#writing-to-stdout).
162+
163+

0 commit comments

Comments
 (0)