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

ts-log

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-log - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

34

build/example/index.js

@@ -5,2 +5,17 @@ "use strict";

var src_1 = require("../src");
// example class that uses the logger
var Calculator = /** @class */ (function () {
// accept the logger in the constructor, defaulting to dummy logger that does nothing
function Calculator(log) {
if (log === void 0) { log = src_1.dummyLogger; }
this.log = log;
}
Calculator.prototype.sum = function (a, b) {
var result = a + b;
// call the logger
this.log.info("summing " + a + " + " + b + " = " + result, a, b, result);
return result;
};
return Calculator;
}());
// example custom logger that logs to a file

@@ -51,20 +66,5 @@ var FileLogger = /** @class */ (function () {

}());
// example class that uses the logger
var Calculator = /** @class */ (function () {
// accept the logger in the constructor, defaulting to dummy logger
function Calculator(log) {
if (log === void 0) { log = src_1.dummyLogger; }
this.log = log;
}
Calculator.prototype.sum = function (a, b) {
var result = a + b;
// call the logger
this.log.info("summing " + a + " + " + b + " = " + result, a, b, result);
return result;
};
return Calculator;
}());
// don't define the logger, defaults to dummy logger that does not do anything
// don't define a logger, defaults to dummy logger that does nothing
var calculator1 = new Calculator();
// use the build-in console as the logger
// use the built-in console as the logger
var calculator2 = new Calculator(console);

@@ -71,0 +71,0 @@ // use the custom file logger

@@ -14,3 +14,2 @@ "use strict";

}
/* dummy */
},

@@ -22,3 +21,2 @@ debug: function (_message) {

}
/* dummy */
},

@@ -30,3 +28,2 @@ info: function (_message) {

}
/* dummy */
},

@@ -38,3 +35,2 @@ warn: function (_message) {

}
/* dummy */
},

@@ -46,5 +42,4 @@ error: function (_message) {

}
/* dummy */
},
};
//# sourceMappingURL=index.js.map

@@ -17,4 +17,4 @@ "use strict";

while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {

@@ -21,0 +21,0 @@ case 0: case 1: t = op; break;

import * as fs from "fs";
import { dummyLogger, Logger } from "../src";
// example class that uses the logger
class Calculator {
// accept the logger in the constructor, defaulting to dummy logger that does nothing
public constructor(private readonly log: Logger = dummyLogger) {}
public sum(a: number, b: number) {
const result = a + b;
// call the logger
this.log.info(`summing ${a} + ${b} = ${result}`, a, b, result);
return result;
}
}
// example custom logger that logs to a file

@@ -33,21 +48,6 @@ class FileLogger implements Logger {

// example class that uses the logger
class Calculator {
// accept the logger in the constructor, defaulting to dummy logger
public constructor(private readonly log: Logger = dummyLogger) {}
public sum(a: number, b: number) {
const result = a + b;
// call the logger
this.log.info(`summing ${a} + ${b} = ${result}`, a, b, result);
return result;
}
}
// don't define the logger, defaults to dummy logger that does not do anything
// don't define a logger, defaults to dummy logger that does nothing
const calculator1 = new Calculator();
// use the build-in console as the logger
// use the built-in console as the logger
const calculator2 = new Calculator(console);

@@ -54,0 +54,0 @@

{
"name": "ts-log",
"version": "2.1.3",
"version": "2.1.4",
"description": "Abstract logger TypeScript interface with a dummy logger that does nothing, useful for libraries.",

@@ -8,9 +8,3 @@ "main": "build/src/index.js",

"author": "Stagnation Lab",
"keywords": [
"typescript",
"abstract",
"logger",
"console",
"dummy"
],
"keywords": ["typescript", "abstract", "logger", "console", "dummy"],
"license": "MIT",

@@ -34,3 +28,3 @@ "repository": {

"coverage": "yarn tidy:coverage && jest --collectCoverage",
"audit": "yarn prettier && yarn build && yarn lint && yarn coverage",
"validate": "yarn prettier && yarn build && yarn lint && yarn coverage",
"coveralls": "cat ./coverage/lcov.info | coveralls"

@@ -40,13 +34,13 @@ },

"devDependencies": {
"@types/jest": "^22.2.2",
"@types/node": "^9.6.1",
"coveralls": "^3.0.0",
"jest": "^22.4.3",
"nodemon": "^1.17.3",
"prettier": "^1.12.1",
"@types/jest": "^23.3.9",
"@types/node": "^10.12.9",
"coveralls": "^3.0.2",
"jest": "^23.6.0",
"nodemon": "^1.18.6",
"prettier": "^1.15.2",
"rimraf": "^2.6.2",
"ts-jest": "^22.4.2",
"ts-jest": "^23.10.4",
"tslint": "^5.11.0",
"typescript": "^2.8.1",
"typestrict": "^0.0.9"
"typescript": "^3.1.6",
"typestrict": "^1.0.1"
},

@@ -57,17 +51,8 @@ "jest": {

},
"roots": [
"src"
],
"roots": ["src"],
"collectCoverage": false,
"collectCoverageFrom": [
"src/**/*.ts"
],
"collectCoverageFrom": ["src/**/*.ts"],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
"moduleFileExtensions": ["ts", "tsx", "js", "json"]
}
}

@@ -11,8 +11,9 @@ # TypeScript Abstract Logger

Useful for libraries wanting to provide a pluggable logger that does nothing by default.
Useful for libraries wanting to provide a pluggable logger that does nothing by default (or provide your own default such as [bunyan](https://github.com/trentm/node-bunyan)).
- Matches the build-in console that can be directly plugged in.
- Matches the built-in console that can be used directly.
- Also matches [bunyan](https://github.com/trentm/node-bunyan).
- Provides usage and custom logger example.
- Written in TypeScript, no need for extra typings.
- No dependencies, 24 LOC with comments, 100% test coverage.

@@ -26,2 +27,5 @@ ## Installation

```
```cmd
yarn add ts-log
```

@@ -31,7 +35,22 @@ ## Example

```typescript
import { dummyLogger, ILogger } from "ts-log";
import { dummyLogger, Logger } from "ts-log";
import * as fs from "fs";
// example class that uses the logger
class Calculator {
// accept the logger in the constructor, defaulting to dummy logger that does nothing
public constructor(private readonly log: Logger = dummyLogger) {}
public sum(a: number, b: number) {
const result = a + b;
// call the logger
this.log.info(`summing ${a} + ${b} = ${result}`, a, b, result);
return result;
}
}
// example custom logger that logs to a file
class FileLogger implements ILogger {
class FileLogger implements Logger {
private readonly fd: number;

@@ -68,21 +87,6 @@

// example class that uses the logger
class Calculator {
// accept the logger in the constructor, defaulting to dummy logger
public constructor(private readonly log: ILogger = dummyLogger) {}
public sum(a: number, b: number) {
const result = a + b;
// call the logger
this.log.info(`summing ${a} + ${b} = ${result}`, a, b, result);
return result;
}
}
// don't define the logger, defaults to dummy logger that does not do anything
// don't define a logger, defaults to dummy logger that does nothing
const calculator1 = new Calculator();
// use the build-in console as the logger
// use the built-in console as the logger
const calculator2 = new Calculator(console);

@@ -107,2 +111,2 @@

- `yarn prettier` to run prettier.
- `yarn audit` to run all pre-commit checks (prettier, build, lint, test)
- `yarn validate` to run all pre-commit checks (prettier, build, lint, test)

@@ -19,17 +19,7 @@ /**

export const dummyLogger: Logger = {
trace: (_message?: any, ..._optionalParams: any[]) => {
/* dummy */
},
debug: (_message?: any, ..._optionalParams: any[]) => {
/* dummy */
},
info: (_message?: any, ..._optionalParams: any[]) => {
/* dummy */
},
warn: (_message?: any, ..._optionalParams: any[]) => {
/* dummy */
},
error: (_message?: any, ..._optionalParams: any[]) => {
/* dummy */
},
trace: (_message?: any, ..._optionalParams: any[]) => {},
debug: (_message?: any, ..._optionalParams: any[]) => {},
info: (_message?: any, ..._optionalParams: any[]) => {},
warn: (_message?: any, ..._optionalParams: any[]) => {},
error: (_message?: any, ..._optionalParams: any[]) => {},
};

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