@meadown/logger 1.0.1 → 1.1.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/dist/cjs/config.d.ts +6 -0
- package/dist/cjs/config.js +19 -0
- package/dist/cjs/index.d.ts +18 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/utils/getFileName.d.ts +5 -0
- package/dist/cjs/utils/getFileName.js +19 -0
- package/dist/cjs/utils/getTimeStamp.d.ts +2 -0
- package/dist/cjs/utils/getTimeStamp.js +13 -0
- package/dist/cjs/utils/index.d.ts +2 -0
- package/dist/cjs/utils/index.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +13 -7
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* config.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 dewan-meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isLogAllowed = isLogAllowed;
|
|
10
|
+
/**
|
|
11
|
+
* Logging is enabled in every environment except production, read directly
|
|
12
|
+
* from `process.env.NODE_ENV`. No configuration — set `NODE_ENV=production`
|
|
13
|
+
* in your runtime to silence logs.
|
|
14
|
+
*/
|
|
15
|
+
function isLogAllowed() {
|
|
16
|
+
// Guard `process` so the logger doesn't throw in non-Node runtimes (browser,
|
|
17
|
+
// edge) where it may be undefined; default to logging when it's absent.
|
|
18
|
+
return typeof process === "undefined" || process.env.NODE_ENV !== "production";
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The logger: a callable for info logs, plus `.error` and `.warn` variants. */
|
|
2
|
+
export interface LogFN {
|
|
3
|
+
(...args: unknown[]): void;
|
|
4
|
+
error(...args: unknown[]): void;
|
|
5
|
+
warn(...args: unknown[]): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Logs to the console, but only outside production. Each line is prefixed with
|
|
9
|
+
* an `[INFO]` tag, an ISO timestamp, and the file and line it was called from;
|
|
10
|
+
* all arguments are then printed as-is. `.error` and `.warn` behave the same
|
|
11
|
+
* with their own tags and console channels.
|
|
12
|
+
* @example
|
|
13
|
+
* customLog("Auth", "user logged in")
|
|
14
|
+
* // [INFO] 2026-05-30T10:00:00.000Z (server.ts:42) Auth user logged in
|
|
15
|
+
*/
|
|
16
|
+
declare const customLog: LogFN;
|
|
17
|
+
export { customLog };
|
|
18
|
+
export default customLog;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* index.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 dewan-meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.customLog = void 0;
|
|
10
|
+
const index_js_1 = require("./utils/index.js");
|
|
11
|
+
const config_js_1 = require("./config.js");
|
|
12
|
+
/**
|
|
13
|
+
* Builds a log function bound to a console channel and tag. The returned closure
|
|
14
|
+
* is what the caller invokes directly, so {@link getFileName} still resolves the
|
|
15
|
+
* caller's own frame (no extra stack frame is inserted). `console[channel]` is
|
|
16
|
+
* looked up at call time, so reassigning `console.log` (e.g. in tests) is
|
|
17
|
+
* respected. Logs only outside production — see {@link isLogAllowed}.
|
|
18
|
+
*/
|
|
19
|
+
function createLog(channel, tag) {
|
|
20
|
+
return (...args) => {
|
|
21
|
+
if ((0, config_js_1.isLogAllowed)())
|
|
22
|
+
console[channel](tag, (0, index_js_1.getTimeStamp)(), `(${(0, index_js_1.getFileName)()})`, ...args);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Logs to the console, but only outside production. Each line is prefixed with
|
|
27
|
+
* an `[INFO]` tag, an ISO timestamp, and the file and line it was called from;
|
|
28
|
+
* all arguments are then printed as-is. `.error` and `.warn` behave the same
|
|
29
|
+
* with their own tags and console channels.
|
|
30
|
+
* @example
|
|
31
|
+
* customLog("Auth", "user logged in")
|
|
32
|
+
* // [INFO] 2026-05-30T10:00:00.000Z (server.ts:42) Auth user logged in
|
|
33
|
+
*/
|
|
34
|
+
const customLog = Object.assign(createLog("log", "[INFO]"), {
|
|
35
|
+
error: createLog("error", "[ERROR]"),
|
|
36
|
+
warn: createLog("warn", "[WARN]"),
|
|
37
|
+
});
|
|
38
|
+
exports.customLog = customLog;
|
|
39
|
+
exports.default = customLog;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* getFileName.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 dewan-meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = getFileName;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the caller's source location as `file.ext:line` by reading the call
|
|
12
|
+
* stack, or `"unknown"` if it can't be determined (e.g. minified or eval code).
|
|
13
|
+
*/
|
|
14
|
+
function getFileName() {
|
|
15
|
+
const stack = new Error().stack ?? "";
|
|
16
|
+
const line = stack.split("\n")[3] ?? "";
|
|
17
|
+
const match = line.match(/([^/\\]+\.[cm]?[jt]sx?):(\d+)/);
|
|
18
|
+
return match ? match[0] : "unknown";
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* getTimeStamp.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 dewan-meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = getTimeStamp;
|
|
10
|
+
/** Returns the current time as an ISO-8601 string, e.g. `2026-05-30T10:00:00.000Z`. */
|
|
11
|
+
function getTimeStamp() {
|
|
12
|
+
return new Date().toISOString();
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* index.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 dewan-meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getTimeStamp = exports.getFileName = void 0;
|
|
13
|
+
var getFileName_js_1 = require("./getFileName.js");
|
|
14
|
+
Object.defineProperty(exports, "getFileName", { enumerable: true, get: function () { return __importDefault(getFileName_js_1).default; } });
|
|
15
|
+
var getTimeStamp_js_1 = require("./getTimeStamp.js");
|
|
16
|
+
Object.defineProperty(exports, "getTimeStamp", { enumerable: true, get: function () { return __importDefault(getTimeStamp_js_1).default; } });
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,gFAAgF;AAChF,MAAM,WAAW,KAAK;IACpB,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC1B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;CAC/B;AAmBD;;;;;;;;GAQG;AACH,QAAA,MAAM,SAAS,EAAE,KAGf,CAAA;AAEF,eAAe,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,gFAAgF;AAChF,MAAM,WAAW,KAAK;IACpB,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC1B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;CAC/B;AAmBD;;;;;;;;GAQG;AACH,QAAA,MAAM,SAAS,EAAE,KAGf,CAAA;AAEF,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,eAAe,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAS1C;;;;;;GAMG;AACH,SAAS,SAAS,CAChB,OAAiC,EACjC,GAAW;IAEX,OAAO,CAAC,GAAG,IAAe,EAAQ,EAAE;QAClC,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,IAAI,WAAW,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACxE,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAU,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;IACjE,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC;IACpC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC;CAClC,CAAC,CAAA;AAEF,eAAe,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAS1C;;;;;;GAMG;AACH,SAAS,SAAS,CAChB,OAAiC,EACjC,GAAW;IAEX,OAAO,CAAC,GAAG,IAAe,EAAQ,EAAE;QAClC,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,IAAI,WAAW,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACxE,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAU,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;IACjE,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC;IACpC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC;CAClC,CAAC,CAAA;AAEF,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,eAAe,SAAS,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meadown/logger",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A tiny, zero-dependency logger for Node.js and TypeScript that tags each line, timestamps it, shows the source file and line, and goes quiet in production.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger",
|
|
@@ -23,13 +23,19 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"author": "Dewan Mobashirul",
|
|
25
25
|
"type": "module",
|
|
26
|
-
"main": "dist/index.js",
|
|
27
|
-
"
|
|
26
|
+
"main": "./dist/cjs/index.js",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
28
29
|
"exports": {
|
|
29
30
|
".": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/index.d.ts",
|
|
37
|
+
"default": "./dist/cjs/index.js"
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
},
|
|
35
41
|
"files": [
|
|
@@ -42,7 +48,7 @@
|
|
|
42
48
|
"access": "public"
|
|
43
49
|
},
|
|
44
50
|
"scripts": {
|
|
45
|
-
"build": "tsc",
|
|
51
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/write-cjs-pkg.mjs",
|
|
46
52
|
"test": "tsc && node --test \"test/**/*.test.mjs\"",
|
|
47
53
|
"lint": "eslint src",
|
|
48
54
|
"lint:fix": "eslint src --fix",
|