Skip to content

Commit 226f0b6

Browse files
committed
insial release
0 parents  commit 226f0b6

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.code
2+
.vs_code
3+
.idea

logger.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
let environment: string = 'development';
2+
let config: any;
3+
4+
try {
5+
// Attempt to dynamically import the logger.config file
6+
config = require('../../logger.config')?.default;
7+
} catch (error) {
8+
console.warn(
9+
'No environment config found, defaulting to "development".\n ' +
10+
'If using React Native, create a file "logger.config.js" in the root directory'
11+
);
12+
}
13+
14+
// Checking if the global environment variable is set
15+
if (globalThis.__APP_ENV__) {
16+
environment = globalThis.__APP_ENV__ as string; // Type assertion
17+
} else if (config?.ENV) {
18+
environment = config.ENV;
19+
}
20+
21+
console.warn('Project Environment set to:', environment);
22+
23+
const isDev: boolean = (environment.toLowerCase() === "development");
24+
25+
interface Logger {
26+
info: (taq: string, indicator: string, message?: string) => void;
27+
debug: (taq: string, indicator: string, message?: string) => void;
28+
dLog: (taq: string, indicator: string, data?: any) => void;
29+
Warn: (taq: string, indicator: string, message?: string) => void;
30+
Error: (taq: string, indicator: string, message?: string) => void;
31+
}
32+
33+
const Logger: Logger = {
34+
info: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
35+
console.log(`[INFO][${taq}][${indicator}]`, message);
36+
},
37+
debug: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
38+
if (isDev) {
39+
console.log(`[DEV][${taq}][${indicator}]`, message);
40+
}
41+
},
42+
dLog: (taq: string, indicator: string, data: any = " ") => {
43+
if (isDev) {
44+
console.log('---------------------------------\n');
45+
console.log(`[DEV][${taq}]`, indicator);
46+
console.log(data);
47+
console.log('---------------------------------\n');
48+
}
49+
},
50+
Warn: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
51+
console.warn(`[WARN][${taq}][${indicator}]`, message);
52+
},
53+
Error: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
54+
console.error(`[ERROR][${taq}][${indicator}]`, message);
55+
}
56+
};
57+
58+
export default Logger;

loggerWrapper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Logger from "logger/logger";
2+
3+
const loggerWrapper = (loggerFunction, fileName) => (...args) => loggerFunction(fileName, ...args);
4+
export const LoggerWithFile = (fileName) => {
5+
return {
6+
info: loggerWrapper(Logger.info, fileName),
7+
debug: loggerWrapper(Logger.debug, fileName),
8+
dLog: loggerWrapper(Logger.dLog, fileName),
9+
Warn: loggerWrapper(Logger.Warn, fileName),
10+
Error: loggerWrapper(Logger.Error, fileName),
11+
};
12+
};
13+

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "js-dlogger",
3+
"version": "1.0.0",
4+
"description": "A lightweight and efficient logging utility for JavaScript applications. This package provides multiple logging functions such as info(), dLog(), warn(), debug and error(), displaying logs in the console along with the filename for better debugging and traceability. Perfect for developers looking for a simple yet powerful logging solution.",
5+
"main": "logger.ts",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/structlooper/js-dlogger.git"
12+
},
13+
"keywords": [
14+
"package",
15+
"javaScript-logger",
16+
"js-logger",
17+
"debugger",
18+
"console-logger",
19+
"printer",
20+
"react-logger",
21+
"react-native-logger",
22+
"angular-logger",
23+
"node-logger",
24+
"nextjs-logger"
25+
],
26+
"author": "structlooper",
27+
"license": "MIT",
28+
"bugs": {
29+
"url": "https://github.com/structlooper/js-dlogger/issues"
30+
},
31+
"homepage": "https://github.com/structlooper/js-dlogger#readme"
32+
}

0 commit comments

Comments
 (0)