Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updated metadata to exclude error object #16

Merged
merged 22 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6ec5dc0
fix: updated the lib directory
jainaman1497 Sep 21, 2022
e7d01f3
feat: added support to include service
jainaman1497 Sep 21, 2022
4b96c8e
feat: added support to include service
jainaman1497 Sep 21, 2022
6f201a0
Merge https://github.com/Safe-Security/logger
jainaman1497 Sep 22, 2022
4251283
fix: updated logger not to exit after logging an uncaughtException
jainaman1497 Sep 22, 2022
9209c35
fix: updated logger not to exit after logging an uncaughtException
jainaman1497 Sep 22, 2022
794a1a4
Merge https://github.com/Safe-Security/logger
jainaman1497 Sep 26, 2022
4ff50d6
feat: change the format for messageMetadata
jainaman1497 Sep 26, 2022
810cd52
fix: updated the version
jainaman1497 Sep 26, 2022
4505b08
feat: updated logger to user metadata
jainaman1497 Sep 26, 2022
43d7193
feat: added auto-relase and logger to use metadata
jainaman1497 Sep 26, 2022
f7e20c5
feat: added auto-relase and logger to use metadata
jainaman1497 Sep 26, 2022
ee634eb
feat: added auto-relase and logger to use metadata
jainaman1497 Sep 26, 2022
123b186
Merge https://github.com/Safe-Security/logger
jainaman1497 Sep 27, 2022
39cab49
Update release.yml
amanjain14 Sep 30, 2022
c41cb6a
Update release.yml
amanjain14 Sep 30, 2022
bd839a5
fix: review feedbacks
jainaman1497 Sep 30, 2022
09060d5
fix: updated metadata to exclude error object
amanjain14 Oct 12, 2022
5af2adc
Merge pull request #1 from Safe-Security/main
amanjain14 Oct 12, 2022
bc1e16d
fix: custom formatter for error
jainaman1497 Oct 12, 2022
63ef570
Merge branch 'main' of github.com:amanjain14/logger
jainaman1497 Oct 12, 2022
52209e7
fix: updated based on feedback
jainaman1497 Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ export const levels = winston.config.npm.levels;

export type Logger = winston.Logger;

/* A custom format that is used to format the error object. */
const formatError = winston.format(info => {
if ("error" in info && info.error instanceof Error) {
const {
error: { message, stack, ...rest }
} = info;
info.error = { message, stack, ...rest };
}

return info;
});

export const createLogger = (
{
logLevel = "info",
Expand All @@ -32,8 +44,17 @@ export const createLogger = (

// moves all the other fields in the message to `metadata` property
metadata({
fillExcept: ["message", "level", "timestamp", "service", "type"]
fillExcept: [
"message",
"level",
"timestamp",
"service",
"type",
"error"
]
}),
// custom formatter to format the "error" property
formatError(),

// default log format is JSON
json()
Expand Down
8 changes: 7 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ const { createLogger } = require("logger-safe-security");
const logger = createLogger({ service: "sample" });

logger.info("This is a sample logger");
logger.info("This is a sample logger with more information", { planet: "Earth" });
logger.info("This is a sample logger with more information", {
planet: "Earth",
});

/* Logging the error property. */
const err = new Error("This is a sample Error");
logger.info("Error occurred while performing the operation", { error: err });
7 changes: 6 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ import { createLogger } from "logger-safe-security";
const logger = createLogger({ service: "sample" });

logger.info("This is a sample logger");
logger.info("This is a sample logger with more information", { planet: "Earth" });
logger.info("This is a sample logger with more information", { planet: "Earth" });


/* Logging the error property. */
const err = new Error("This is a sample Error");
logger.info("Error occurred while performing the operation", { error: err });