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

fast-node-logger

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-node-logger - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

5

.vscode/settings.json
{
"typescript.tsdk": "node_modules\\typescript\\lib"
"typescript.tsdk": "node_modules\\typescript\\lib",
"cSpell.words": [
"pinoms"
]
}

9

dist/app.js

@@ -22,8 +22,9 @@ "use strict";

const options = {
logDir: "./logs",
retentionTime: 30000,
level: "trace",
prettyPrint: { colorize: true, translateTime: "SYS:standard" },
};
yield _1.createLogger(options);
const logger = yield _1.createLogger(options);
_1.writeLog(`logger is created!`, { stdout: true });
console.log(`here is my secret: ${process.env.MY_SECRET}`);
logger.debug("debug log");
logger.info(`here is my secret: ${process.env.MY_SECRET}`);
return process.env.MY_SECRET;

@@ -30,0 +31,0 @@ });

import pino from "pino";
export interface Options {
export interface Options extends pino.LoggerOptions {
logDir?: string;
retentionTime?: number;
/**prettify config for console output */
prettyPrint?: pino.PrettyOptions;
}
/** @returns a previously instantiated instance of Pino that logs to an automatically generated file in logs folder in root directory */
export declare function createLogger(options?: Options): Promise<pino.Logger>;
/** get logs and if log file exist, write it to file and console.log it */
/** write message to both file and/or console */
export declare function writeLog(message: any, config?: {
stdout: boolean;
}): void;

@@ -11,9 +11,2 @@ "use strict";

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -23,14 +16,17 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path"));
const pino_1 = __importDefault(require("pino"));
const path_1 = __importDefault(require("path"));
const utils_1 = require("./helpers/utils");
const pino_1 = __importDefault(require("pino"));
const variables_1 = require("./helpers/variables");
/** instance for logging to file */
let logFileStream;
/**instance for log to console */
let logToConsole;
/** @returns a previously instantiated instance of Pino that logs to an automatically generated file in logs folder in root directory */
function createLogger(options) {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e;
return __awaiter(this, void 0, void 0, function* () {
const fileName = `${new Date().getTime()}.log`;
const dirPath = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.logDir, (_b !== null && _b !== void 0 ? _b : variables_1.defaultLogFolder));
const filePath = path.join(dirPath, fileName);
const filePath = path_1.default.join(dirPath, fileName);
/** make sure logs folder exist */

@@ -47,5 +43,6 @@ yield utils_1.createDirectoryIfNotExist(dirPath).catch(function () {

});
console.log(`Logging to file: ${filePath}`);
const dest = pino_1.default.destination(filePath);
logFileStream = pino_1.default(dest);
logToConsole = pino_1.default(Object.assign({}, options));
logFileStream = pino_1.default((_e = Object.assign(Object.assign({}, options), { prettyPrint: { colorize: false } }), (_e !== null && _e !== void 0 ? _e : {})), dest);
logToConsole.info(`Logging to file: ${filePath}`);
return logFileStream;

@@ -55,8 +52,9 @@ });

exports.createLogger = createLogger;
/** get logs and if log file exist, write it to file and console.log it */
/** write message to both file and/or console */
function writeLog(message, config = { stdout: false }) {
var _a;
if (logFileStream) {
logFileStream.info(message);
if (config.stdout) {
console.log(message);
(_a = logToConsole) === null || _a === void 0 ? void 0 : _a.info(message);
}

@@ -63,0 +61,0 @@ }

{
"name": "fast-node-logger",
"version": "1.1.1",
"version": "1.2.0",
"description": "fast node logger base on pino",

@@ -57,4 +57,5 @@ "repository": {

"pino": "^5.16.0",
"pino-pretty": "^3.5.0",
"rimraf": "^3.0.0"
}
}
### A very opinionated file logger and rotation, base on [pino](https://www.npmjs.com/package/pino).
this package does:
this package provides:
- create an instance of [pino](https://www.npmjs.com/package/pino) logger
- quick start with default configuration
- an instance of [pino](https://www.npmjs.com/package/pino) logger
- most flexibility of pino with options and prettify the output
- create a new file in `logs` folder of root directory.
- delete old log files
- type safe with typescript

@@ -16,7 +19,6 @@ ## Notice:

```js
import { createLogger, writeLog } from "fast-node-logger";
import { createLogger } from "fast-node-logger";
createLogger().then(() => {
writeLog("hi");
});
const logger = await createLogger();
logger.info(`Logger is Ready!`);
```

@@ -34,2 +36,15 @@

### use pino original options [Pino Docs](https://github.com/pinojs/pino/blob/master/docs/api.md#options)
```js
import { createLogger, Options } from "fast-node-logger";
const options: Options = {
level: "trace",
prettyPrint: { colorize: true, translateTime: "SYS:standard" },
};
const logger = await createLogger(options);
```
### CreateLogger(options)

@@ -40,3 +55,6 @@

```js
import { createLogger } from "fast-node-logger";
const logger = await createLogger();
logger.info(`Logger is Ready!`);

@@ -47,6 +65,10 @@ ```

a shortcut for `logger.info(message)` with ability to additionally `console.log(message)` with second parameter `{stdout: true}`
a shortcut for `logger.info(message)` with ability to additionally print to console with second parameter `{stdout: true}`
## TODO:
```js
import { writeLog, createLogger, Options } from "fast-node-logger";
- add pino options in createLogger options for more flexibility
await createLogger();
writeLog(`logger is created!`, { stdout: true });
```

@@ -8,8 +8,9 @@ /** How to use it: */

const options: Options = {
logDir: "./logs",
retentionTime: 30000,
level: "trace",
prettyPrint: { colorize: true, translateTime: "SYS:standard" },
};
await createLogger(options);
const logger = await createLogger(options);
writeLog(`logger is created!`, { stdout: true });
console.log(`here is my secret: ${process.env.MY_SECRET}`);
logger.debug("debug log");
logger.info(`here is my secret: ${process.env.MY_SECRET}`);
return process.env.MY_SECRET;

@@ -16,0 +17,0 @@ }

@@ -1,11 +0,18 @@

import * as path from "path";
import pino from "pino";
import path from "path";
import { deleteOldFiles, createDirectoryIfNotExist } from "./helpers/utils";
import pino from "pino";
import { defaultLogFolder } from "./helpers/variables";
/** instance for logging to file */
let logFileStream: pino.Logger | undefined;
export interface Options {
/**instance for log to console */
let logToConsole: pino.Logger | undefined;
export interface Options extends pino.LoggerOptions {
logDir?: string;
retentionTime?: number;
/**prettify config for console output */
prettyPrint?: pino.PrettyOptions;
}

@@ -32,12 +39,18 @@

console.log(`Logging to file: ${filePath}`);
const dest = pino.destination(filePath);
logFileStream = pino(dest);
logToConsole = pino({
...options,
});
logFileStream = pino(
{ ...options, prettyPrint: { colorize: false } } ?? {},
dest,
);
logToConsole.info(`Logging to file: ${filePath}`);
return logFileStream;
}
/** get logs and if log file exist, write it to file and console.log it */
/** write message to both file and/or console */
export function writeLog(message: any, config = { stdout: false }) {

@@ -48,3 +61,3 @@ if (logFileStream) {

if (config.stdout) {
console.log(message);
logToConsole?.info(message);
}

@@ -51,0 +64,0 @@ } else {

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