loglevel-datadog 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/loglevel-datadog.d.ts +3 -0
- package/dist/loglevel-datadog.js +25 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Kevin Brey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# loglevel-datadog
|
|
2
|
+
|
|
3
|
+
Send loglevel logs from the browser to Datadog via the [datadog browser logs SDK](https://github.com/DataDog/browser-sdk/tree/main/packages/logs#browser-log-collection).
|
|
4
|
+
|
|
5
|
+
`loglevel` + `@datadog/browser-logs`
|
|
6
|
+
|
|
7
|
+
Note that adding plugins to loglevel [**will show log output line numbers as coming from inside the plugin**](https://github.com/pimterry/loglevel#writing-plugins).
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import log from 'loglevel';
|
|
13
|
+
import { loglevelDatadog } from 'loglevel-datadog';
|
|
14
|
+
|
|
15
|
+
loglevelDatadog(log, {
|
|
16
|
+
clientToken: '<DATADOG_CLIENT_TOKEN>',
|
|
17
|
+
site: '<DATADOG_SITE>',
|
|
18
|
+
forwardErrorsToLogs: true,
|
|
19
|
+
sampleRate: 100,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
log.warn('hello datadog');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
`loglevelDatadog` uses the same configuration interface as `@datadog/browser-logs`. See the [datadog initialization parameters](https://github.com/DataDog/browser-sdk/tree/main/packages/logs#initialization-parameters) for more details.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loglevelDatadog } from './loglevel-datadog';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loglevelDatadog } from './loglevel-datadog';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LogLevelNumbers, RootLogger } from 'loglevel';
|
|
2
|
+
import { LogsInitConfiguration, StatusType } from '@datadog/browser-logs';
|
|
3
|
+
export declare function loglevelDatadog(logger: RootLogger, datadogConfiguration: LogsInitConfiguration, statusTypesMap?: Record<LogLevelNumbers, StatusType>): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { datadogLogs, } from '@datadog/browser-logs';
|
|
2
|
+
const STATUS_TYPE = {
|
|
3
|
+
0: 'debug',
|
|
4
|
+
1: 'debug',
|
|
5
|
+
2: 'error',
|
|
6
|
+
3: 'info',
|
|
7
|
+
4: 'warn',
|
|
8
|
+
5: 'debug',
|
|
9
|
+
};
|
|
10
|
+
export function loglevelDatadog(logger, datadogConfiguration, statusTypesMap = STATUS_TYPE) {
|
|
11
|
+
datadogLogs.init(datadogConfiguration);
|
|
12
|
+
const { methodFactory } = logger;
|
|
13
|
+
logger.methodFactory = (methodName, level, loggerName) => {
|
|
14
|
+
const rawMethod = methodFactory(methodName, level, loggerName);
|
|
15
|
+
return (...messages) => {
|
|
16
|
+
const message = messages
|
|
17
|
+
.map((m) => (typeof m === 'string' ? m : JSON.stringify(m)))
|
|
18
|
+
.join(' ');
|
|
19
|
+
datadogLogs.logger.log(message, {}, statusTypesMap[level]);
|
|
20
|
+
// TODO: Remove this line from traces
|
|
21
|
+
rawMethod(...messages);
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
logger.setLevel(logger.getLevel());
|
|
25
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "loglevel-datadog",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "loglevel plugin to send logs from the browser to Datadog via the datadog browser logs SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
+
"prepublish": "npm run build",
|
|
14
|
+
"prepare": "husky install",
|
|
15
|
+
"semantic-release": "semantic-release"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/manbearwiz/loglevel-datadog.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"browser",
|
|
23
|
+
"datadog",
|
|
24
|
+
"error",
|
|
25
|
+
"log",
|
|
26
|
+
"logger",
|
|
27
|
+
"logging",
|
|
28
|
+
"loglevel-plugin",
|
|
29
|
+
"loglevel",
|
|
30
|
+
"logs",
|
|
31
|
+
"plugin",
|
|
32
|
+
"typescript"
|
|
33
|
+
],
|
|
34
|
+
"author": "Kevin Brey",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/manbearwiz/loglevel-datadog/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/manbearwiz/loglevel-datadog#readme",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@datadog/browser-logs": "^3.8.0",
|
|
42
|
+
"loglevel": "^1.8.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
46
|
+
"@types/node": "^16.7.13",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
48
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
49
|
+
"eslint": "^7.32.0",
|
|
50
|
+
"eslint-config-prettier": "^8.3.0",
|
|
51
|
+
"eslint-plugin-import": "^2.25.3",
|
|
52
|
+
"husky": "^7.0.4",
|
|
53
|
+
"lint-staged": "^11.2.6",
|
|
54
|
+
"prettier": "2.4.0",
|
|
55
|
+
"typescript": "^4.4.2",
|
|
56
|
+
"semantic-release": "^18.0.1"
|
|
57
|
+
},
|
|
58
|
+
"lint-staged": {
|
|
59
|
+
"*.js": "eslint --cache --fix",
|
|
60
|
+
"*.{js,css,md}": "prettier --write"
|
|
61
|
+
},
|
|
62
|
+
"release": {
|
|
63
|
+
"branches": [
|
|
64
|
+
"main"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
}
|