Socket
Socket
Sign inDemoInstall

pino-tiny

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-tiny - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

12

dist/index.d.ts
#!/usr/bin/env node
import { prettifier } from './logger';
export interface PinoTinyOptions {
hideIcons?: boolean;
hideLetters?: boolean;
hideTimestamp?: boolean;
hideColors?: boolean;
hideWeb?: boolean;
msgKey?: string;
filter?: (data: any) => any | undefined;
}
declare function run(filter?: (data: any) => any | undefined): void;
export declare const PinoTinyPrettifier: typeof prettifier;
export declare const Run: typeof run;
export {};

31

dist/index.js
#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PinoTinyPrettifier = void 0;
exports.Run = exports.PinoTinyPrettifier = void 0;
var logger_1 = require("./logger");
var yargs_1 = __importDefault(require("yargs/yargs"));
var helpers_1 = __importDefault(require("yargs/helpers"));
function run(filter) {
var argv = (0, yargs_1.default)(helpers_1.default.hideBin(process.argv)).options({
i: { type: 'boolean', default: false, alias: 'hide-icons', description: 'Hide level emoji icons.' },
l: { type: 'boolean', default: false, alias: 'hide-letters', description: 'Hide level letters.' },
t: { type: 'boolean', default: false, alias: 'hide-timestamp', description: 'Hide the timestamp.' },
c: { type: 'boolean', default: false, alias: 'hide-colors', description: 'Remove ansi colors from output.' },
w: { type: 'boolean', default: false, alias: 'hide-web', description: 'Hide web stats.' },
m: { type: 'string', default: 'msg', alias: 'msg-key', description: 'The key to use for message from the JSON log data.' }
}).parseSync();
var cliOptions = {
hideIcons: argv.i,
hideLetters: argv.l,
hideTimestamp: argv.t,
hideColors: argv.c,
msgKey: argv.m,
hideWeb: argv.w
};
if (filter != null)
cliOptions.filter = filter;
(0, logger_1.start)(cliOptions);
}
if (require.main === module) {
(0, logger_1.start)();
run();
}
exports.PinoTinyPrettifier = logger_1.prettifier;
exports.Run = run;

9

dist/logger.d.ts

@@ -1,5 +0,6 @@

export declare function start(): void;
export declare function prettifier(): any;
import { PinoTinyOptions } from '.';
export declare function start(options: PinoTinyOptions): void;
export declare function prettifier(options: PinoTinyOptions): any;
export declare function parse(line: string): any;
export declare function format(data: any, key?: string): string | undefined;
export declare function callback(): (input: any, enc: unknown, cb: (error?: any, result?: any) => void) => void;
export declare function format(data: any, options?: PinoTinyOptions): string | undefined;
export declare function callback(options: PinoTinyOptions): (input: any, enc: unknown, cb: (error?: any, result?: any) => void) => void;

@@ -13,12 +13,14 @@ "use strict";

var dateformat_1 = __importDefault(require("dateformat"));
var strip_ansi_1 = __importDefault(require("strip-ansi"));
var levels = {
10: { prefix: 'TRC 🔎', color: chalk_1.default.rgb(128, 128, 128) },
20: { prefix: 'DBG đŸĒ˛ ', color: chalk_1.default.rgb(255, 255, 0) },
30: { prefix: 'INF ℹī¸ ', color: chalk_1.default.rgb(0, 255, 0) },
40: { prefix: 'WRN ⚠ī¸ ', color: chalk_1.default.rgb(255, 128, 0) },
50: { prefix: 'ERR đŸ”Ĩ', color: chalk_1.default.rgb(255, 0, 0) },
60: { prefix: 'FTL đŸ’Ŗ', color: chalk_1.default.bgRgb(255, 0, 0).white }
10: { letters: 'TRC', icon: ' 🔎', color: chalk_1.default.rgb(128, 128, 128) },
20: { letters: 'DBG', icon: ' đŸĒ˛ ', color: chalk_1.default.rgb(255, 255, 0) },
30: { letters: 'INF', icon: ' ℹī¸ ', color: chalk_1.default.rgb(0, 255, 0) },
40: { letters: 'WRN', icon: ' ⚠ī¸ ', color: chalk_1.default.rgb(255, 128, 0) },
50: { letters: 'ERR', icon: ' đŸ”Ĩ', color: chalk_1.default.rgb(255, 0, 0) },
60: { letters: 'FTL', icon: ' đŸ’Ŗ', color: chalk_1.default.bgRgb(255, 0, 0).white }
};
function start() {
var thru = through2_1.default.obj(callback());
var unknown = { letters: '???', icon: ' 🤷‍', color: chalk_1.default.rgb(128, 128, 128) };
function start(options) {
var thru = through2_1.default.obj(callback(options));
var parser = (0, split2_1.default)(parse);

@@ -31,9 +33,8 @@ (0, pump_1.default)(process.stdin, parser, thru, process.stdout).on('error', console.error);

exports.start = start;
function prettifier() {
return function (options) {
var key = options.msg;
function prettifier(options) {
return function () {
return function (data) {
var _a;
var entry = typeof data === 'string' ? parse(data) : data;
return (_a = format(entry, key)) !== null && _a !== void 0 ? _a : '';
return (_a = format(entry, options)) !== null && _a !== void 0 ? _a : '';
};

@@ -46,2 +47,3 @@ };

var output = JSON.parse(line);
console.log(line);
return output;

@@ -59,18 +61,34 @@ }

exports.parse = parse;
function format(data, key) {
var _a;
if (key === void 0) { key = 'msg'; }
var isWeb = data.res != null && data.req != null;
var level = levels[data.level];
var prefix = level != null ? level.color(level.prefix) : chalk_1.default.grey('????');
var web = isWeb ? data.req.method + " " + data.req.url + " (" + data.res.statusCode + (data.responseTime != null ? "/" + data.responseTime.toLocaleString() + "ms" : '') + ")" : '';
var msg = (_a = data[key]) !== null && _a !== void 0 ? _a : chalk_1.default.grey(JSON.stringify(data));
var output = prefix + " " + chalk_1.default.dim((0, dateformat_1.default)(data.time, 'HH:mm:ss.l')) + " " + msg + " " + chalk_1.default.dim(web) + "\n";
return output;
function format(data, options) {
var _a, _b, _c, _d, _e, _f;
if (options === void 0) { options = {}; }
if (options.filter != null) {
data = options.filter(data);
}
if (data == null)
return;
var parts = [];
var level = (_a = levels[data.level]) !== null && _a !== void 0 ? _a : unknown;
if (!((_b = options.hideLetters) !== null && _b !== void 0 ? _b : false)) {
var prefix = [level.letters];
if ((!((_c = options.hideIcons) !== null && _c !== void 0 ? _c : false))) {
prefix.push(level.icon);
}
parts.push(level.color(prefix.join(' ')));
}
if (!((_d = options.hideTimestamp) !== null && _d !== void 0 ? _d : false)) {
parts.push(chalk_1.default.dim((0, dateformat_1.default)(data.time, 'HH:mm:ss.l')));
}
parts.push(data.msg);
if (!((_e = options.hideTimestamp) !== null && _e !== void 0 ? _e : false) && data.res != null && data.req != null) {
parts.push(chalk_1.default.dim(data.req.method + " " + data.req.url + " (" + data.res.statusCode + (data.responseTime != null ? "/" + data.responseTime.toLocaleString() + "ms" : '') + ")"));
}
var output = parts.join(' ') + "\n";
return ((_f = options.hideColors) !== null && _f !== void 0 ? _f : false) ? (0, strip_ansi_1.default)(output) : output;
}
exports.format = format;
function callback() {
function callback(options) {
return function (input, _enc, cb) {
try {
cb(null, format(input));
cb(null, format(input, options));
}

@@ -77,0 +95,0 @@ catch (err) {

{
"name": "pino-tiny",
"version": "2.0.0",
"version": "2.1.0",
"main": "dist/index.js",

@@ -26,3 +26,2 @@ "bin": {

"dependencies": {
"@types/dateformat": "^3.0.1",
"chalk": "^4.1.2",

@@ -32,6 +31,8 @@ "dateformat": "^4.5.1",

"split2": "^3.2.2",
"through2": "^4.0.2"
"strip-ansi": "^6.0.0",
"through2": "^4.0.2",
"yargs": "^17.1.1"
},
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/dateformat": "^3.0.1",
"@types/node": "^16.7.10",

@@ -41,2 +42,3 @@ "@types/pump": "^1.1.1",

"@types/through2": "^2.0.36",
"@types/yargs": "^17.0.2",
"@typescript-eslint/parser": "^4.30.0",

@@ -43,0 +45,0 @@ "eslint": "^7.32.0",

@@ -29,2 +29,17 @@ # pino-tiny

### CLI Arguments
Now you can tweak the output a bit with command line arguments
```
Options:
--help Show help
--version Show version number
-i, --hide-icons Hide level emoji icons.
-l, --hide-letters Hide level letters.
-t, --hide-timestamp Hide the timestamp.
-c, --hide-colors Remove ansi colors from output.
-w, --hide-web Hide web stats.
-m, --msg-key The key to use for message from the JSON log data.
```
...or put it in your `package.json` file...

@@ -51,3 +66,3 @@

const logger = new Pino({
prettifier: PinoTinyPrettifier(),
prettifier: PinoTinyPrettifier(/*{[options]}*/),
prettyPrint: true

@@ -64,2 +79,65 @@ })

### Prettifier Options
The prettifier has the same options as the cli. Plus a filter function.
```typescript
PinoTinyOptions {
hideIcons?: boolean
hideLetters?: boolean
hideTimestamp?: boolean
hideColors?: boolean
hideWeb?: boolean
msgKey?: string
filter?: (data: any) => any | undefined
}
```
The `filter` option allows you to filter and process the log data. So you can do something like
```javascript
// remove ansi colors and remove messages that have secrets.
const logger = new Pino({
prettifier: PinoTinyPrettifier(
{
hideColor: true,
filter:(data) => {
if (data.hasSecret) {
return { ...data, msg:'*** secret ***' }
} else {
return data
}
}
}
),
prettyPrint: true
})
```
## extensible-ish
pino-tiny runs like a process you pipe the output of your application into and it makes nice output. it also exports a function `Run` that takes the filter option function as a parameter.
this allows you to control if a log entry gets printed, and you can mangle the output (in the msg property of the log). here is a ridiculous example:
```javascript
const { Run } = require('pino-tiny')
function filter (data) {
if(data.msg.indexOf('happy') >= 0) {
// nothing happy gets out.
return false;
}
else {
// prepend msg with woah.
return {
...data,
msg: `[woah!] ${data.msg}`
}
}
}
//start the logger
Run(filter)
```
## what does pino-tiny do?

@@ -81,2 +159,9 @@

* emojis! 🔎 đŸĒ˛ ℹī¸ ⚠ī¸ đŸ”Ĩ đŸ’Ŗ
* src is now in typescript
* src is now in typescript
## New in v2.1
* added prettifier options
* added prettifier options as cli args
* added back the filter method in options
* added back the extensibility
#!/usr/bin/env node
import { start, prettifier } from './logger'
import Yargs from 'yargs/yargs'
import Helpers from 'yargs/helpers'
export interface PinoTinyOptions {
hideIcons?: boolean
hideLetters?: boolean
hideTimestamp?: boolean
hideColors?: boolean
hideWeb?: boolean
msgKey?: string
filter?: (data: any) => any | undefined
}
function run (filter?: (data: any) => any | undefined): void {
const argv = Yargs(Helpers.hideBin(process.argv)).options({
i: { type: 'boolean', default: false, alias: 'hide-icons', description: 'Hide level emoji icons.' },
l: { type: 'boolean', default: false, alias: 'hide-letters', description: 'Hide level letters.' },
t: { type: 'boolean', default: false, alias: 'hide-timestamp', description: 'Hide the timestamp.' },
c: { type: 'boolean', default: false, alias: 'hide-colors', description: 'Remove ansi colors from output.' },
w: { type: 'boolean', default: false, alias: 'hide-web', description: 'Hide web stats.' },
m: { type: 'string', default: 'msg', alias: 'msg-key', description: 'The key to use for message from the JSON log data.' }
}).parseSync()
const cliOptions: PinoTinyOptions = {
hideIcons: argv.i,
hideLetters: argv.l,
hideTimestamp: argv.t,
hideColors: argv.c,
msgKey: argv.m,
hideWeb: argv.w
}
if (filter != null) cliOptions.filter = filter
start(cliOptions)
}
if (require.main === module) {
start()
run()
}
export const PinoTinyPrettifier = prettifier
export const Run = run

@@ -7,5 +7,8 @@ import Split from 'split2'

import DateFormat from 'dateformat'
import { PinoTinyOptions } from '.'
import StripAnsi from 'strip-ansi'
interface Level {
prefix: string
letters: string
icon: string
color: Chalk.Chalk

@@ -17,12 +20,14 @@ }

const levels: Levels = {
10: { prefix: 'TRC 🔎', color: Chalk.rgb(128, 128, 128) },
20: { prefix: 'DBG đŸĒ˛ ', color: Chalk.rgb(255, 255, 0) },
30: { prefix: 'INF ℹī¸ ', color: Chalk.rgb(0, 255, 0) },
40: { prefix: 'WRN ⚠ī¸ ', color: Chalk.rgb(255, 128, 0) },
50: { prefix: 'ERR đŸ”Ĩ', color: Chalk.rgb(255, 0, 0) },
60: { prefix: 'FTL đŸ’Ŗ', color: Chalk.bgRgb(255, 0, 0).white }
10: { letters: 'TRC', icon: ' 🔎', color: Chalk.rgb(128, 128, 128) },
20: { letters: 'DBG', icon: ' đŸĒ˛ ', color: Chalk.rgb(255, 255, 0) },
30: { letters: 'INF', icon: ' ℹī¸ ', color: Chalk.rgb(0, 255, 0) },
40: { letters: 'WRN', icon: ' ⚠ī¸ ', color: Chalk.rgb(255, 128, 0) },
50: { letters: 'ERR', icon: ' đŸ”Ĩ', color: Chalk.rgb(255, 0, 0) },
60: { letters: 'FTL', icon: ' đŸ’Ŗ', color: Chalk.bgRgb(255, 0, 0).white }
}
export function start (): void {
const thru = Through.obj(callback())
const unknown: Level = { letters: '???', icon: ' 🤷‍', color: Chalk.rgb(128, 128, 128) }
export function start (options: PinoTinyOptions): void {
const thru = Through.obj(callback(options))
const parser = Split(parse)

@@ -38,8 +43,7 @@ Pump(process.stdin, parser, thru, process.stdout).on('error', console.error)

export function prettifier (): any {
return (options: any) => {
const key = options.msg
export function prettifier (options: PinoTinyOptions): any {
return () => {
return (data: any) => {
const entry = typeof data === 'string' ? parse(data) : data
return format(entry, key) ?? ''
return format(entry, options) ?? ''
}

@@ -52,2 +56,3 @@ }

const output = JSON.parse(line)
console.log(line)
return output

@@ -64,16 +69,37 @@ } catch (err) {

export function format (data: any, key: string = 'msg'): string | undefined {
const isWeb = data.res != null && data.req != null
const level = levels[data.level]
const prefix = level != null ? level.color(level.prefix) : Chalk.grey('????')
const web = isWeb ? `${data.req.method as string} ${data.req.url as string} (${data.res.statusCode as string}${data.responseTime != null ? `/${(data.responseTime as number).toLocaleString()}ms` : ''})` : ''
const msg: string = data[key] ?? Chalk.grey(JSON.stringify(data))
const output = `${prefix} ${Chalk.dim(DateFormat(data.time, 'HH:mm:ss.l'))} ${msg} ${Chalk.dim(web)}\n`
return output
export function format (data: any, options: PinoTinyOptions = {}): string | undefined {
if (options.filter != null) {
data = options.filter(data)
}
if (data == null) return
const parts: string[] = []
const level: Level = levels[data.level] ?? unknown
if (!(options.hideLetters ?? false)) {
const prefix: string[] = [level.letters]
if ((!(options.hideIcons ?? false))) {
prefix.push(level.icon)
}
parts.push(level.color(prefix.join(' ')))
}
if (!(options.hideTimestamp ?? false)) {
parts.push(Chalk.dim(DateFormat(data.time, 'HH:mm:ss.l')))
}
parts.push(data.msg)
if (!(options.hideTimestamp ?? false) && data.res != null && data.req != null) {
parts.push(Chalk.dim(`${data.req.method as string} ${data.req.url as string} (${data.res.statusCode as string}${data.responseTime != null ? `/${(data.responseTime as number).toLocaleString()}ms` : ''})`))
}
const output = `${parts.join(' ')}\n`
return options.hideColors ?? false ? StripAnsi(output) : output
}
export function callback (): (input: any, enc: unknown, cb: (error?: any, result?: any) => void) => void {
export function callback (options: PinoTinyOptions): (input: any, enc: unknown, cb: (error?: any, result?: any) => void) => void {
return (input, _enc, cb) => {
try {
cb(null, format(input))
cb(null, format(input, options))
} catch (err: any) {

@@ -80,0 +106,0 @@ cb(new Error(`Unable to process log: "${JSON.stringify(input)}". error: ${err.message as string}`))

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