@ttoss/logger 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -22,12 +22,21 @@ These package solves this, providing some levels of log that are emitted based o
22
22
 
23
23
  ## How to use
24
24
 
25
- Just instantiate the logger, provide a context name and start to use:
25
+ Just instantiate the logger, providing the `isDev` value configuration and start to use:
26
26
 
27
27
  ```ts
28
+ // createLogger.ts
29
+
28
30
  import { Logger } from '@ttoss/logger';
31
+ import { config } from 'dotenv';
32
+
33
+ config();
34
+
35
+ export const createLogger = Logger(process.env.DEV === 'true');
29
36
 
30
- const logger = Logger('createContext');
37
+ // randomFile.ts
38
+
39
+ const logger = createLogger('randomFile');
31
40
 
32
41
  logger.warn('This will emit an warn on console');
33
42
 
@@ -35,3 +44,14 @@ logger.error('This will emit a log of type error on console');
35
44
 
36
45
  loggger.info('This will emit a simple log on console');
37
46
  ```
47
+
48
+ If you not pass any parameter to `Logger`, it gonna considers to be in dev environment:
49
+
50
+ ```ts
51
+ // createLogger.ts
52
+
53
+ import { Logger } from '@ttoss/logger';
54
+
55
+ // In dev environment, gonna log everything
56
+ export const createLogger = Logger();
57
+ ```
@@ -0,0 +1,32 @@
1
+ /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+
3
+ // src/index.ts
4
+ var {
5
+ log,
6
+ warn,
7
+ error
8
+ } = console;
9
+ var Logger = isDev => {
10
+ const devEnv = isDev !== void 0 ? isDev : true;
11
+ return prefix => {
12
+ return {
13
+ warn: value => {
14
+ if (devEnv) {
15
+ const now = /* @__PURE__ */new Date();
16
+ warn(`[${now}] - ${prefix} - ${value}`);
17
+ }
18
+ },
19
+ info: value => {
20
+ if (devEnv) {
21
+ const now = /* @__PURE__ */new Date();
22
+ log(`[${now}] - ${prefix} - ${value}`);
23
+ }
24
+ },
25
+ error: value => {
26
+ const now = /* @__PURE__ */new Date();
27
+ error(`[${now}] - ${prefix} - ${value}`);
28
+ }
29
+ };
30
+ };
31
+ };
32
+ export { Logger };
@@ -0,0 +1,7 @@
1
+ declare const Logger: (isDev?: boolean) => (prefix: string) => {
2
+ warn: (value: string) => void;
3
+ info: (value: string) => void;
4
+ error: (value: string) => void;
5
+ };
6
+
7
+ export { Logger };
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ "use strict";
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
24
+ value: true
25
+ }), mod);
26
+
27
+ // src/index.ts
28
+ var src_exports = {};
29
+ __export(src_exports, {
30
+ Logger: () => Logger
31
+ });
32
+ module.exports = __toCommonJS(src_exports);
33
+ var {
34
+ log,
35
+ warn,
36
+ error
37
+ } = console;
38
+ var Logger = isDev => {
39
+ const devEnv = isDev !== void 0 ? isDev : true;
40
+ return prefix => {
41
+ return {
42
+ warn: value => {
43
+ if (devEnv) {
44
+ const now = /* @__PURE__ */new Date();
45
+ warn(`[${now}] - ${prefix} - ${value}`);
46
+ }
47
+ },
48
+ info: value => {
49
+ if (devEnv) {
50
+ const now = /* @__PURE__ */new Date();
51
+ log(`[${now}] - ${prefix} - ${value}`);
52
+ }
53
+ },
54
+ error: value => {
55
+ const now = /* @__PURE__ */new Date();
56
+ error(`[${now}] - ${prefix} - ${value}`);
57
+ }
58
+ };
59
+ };
60
+ };
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ Logger
64
+ });
package/package.json CHANGED
@@ -1,18 +1,29 @@
1
1
  {
2
2
  "name": "@ttoss/logger",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Simple environment agnostic logger",
5
5
  "license": "MIT",
6
6
  "contributors": [
7
7
  "Eron Alves <eron.alves@rocketmail.com>"
8
8
  ],
9
- "main": "index.js",
9
+ "main": "dist/index.js",
10
+ "module": "dist/esm/index.js",
11
+ "files": [
12
+ "dist",
13
+ "src"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsup"
17
+ },
18
+ "sideEffects": false,
19
+ "typings": "dist/index.d.ts",
10
20
  "devDependencies": {
11
- "@ttoss/config": "^1.29.5"
21
+ "@ttoss/config": "^1.29.5",
22
+ "tsup": "^6.7.0"
12
23
  },
13
24
  "keywords": [],
14
25
  "publishConfig": {
15
26
  "access": "public"
16
27
  },
17
- "gitHead": "13f3d2b990be54d050adfe8d05d10cf16d127177"
28
+ "gitHead": "2638ab0d44af4673166e1e240de02dc66fd85bbc"
18
29
  }
package/src/index.ts CHANGED
@@ -1,24 +1,26 @@
1
1
  const { log, warn, error } = console;
2
- const isDev: boolean =
3
- (import.meta as any)?.env?.DEV || (process.env as any)?.DEV === 'true';
4
2
 
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) {
3
+ export const Logger = (isDev?: boolean) => {
4
+ const devEnv = isDev !== undefined ? isDev : true;
5
+
6
+ return (prefix: string) => {
7
+ return {
8
+ warn: (value: string) => {
9
+ if (devEnv) {
10
+ const now = new Date();
11
+ warn(`[${now}] - ${prefix} - ${value}`);
12
+ }
13
+ },
14
+ info: (value: string) => {
15
+ if (devEnv) {
16
+ const now = new Date();
17
+ log(`[${now}] - ${prefix} - ${value}`);
18
+ }
19
+ },
20
+ error: (value: string) => {
15
21
  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
- },
22
+ error(`[${now}] - ${prefix} - ${value}`);
23
+ },
24
+ };
23
25
  };
24
26
  };
package/CHANGELOG.md DELETED
@@ -1,10 +0,0 @@
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/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "@ttoss/config/tsconfig.json",
3
- // supports `import.meta`
4
- "compilerOptions": {
5
- "module": "es2020"
6
- }
7
- }