@4lch4/logger
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,5 +0,6 @@ | ||
import { IColorOpts, ILogger, LogFormat } from './interfaces'; | ||
import { ILogger, ILoggerOpts } from './interfaces'; | ||
export declare class Logger implements ILogger { | ||
private formatter; | ||
constructor(format?: LogFormat, colors?: IColorOpts); | ||
private ioUtil?; | ||
constructor(loggerOpts: ILoggerOpts); | ||
info(msg: string): void; | ||
@@ -6,0 +7,0 @@ warn(msg: string): void; |
@@ -6,10 +6,14 @@ "use strict"; | ||
const lib_1 = require("./lib"); | ||
const IOUtil_1 = require("./lib/IOUtil"); | ||
class Logger { | ||
constructor(format, colors) { | ||
constructor(loggerOpts) { | ||
let colorOpts = lib_1.DefaultColors; | ||
let formatOpt = lib_1.DefaultLogFormat; | ||
if (colors) | ||
colorOpts = colors; | ||
if (format) | ||
formatOpt = format; | ||
if (loggerOpts.format) | ||
formatOpt = loggerOpts.format; | ||
if (loggerOpts.colorOpts) | ||
colorOpts = loggerOpts.colorOpts; | ||
if (loggerOpts.logDir) { | ||
this.ioUtil = new IOUtil_1.IOUtil(loggerOpts.logDir, loggerOpts.format); | ||
} | ||
this.formatter = new lib_1.Formatter(formatOpt, colorOpts); | ||
@@ -19,8 +23,14 @@ } | ||
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.info)); | ||
if (this.ioUtil) | ||
this.ioUtil.writeToLog(msg, interfaces_1.Level.info); | ||
} | ||
warn(msg) { | ||
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.warn)); | ||
if (this.ioUtil) | ||
this.ioUtil.writeToLog(msg, interfaces_1.Level.warn); | ||
} | ||
debug(msg) { | ||
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.debug)); | ||
if (this.ioUtil) | ||
this.ioUtil.writeToLog(msg, interfaces_1.Level.debug); | ||
} | ||
@@ -37,8 +47,21 @@ error(msg, ...extra) { | ||
} | ||
if (this.ioUtil) { | ||
if (msg instanceof Error) | ||
this.ioUtil.writeToLog(msg.message, interfaces_1.Level.error); | ||
else | ||
this.ioUtil.writeToLog(msg, interfaces_1.Level.error); | ||
if (extra.length > 0) { | ||
this.ioUtil.writeToLog(extra.join('\n'), interfaces_1.Level.error); | ||
} | ||
} | ||
} | ||
success(msg) { | ||
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.success)); | ||
if (this.ioUtil) | ||
this.ioUtil.writeToLog(msg, interfaces_1.Level.success); | ||
} | ||
log(msg, level) { | ||
console.log(this.formatter.formatMsg(msg, level)); | ||
if (this.ioUtil) | ||
this.ioUtil.writeToLog(msg, level); | ||
} | ||
@@ -45,0 +68,0 @@ } |
export * from './IColorOpts'; | ||
export * from './ILogFilePaths'; | ||
export * from './ILogger'; | ||
export * from './ILoggerOpts'; | ||
export * from './Level'; | ||
export * from './LogFormat'; |
@@ -14,5 +14,7 @@ "use strict"; | ||
__exportStar(require("./IColorOpts"), exports); | ||
__exportStar(require("./ILogFilePaths"), exports); | ||
__exportStar(require("./ILogger"), exports); | ||
__exportStar(require("./ILoggerOpts"), exports); | ||
__exportStar(require("./Level"), exports); | ||
__exportStar(require("./LogFormat"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
const os_1 = require("os"); | ||
const _1 = require("."); | ||
const _1 = require("./"); | ||
dayjs_1.default.extend(advancedFormat_1.default); | ||
@@ -14,0 +14,0 @@ class Formatter { |
{ | ||
"name": "@4lch4/logger", | ||
"displayName": "Logger", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A small utility for logging to console within NodeJS/TypeScript applications.", | ||
@@ -36,4 +36,8 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/fs-extra": "^9.0.8", | ||
"np": "^7.4.0" | ||
}, | ||
"optionalDependencies": { | ||
"fs-extra": "^9.1.0" | ||
} | ||
} |
@@ -1,13 +0,18 @@ | ||
import { IColorOpts, ILogger, Level, LogFormat } from './interfaces' | ||
import { ILogger, ILoggerOpts, Level } from './interfaces' | ||
import { DefaultColors, DefaultLogFormat, Formatter } from './lib' | ||
import { IOUtil } from './lib/IOUtil' | ||
export class Logger implements ILogger { | ||
private formatter: Formatter | ||
private ioUtil?: IOUtil | ||
constructor(format?: LogFormat, colors?: IColorOpts) { | ||
constructor(loggerOpts: ILoggerOpts) { | ||
let colorOpts = DefaultColors | ||
let formatOpt = DefaultLogFormat | ||
if (colors) colorOpts = colors | ||
if (format) formatOpt = format | ||
if (loggerOpts.format) formatOpt = loggerOpts.format | ||
if (loggerOpts.colorOpts) colorOpts = loggerOpts.colorOpts | ||
if (loggerOpts.logDir) { | ||
this.ioUtil = new IOUtil(loggerOpts.logDir, loggerOpts.format) | ||
} | ||
@@ -19,2 +24,4 @@ this.formatter = new Formatter(formatOpt, colorOpts) | ||
console.log(this.formatter.formatMsg(msg, Level.info)) | ||
if (this.ioUtil) this.ioUtil.writeToLog(msg, Level.info) | ||
} | ||
@@ -24,2 +31,4 @@ | ||
console.log(this.formatter.formatMsg(msg, Level.warn)) | ||
if (this.ioUtil) this.ioUtil.writeToLog(msg, Level.warn) | ||
} | ||
@@ -29,2 +38,4 @@ | ||
console.log(this.formatter.formatMsg(msg, Level.debug)) | ||
if (this.ioUtil) this.ioUtil.writeToLog(msg, Level.debug) | ||
} | ||
@@ -42,2 +53,11 @@ | ||
} | ||
if (this.ioUtil) { | ||
if (msg instanceof Error) this.ioUtil.writeToLog(msg.message, Level.error) | ||
else this.ioUtil.writeToLog(msg, Level.error) | ||
if (extra.length > 0) { | ||
this.ioUtil.writeToLog(extra.join('\n'), Level.error) | ||
} | ||
} | ||
} | ||
@@ -47,2 +67,4 @@ | ||
console.log(this.formatter.formatMsg(msg, Level.success)) | ||
if (this.ioUtil) this.ioUtil.writeToLog(msg, Level.success) | ||
} | ||
@@ -52,3 +74,5 @@ | ||
console.log(this.formatter.formatMsg(msg, level)) | ||
if (this.ioUtil) this.ioUtil.writeToLog(msg, level) | ||
} | ||
} |
export * from './IColorOpts' | ||
export * from './ILogFilePaths' | ||
export * from './ILogger' | ||
export * from './ILoggerOpts' | ||
export * from './Level' | ||
export * from './LogFormat' |
@@ -5,5 +5,5 @@ import chalk from 'chalk' | ||
import { hostname } from 'os' | ||
import { DefaultDayJSFormats } from '.' | ||
import { IColorOpts, Level } from '../interfaces' | ||
import { LogFormat } from '../interfaces/LogFormat' | ||
import { DefaultDayJSFormats } from './' | ||
@@ -10,0 +10,0 @@ dayjs.extend(AdvancedFormats) |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
41692
64
829
3
2
1