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 0.4.0 to 1.0.0

dist/lib/defaults.d.ts

2

dist/defaults.d.ts
import { IColorOpts } from './interfaces/IColorOpts';
import { LogFormat } from './interfaces/LogFormat';
export declare const DefaultColors: IColorOpts;
export declare const DefaultFormat: LogFormat;

3

dist/defaults.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultColors = void 0;
exports.DefaultFormat = exports.DefaultColors = void 0;
exports.DefaultColors = {

@@ -11,2 +11,3 @@ debug: 'cyan',

};
exports.DefaultFormat = 'plaintext';
//# sourceMappingURL=defaults.js.map
import { IColorOpts, ILogger, LogFormat } from './interfaces';
export declare class Logger implements ILogger {
private colors;
constructor(_format: LogFormat, colors?: IColorOpts);
private colorMsg;
private formatter;
constructor(format?: LogFormat, colors?: IColorOpts);
info(msg: string): void;
warn(msg: string): void;
debug(msg: string): void;
error(msg: string | Error, ..._extra: any[]): void;
error(msg: string | Error, ...extra: any[]): void;
success(msg: string): void;
log(msg: string, level: any): void;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const chalk_1 = __importDefault(require("chalk"));
const defaults_1 = require("./defaults");
const interfaces_1 = require("./interfaces");
const lib_1 = require("./lib");
class Logger {
constructor(_format, colors) {
this.colors = defaults_1.DefaultColors;
constructor(format, colors) {
let colorOpts = lib_1.DefaultColors;
let formatOpt = lib_1.DefaultLogFormat;
if (colors)
this.colors = colors;
colorOpts = colors;
if (format)
formatOpt = format;
this.formatter = new lib_1.Formatter(formatOpt, colorOpts);
}
colorMsg(msg, level) {
return chalk_1.default.keyword(this.colors[level])(msg);
}
info(msg) {
console.log(this.colorMsg(msg, interfaces_1.Level.info));
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.info));
}
warn(msg) {
console.log(this.colorMsg(msg, interfaces_1.Level.warn));
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.warn));
}
debug(msg) {
console.log(this.colorMsg(msg, interfaces_1.Level.debug));
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.debug));
}
error(msg, ..._extra) {
console.log(this.colorMsg(msg instanceof Error ? msg.message : msg, interfaces_1.Level.error));
console.log(this.colorMsg(_extra.join('\n'), interfaces_1.Level.error));
error(msg, ...extra) {
if (msg instanceof Error) {
console.log(this.formatter.formatMsg(msg.message, interfaces_1.Level.error));
}
else {
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.error));
}
if (extra.length > 0) {
console.log(this.formatter.formatMsg(extra.join('\n'), interfaces_1.Level.error));
}
}
success(msg) {
console.log(this.colorMsg(msg, interfaces_1.Level.success));
console.log(this.formatter.formatMsg(msg, interfaces_1.Level.success));
}
log(msg, level) {
console.log(this.colorMsg(msg, level));
console.log(this.formatter.formatMsg(msg, level));
}

@@ -38,0 +42,0 @@ }

{
"name": "@4lch4/logger",
"displayName": "Logger",
"version": "0.4.0",
"version": "1.0.0",
"description": "A small utility for logging to console within NodeJS/TypeScript applications.",

@@ -6,0 +6,0 @@ "main": "dist/index.js",

@@ -1,46 +0,48 @@

import chalk from 'chalk'
import { DefaultColors } from './defaults'
import { IColorOpts, ILogger, Level, LogFormat } from './interfaces'
import { DefaultColors, DefaultLogFormat, Formatter } from './lib'
export class Logger implements ILogger {
// private _format: LogFormat
private colors: IColorOpts = DefaultColors
private formatter: Formatter
constructor(format?: LogFormat, colors?: IColorOpts) {
let colorOpts = DefaultColors
let formatOpt = DefaultLogFormat
constructor(_format: LogFormat, colors?: IColorOpts) {
if (colors) this.colors = colors
// this._format = format
}
if (colors) colorOpts = colors
if (format) formatOpt = format
private colorMsg(msg: string, level: Level) {
return chalk.keyword(this.colors[level])(msg)
this.formatter = new Formatter(formatOpt, colorOpts)
}
// private formatMsg(msg: string, level: Level) {
// }
info(msg: string) {
console.log(this.colorMsg(msg, Level.info))
console.log(this.formatter.formatMsg(msg, Level.info))
}
warn(msg: string) {
console.log(this.colorMsg(msg, Level.warn))
console.log(this.formatter.formatMsg(msg, Level.warn))
}
debug(msg: string) {
console.log(this.colorMsg(msg, Level.debug))
console.log(this.formatter.formatMsg(msg, Level.debug))
}
error(msg: string | Error, ..._extra: any[]) {
console.log(this.colorMsg(msg instanceof Error ? msg.message : msg, Level.error))
console.log(this.colorMsg(_extra.join('\n'), Level.error))
error(msg: string | Error, ...extra: any[]) {
if (msg instanceof Error) {
console.log(this.formatter.formatMsg(msg.message, Level.error))
} else {
console.log(this.formatter.formatMsg(msg, Level.error))
}
if (extra.length > 0) {
console.log(this.formatter.formatMsg(extra.join('\n'), Level.error))
}
}
success(msg: string) {
console.log(this.colorMsg(msg, Level.success))
console.log(this.formatter.formatMsg(msg, Level.success))
}
log(msg: string, level: any) {
console.log(this.colorMsg(msg, level))
console.log(this.formatter.formatMsg(msg, level))
}
}

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