@libp2p/logger 0.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 ADDED
@@ -0,0 +1,4 @@
1
+ This project is dual licensed under MIT and Apache-2.0.
2
+
3
+ MIT: https://www.opensource.org/licenses/mit
4
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # libp2p-logger <!-- omit in toc -->
2
+
3
+ > A logging component for use in js-libp2p components
4
+
5
+ ## Table of Contents <!-- omit in toc -->
6
+
7
+ - [Description](#description)
8
+ - [Installation](#installation)
9
+ - [Example](#example)
10
+ - [License](#license)
11
+ - [Contribution](#contribution)
12
+
13
+ ## Description
14
+
15
+ A map that reports it's size to the libp2p [Metrics](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/metrics#readme) system.
16
+
17
+ If metrics are disabled a regular map is used.
18
+
19
+ ## Installation
20
+
21
+ ```console
22
+ $ npm i @libp2p/logger
23
+ ```
24
+
25
+ ## Example
26
+
27
+ ```JavaScript
28
+ import { logger } from '@libp2p/logger'
29
+
30
+ const log = logger('libp2p:my:component:name')
31
+
32
+ log('something happened: %s', 'it was ok')
33
+ log.error('something bad happened: %o', err)
34
+ ```
35
+
36
+ ```console
37
+ $ DEBUG=libp2p:* node index.js
38
+ something happened: it was ok
39
+ something bad happened: <stack trace>
40
+ ```
41
+
42
+ ## License
43
+
44
+ Licensed under either of
45
+
46
+ * Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
47
+ * MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
48
+
49
+ ### Contribution
50
+
51
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
@@ -0,0 +1,7 @@
1
+ export interface Logger {
2
+ (formatter: any, ...args: any[]): void;
3
+ error: (formatter: any, ...args: any[]) => void;
4
+ enabled: boolean;
5
+ }
6
+ export declare function logger(name: string): Logger;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACrB,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IACtC,KAAK,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC/C,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,wBAAgB,MAAM,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5C"}
@@ -0,0 +1,7 @@
1
+ import debug from 'debug';
2
+ export function logger(name) {
3
+ return Object.assign(debug(name), {
4
+ error: debug(`${name}:error`)
5
+ });
6
+ }
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,MAAM,UAAU,MAAM,CAAE,IAAY;IAClC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QAChC,KAAK,EAAE,KAAK,CAAC,GAAG,IAAI,QAAQ,CAAC;KAC9B,CAAC,CAAA;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,142 @@
1
+ {
2
+ "name": "@libp2p/logger",
3
+ "version": "0.0.0",
4
+ "description": "A logging component for use in js-libp2p components",
5
+ "license": "Apache-2.0 OR MIT",
6
+ "homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-logger#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/libp2p/js-libp2p-interfaces/issues"
13
+ },
14
+ "keywords": [
15
+ "IPFS"
16
+ ],
17
+ "engines": {
18
+ "node": ">=16.0.0",
19
+ "npm": ">=7.0.0"
20
+ },
21
+ "type": "module",
22
+ "types": "./dist/src/index.d.ts",
23
+ "files": [
24
+ "src",
25
+ "dist/src",
26
+ "!dist/test",
27
+ "!**/*.tsbuildinfo"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "import": "./dist/src/index.js"
32
+ }
33
+ },
34
+ "eslintConfig": {
35
+ "extends": "ipfs",
36
+ "parserOptions": {
37
+ "sourceType": "module"
38
+ }
39
+ },
40
+ "release": {
41
+ "branches": [
42
+ "master"
43
+ ],
44
+ "plugins": [
45
+ [
46
+ "@semantic-release/commit-analyzer",
47
+ {
48
+ "preset": "conventionalcommits",
49
+ "releaseRules": [
50
+ {
51
+ "breaking": true,
52
+ "release": "major"
53
+ },
54
+ {
55
+ "revert": true,
56
+ "release": "patch"
57
+ },
58
+ {
59
+ "type": "feat",
60
+ "release": "minor"
61
+ },
62
+ {
63
+ "type": "fix",
64
+ "release": "patch"
65
+ },
66
+ {
67
+ "type": "chore",
68
+ "release": "patch"
69
+ },
70
+ {
71
+ "type": "docs",
72
+ "release": "patch"
73
+ },
74
+ {
75
+ "type": "test",
76
+ "release": "patch"
77
+ },
78
+ {
79
+ "scope": "no-release",
80
+ "release": false
81
+ }
82
+ ]
83
+ }
84
+ ],
85
+ [
86
+ "@semantic-release/release-notes-generator",
87
+ {
88
+ "preset": "conventionalcommits",
89
+ "presetConfig": {
90
+ "types": [
91
+ {
92
+ "type": "feat",
93
+ "section": "Features"
94
+ },
95
+ {
96
+ "type": "fix",
97
+ "section": "Bug Fixes"
98
+ },
99
+ {
100
+ "type": "chore",
101
+ "section": "Trivial Changes"
102
+ },
103
+ {
104
+ "type": "docs",
105
+ "section": "Trivial Changes"
106
+ },
107
+ {
108
+ "type": "test",
109
+ "section": "Tests"
110
+ }
111
+ ]
112
+ }
113
+ }
114
+ ],
115
+ "@semantic-release/changelog",
116
+ "@semantic-release/npm",
117
+ "@semantic-release/github",
118
+ "@semantic-release/git"
119
+ ]
120
+ },
121
+ "scripts": {
122
+ "lint": "aegir lint",
123
+ "dep-check": "aegir dep-check dist/src/**/*.js",
124
+ "build": "tsc",
125
+ "pretest": "npm run build",
126
+ "test": "aegir test -f ./dist/test/**/*.js",
127
+ "test:chrome": "npm run test -- -t browser",
128
+ "test:chrome-webworker": "npm run test -- -t webworker",
129
+ "test:firefox": "npm run test -- -t browser -- --browser firefox",
130
+ "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
131
+ "test:node": "npm run test -- -t node --cov",
132
+ "test:electron-main": "npm run test -- -t electron-main"
133
+ },
134
+ "dependencies": {
135
+ "@libp2p/interfaces": "^1.0.0",
136
+ "debug": "^4.3.3"
137
+ },
138
+ "devDependencies": {
139
+ "aegir": "^36.1.3",
140
+ "@types/debug": "^4.1.7"
141
+ }
142
+ }
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ import debug from 'debug'
2
+
3
+ export interface Logger {
4
+ (formatter: any, ...args: any[]): void
5
+ error: (formatter: any, ...args: any[]) => void
6
+ enabled: boolean
7
+ }
8
+
9
+ export function logger (name: string): Logger {
10
+ return Object.assign(debug(name), {
11
+ error: debug(`${name}:error`)
12
+ })
13
+ }