Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@4lch4/logger

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@4lch4/logger - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/interfaces/ILogFilePaths.d.ts

5

dist/index.d.ts

@@ -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;

33

dist/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc