@ttoss/logger 0.1.1
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/CHANGELOG.md +10 -0
- package/LICENSE.md +9 -0
- package/README.md +37 -0
- package/package.json +18 -0
- package/src/index.ts +24 -0
- package/tsconfig.json +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 0.1.1 (2023-04-25)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- public access logger package ([#298](https://github.com/ttoss/ttoss/issues/298)) ([79ce406](https://github.com/ttoss/ttoss/commit/79ce406631943687a9814f2b8f23adbe79aab206))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 ttoss.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @ttoss/logger
|
|
2
|
+
|
|
3
|
+
Simple environment agnostic logger.
|
|
4
|
+
|
|
5
|
+
## Motivation
|
|
6
|
+
|
|
7
|
+
Often, for debugging some piece of code, developers use console.log for it. When the application goes for production, some of these logs still appears, most because they forget to clear these logs.
|
|
8
|
+
These package solves this, providing some levels of log that are emitted based on the environment of the application.
|
|
9
|
+
|
|
10
|
+
## Log Levels vs Environments
|
|
11
|
+
|
|
12
|
+
<table>
|
|
13
|
+
<thead>
|
|
14
|
+
<tr><th>Log Level</th><th>Environment</th></tr>
|
|
15
|
+
</thead>
|
|
16
|
+
<tbody>
|
|
17
|
+
<tr><td>Warn</td><td>Dev-only</td></tr>
|
|
18
|
+
<tr><td>Error</td><td>All</td></tr>
|
|
19
|
+
<tr><td>Info</td><td>Dev-only</td></tr>
|
|
20
|
+
</tbody>
|
|
21
|
+
</table>
|
|
22
|
+
|
|
23
|
+
## How to use
|
|
24
|
+
|
|
25
|
+
Just instantiate the logger, provide a context name and start to use:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Logger } from '@ttoss/logger';
|
|
29
|
+
|
|
30
|
+
const logger = Logger('createContext');
|
|
31
|
+
|
|
32
|
+
logger.warn('This will emit an warn on console');
|
|
33
|
+
|
|
34
|
+
logger.error('This will emit a log of type error on console');
|
|
35
|
+
|
|
36
|
+
loggger.info('This will emit a simple log on console');
|
|
37
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ttoss/logger",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Simple environment agnostic logger",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Eron Alves <eron.alves@rocketmail.com>"
|
|
8
|
+
],
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@ttoss/config": "^1.29.5"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"gitHead": "13f3d2b990be54d050adfe8d05d10cf16d127177"
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { log, warn, error } = console;
|
|
2
|
+
const isDev: boolean =
|
|
3
|
+
(import.meta as any)?.env?.DEV || (process.env as any)?.DEV === 'true';
|
|
4
|
+
|
|
5
|
+
export const Logger = (prefix: string) => {
|
|
6
|
+
return {
|
|
7
|
+
warn: (value: string) => {
|
|
8
|
+
if (isDev) {
|
|
9
|
+
const now = new Date();
|
|
10
|
+
warn(`[${now}] - ${prefix} - ${value}`);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
info: (value: string) => {
|
|
14
|
+
if (isDev) {
|
|
15
|
+
const now = new Date();
|
|
16
|
+
log(`[${now}] - ${prefix} - ${value}`);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
error: (value: string) => {
|
|
20
|
+
const now = new Date();
|
|
21
|
+
error(`[${now}] - ${prefix} - ${value}`);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|