Skip to content

Commit 86da58d

Browse files
committed
initial commit
0 parents  commit 86da58d

19 files changed

+4936
-0
lines changed

.codebeatignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/test/**

.codebeatsettings

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"TYPESCRIPT": {
3+
"TOTAL_LOC": [500, 1000, 1500, 2000],
4+
"TOO_MANY_FUNCTIONS": [40, 50, 60, 70],
5+
"TOTAL_COMPLEXITY": [100, 180, 280, 400]
6+
}
7+
}

.gitignore

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
npm-debug.log*
2+
yarn-debug.log*
3+
yarn-error.log*
4+
.yarn-integrity
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
*.pid.lock
11+
12+
.lock-wscript
13+
14+
.ssh/
15+
dist/
16+
tmp/
17+
out-tsc/
18+
build/
19+
.nyc_output/
20+
node_modules/
21+
.idea/
22+
.project
23+
.classpath
24+
.c9/
25+
*.launch
26+
.settings/
27+
*.sublime-workspace
28+
.vscode/*
29+
.sass-cache/
30+
connect.lock/
31+
coverage/
32+
typings/
33+
docs/
34+
debug*
35+
*.txt
36+
*.js
37+
*.d.ts
38+
*.js.map
39+
*.log
40+
*.swp
41+
*.tgz
42+
.env
43+
.eslintrc
44+
.editorconfig
45+
.gitlab-ci.yml
46+
.DS_Store
47+
Thumbs.db

.npmignore

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.gitignore
2+
.travis.yml
3+
.dockerignore
4+
.ssh/
5+
.nyc_output/
6+
.idea/
7+
.project
8+
.classpath
9+
.c9/
10+
.settings/
11+
.vscode/
12+
.sass-cache/
13+
node_modules/
14+
dist/
15+
tmp/
16+
out-tsc/
17+
build/
18+
connect.lock/
19+
coverage/
20+
typings/
21+
docs/
22+
wiki/
23+
test/
24+
debug*
25+
*.sublime-workspace
26+
*.launch
27+
*.pid
28+
*.log
29+
*.js.map
30+
*.ts
31+
*.tgz
32+
!*.d.ts
33+
debug*.d.ts
34+
.DS_Store
35+
.env
36+
.eslintrc
37+
.editorconfig
38+
.gitlab-ci.yml
39+
Dockerfile
40+
Thumbs.db
41+
tsconfig.json
42+
tslint.json
43+
.codebeatsettings
44+
.codebeatignore
45+
bin/
46+
.git/
47+
examples/

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist: xenial
2+
language: node_js
3+
node_js:
4+
- lts/*

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2018, imqueue.com <[email protected]>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose
4+
with or without fee is hereby granted, provided that the above copyright notice
5+
and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13+
PERFORMANCE OF THIS SOFTWARE.

README.md

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# @imqueue/async-logger
2+
3+
Configurable async logger over winston for @imqueue services.
4+
5+
## Install
6+
7+
~~~bash
8+
npm i --save @imqueue/async-logger
9+
~~~
10+
11+
## Usage
12+
13+
There are two actual ways of using async logger.
14+
15+
1. Rely on singleton instance produced by this library, which is configured by
16+
environment variables (see Configuration section below)
17+
18+
In this case as simple as
19+
~~~typescript
20+
import logger from '@imqueue/async-async-logger';
21+
22+
serviceOptions.logger = logger;
23+
~~~
24+
25+
2. Instantiate and configure async logger programmatically:
26+
~~~typescript
27+
import { Logger } from '@imqueue/async-async-logger';
28+
29+
const { name, version } = require('./package.json');
30+
31+
const logger = new Logger({
32+
transports: [{
33+
type: 'http',
34+
options: {
35+
ssl: true,
36+
port: 443,
37+
path: '/v1/input/<YOUR_API_KEY>',
38+
host: 'http-intake.logs.datadoghq.com',
39+
headers: {
40+
'Content-Type': 'application/json',
41+
},
42+
},
43+
enabled: true,
44+
}],
45+
metadata: {
46+
ddsource: `${ name } ${ version }`,
47+
ddtags: 'env: dev',
48+
hostname: 'localhost'
49+
},
50+
});
51+
52+
serviceOptions.logger = logger;
53+
~~~
54+
55+
## Configuration
56+
57+
Logger can be configured via environment variables. It can be easily integrated
58+
with any remote services. Here we will example configuration based on assumption
59+
to connect with Datadog remote service.
60+
61+
So, basically there are two basic configuration options available:
62+
63+
~~~bash
64+
export LOGGER_TRANSPORTS='[]'
65+
export LOGGER_METADATA='{}'
66+
~~~
67+
68+
Both of them are simply JSON strings referring to replicate corresponding
69+
winston logger settings. Both of them can accept string tags `%name`, `%version`
70+
for dynamic setting of these values from a current service package, if needed.
71+
72+
1. To configure HTTP transport follow to pass such object to `LOGGER_TRANSPORTS`
73+
array:
74+
75+
~~~json
76+
{
77+
"type": string,
78+
"options": {
79+
"ssl": boolean,
80+
"port": number,
81+
"path": string,
82+
"host": string,
83+
"headers": object
84+
},
85+
"enabled": boolean
86+
}
87+
~~~
88+
89+
2. To configure File transport
90+
91+
~~~json
92+
{
93+
"type": string,
94+
"options": {
95+
"filename": string,
96+
"dirname": string,
97+
"options": object,
98+
"maxsize": number,
99+
"zippedArchive": boolean,
100+
"maxFiles": number,
101+
"eol": string,
102+
"tailable": boolean
103+
},
104+
"enabled": boolean
105+
}
106+
~~~
107+
108+
EXAMPLE FOR DATADOG:
109+
110+
~~~bash
111+
export LOGGER_TRANSPORTS='[{"type":"http","options":{"ssl":true,"port":443,"path":"/v1/input/[DATADOG_API_KEY]","host":"http-intake.logs.datadoghq.com","headers":{"Content-Type":"application/json"}}, "enabled": true }]'
112+
~~~
113+
114+
where DATADOG_API_KEY should be replaced with an actual API key.
115+
116+
3. To configure metadata consider the following `LOGGER_METADATA` object:
117+
118+
~~~json
119+
{
120+
"ddsource": string,
121+
"ddtags": string,
122+
"hostname": string
123+
}
124+
~~~
125+
126+
EXAMPLE FOR DATADOG:
127+
128+
~~~bash
129+
export LOGGER_METADATA='{"ddsource":"%name %version","ddtags":"env: dev","hostname":"localhost"}'
130+
~~~
131+
132+
### Lets See It Human-Readable:
133+
134+
~~~bash
135+
# example of transports config
136+
export LOGGER_TRANSPORTS='[{
137+
"type": "http",
138+
"options": {
139+
"ssl": true,
140+
"port": 443,
141+
"path": "/v1/input/<YOUR_API_KEY>",
142+
"host": "http-intake.logs.datadoghq.com",
143+
"headers": {
144+
"Content-Type": "application/json"
145+
}
146+
},
147+
"enabled": true
148+
}, {
149+
"type": "file",
150+
"options": {
151+
"filename": "logs.log",
152+
"dirname": "/home/usr/logs",
153+
"options": object,
154+
"zippedArchive": false,
155+
}
156+
"enabled": true
157+
}]'
158+
# example of metadata for datadog
159+
export LOGGER_METADATA='{
160+
"ddsource": "%name %version",
161+
"ddtags": "env: dev",
162+
"hostname": "localhost"
163+
}';
164+
~~~
165+
166+
## Contributing
167+
168+
Any contributions are greatly appreciated. Feel free to fork, propose PRs, open
169+
issues, do whatever you think may be helpful to this project. PRs which passes
170+
all tests and do not brake tslint rules are first-class candidates to be
171+
accepted!
172+
173+
## License
174+
175+
[ISC](https://github.com/imqueue/pg-pubsub/blob/master/LICENSE)
176+
177+
Happy Coding!

index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*!
2+
* Copyright (c) 2018, imqueue.com <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14+
* PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
import { Logger } from './src';
17+
18+
export * from './src';
19+
20+
// noinspection JSUnusedGlobalSymbols
21+
export default new Logger();

0 commit comments

Comments
 (0)