@4lch4/logger
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -1,8 +0,11 @@ | ||
import { Level } from './interfaces/index.js'; | ||
import { DefaultColors, DefaultLogFormat, Formatter } from './lib/index.js'; | ||
export class Logger { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.logger = exports.Logger = void 0; | ||
const index_js_1 = require("./interfaces/index.js"); | ||
const index_js_2 = require("./lib/index.js"); | ||
class Logger { | ||
formatter; | ||
constructor(loggerOpts) { | ||
let colorOpts = DefaultColors; | ||
let formatOpt = DefaultLogFormat; | ||
let colorOpts = index_js_2.DefaultColors; | ||
let formatOpt = index_js_2.DefaultLogFormat; | ||
if (loggerOpts?.format) | ||
@@ -12,13 +15,13 @@ formatOpt = loggerOpts.format; | ||
colorOpts = loggerOpts.colorOpts; | ||
this.formatter = new Formatter(formatOpt, colorOpts); | ||
this.formatter = new index_js_2.Formatter(formatOpt, colorOpts); | ||
} | ||
info(msg, ...optionalParams) { | ||
console.log(this.formatter.formatMsg(msg, Level.info), optionalParams); | ||
console.log(this.formatter.formatMsg(msg, index_js_1.Level.info), optionalParams); | ||
} | ||
warn(msg, ...optionalParams) { | ||
console.log(this.formatter.formatMsg(msg, Level.warn), optionalParams); | ||
console.log(this.formatter.formatMsg(msg, index_js_1.Level.warn), optionalParams); | ||
} | ||
debug(msg, ...optionalParams) { | ||
if (process.env.DEBUG) { | ||
console.log(this.formatter.formatMsg(msg, Level.debug), optionalParams); | ||
console.log(this.formatter.formatMsg(msg, index_js_1.Level.debug), optionalParams); | ||
} | ||
@@ -28,16 +31,16 @@ } | ||
if (msg instanceof Error) { | ||
console.error(this.formatter.formatMsg(msg.message, Level.error)); | ||
console.error(this.formatter.formatMsg(msg.message, index_js_1.Level.error)); | ||
} | ||
else if (msg instanceof String) { | ||
console.error(this.formatter.formatMsg(msg, Level.error)); | ||
console.error(this.formatter.formatMsg(msg, index_js_1.Level.error)); | ||
} | ||
else { | ||
console.error(this.formatter.formatMsg(msg, Level.error)); | ||
console.error(this.formatter.formatMsg(msg, index_js_1.Level.error)); | ||
} | ||
if (optionalParams.length > 0) { | ||
console.error(this.formatter.formatMsg(optionalParams.join('\n'), Level.error)); | ||
console.error(this.formatter.formatMsg(optionalParams.join('\n'), index_js_1.Level.error)); | ||
} | ||
} | ||
success(msg, ...optionalParams) { | ||
console.log(this.formatter.formatMsg(msg, Level.success), optionalParams); | ||
console.log(this.formatter.formatMsg(msg, index_js_1.Level.success), optionalParams); | ||
} | ||
@@ -48,3 +51,4 @@ log(msg, level, ...optionalParams) { | ||
} | ||
export const logger = new Logger(); | ||
exports.Logger = Logger; | ||
exports.logger = new Logger(); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,4 @@ | ||
import { Level } from './index.js'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_js_1 = require("./index.js"); | ||
//# sourceMappingURL=IColorOpts.js.map |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ILogger.js.map |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ILoggerOpts.js.map |
@@ -1,6 +0,18 @@ | ||
export * from './IColorOpts.js'; | ||
export * from './ILogger.js'; | ||
export * from './ILoggerOpts.js'; | ||
export * from './Level.js'; | ||
export * from './LogFormat.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./IColorOpts.js"), exports); | ||
__exportStar(require("./ILogger.js"), exports); | ||
__exportStar(require("./ILoggerOpts.js"), exports); | ||
__exportStar(require("./Level.js"), exports); | ||
__exportStar(require("./LogFormat.js"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,5 @@ | ||
export var Level; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Level = void 0; | ||
var Level; | ||
(function (Level) { | ||
@@ -8,3 +11,3 @@ Level["info"] = "info"; | ||
Level["success"] = "success"; | ||
})(Level || (Level = {})); | ||
})(Level = exports.Level || (exports.Level = {})); | ||
//# sourceMappingURL=Level.js.map |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=LogFormat.js.map |
@@ -1,2 +0,5 @@ | ||
export const DefaultColors = { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DefaultDayJSFormats = exports.DefaultLogFormat = exports.DefaultColors = void 0; | ||
exports.DefaultColors = { | ||
debug: 'cyan', | ||
@@ -8,4 +11,4 @@ error: 'red', | ||
}; | ||
export const DefaultLogFormat = 'plaintext'; | ||
export const DefaultDayJSFormats = { | ||
exports.DefaultLogFormat = 'plaintext'; | ||
exports.DefaultDayJSFormats = { | ||
prettyFormat: 'YYYY.MM.DD-HH:mm:ss', | ||
@@ -12,0 +15,0 @@ utcMillisecondsFormat: 'x' |
@@ -1,7 +0,13 @@ | ||
import chalk from 'chalk'; | ||
import dayjs from 'dayjs'; | ||
import AdvancedFormats from 'dayjs/plugin/advancedFormat'; | ||
import os from 'os'; | ||
import { DefaultDayJSFormats } from './index.js'; | ||
export class Formatter { | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Formatter = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const dayjs_1 = __importDefault(require("dayjs")); | ||
const advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat")); | ||
const os_1 = __importDefault(require("os")); | ||
const index_js_1 = require("./index.js"); | ||
class Formatter { | ||
format; | ||
@@ -12,6 +18,6 @@ colors; | ||
this.format = format; | ||
dayjs.extend(AdvancedFormats); | ||
dayjs_1.default.extend(advancedFormat_1.default); | ||
} | ||
colorMsg(msg, level) { | ||
return chalk[this.colors[level]](msg); | ||
return chalk_1.default[this.colors[level]](msg); | ||
} | ||
@@ -27,3 +33,3 @@ stringifyMsg(msg) { | ||
time: this.getUTCTime(), | ||
host: os.hostname(), | ||
host: os_1.default.hostname(), | ||
pid: process.pid, | ||
@@ -45,8 +51,9 @@ level, | ||
getUTCTime() { | ||
return dayjs().format(DefaultDayJSFormats.utcMillisecondsFormat); | ||
return dayjs_1.default().format(index_js_1.DefaultDayJSFormats.utcMillisecondsFormat); | ||
} | ||
getPrettyTime() { | ||
return dayjs().format(DefaultDayJSFormats.prettyFormat); | ||
return dayjs_1.default().format(index_js_1.DefaultDayJSFormats.prettyFormat); | ||
} | ||
} | ||
exports.Formatter = Formatter; | ||
//# sourceMappingURL=Formatter.js.map |
@@ -1,3 +0,15 @@ | ||
export * from './defaults.js'; | ||
export * from './Formatter.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./defaults.js"), exports); | ||
__exportStar(require("./Formatter.js"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@4lch4/logger", | ||
"displayName": "Logger", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "A small utility for logging to console within NodeJS/TypeScript applications.", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"engines": { | ||
"node": ">=14.16" | ||
}, | ||
"keywords": [ | ||
@@ -12,0 +8,0 @@ "util", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132054
669
No