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

logger4node

Package Overview
Dependencies
Maintainers
0
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logger4node - npm Package Compare versions

Comparing version 1.0.32 to 1.0.33

32

package.json
{
"name": "logger4node",
"version": "1.0.32",
"version": "1.0.33",
"description": "",
"main": "index.js",
"scripts": {
"test": "npm run copy-test-logger && NODE_ENV=test node_modules/.bin/mocha './spec/**/*.spec.ts'",
"test": "NODE_ENV=test node_modules/.bin/mocha './spec/**/*.spec.ts'",
"build": "rm -rf dist/* && tsc -p ./ && npm run copy-build-files",

@@ -16,3 +16,19 @@ "copy-build-files": "cp ./README.md ./dist/README.md && cp package.json ./dist/package.json && cp package-lock.json ./dist/package-lock.json",

},
"keywords": [],
"keywords": [
"logger",
"logging",
"nodejs",
"typescript",
"log-level",
"json-logging",
"session-logging",
"debugging",
"monitoring",
"log-management",
"error-logging",
"express",
"production",
"devops",
"trace-logging"
],
"author": "yog27ray",

@@ -33,5 +49,5 @@ "license": "ISC",

"@types/mocha": "10.0.6",
"@types/node": "20.14.8",
"@types/node": "20.14.9",
"@types/sinon": "17.0.3",
"@typescript-eslint/eslint-plugin": "7.9.0",
"@typescript-eslint/eslint-plugin": "7.15.0",
"@typescript-eslint/parser": "7.14.1",

@@ -43,3 +59,3 @@ "chai": "4.4.1",

"eslint-plugin-import": "2.29.1",
"eslint-plugin-promise": "6.2.0",
"eslint-plugin-promise": "6.4.0",
"eslint-plugin-typescript": "0.14.0",

@@ -49,3 +65,3 @@ "flush-write-stream": "^2.0.0",

"node-tslint-rules": "1.20.3",
"nyc": "15.1.0",
"nyc": "17.0.0",
"sinon": "18.0.0",

@@ -57,3 +73,3 @@ "sinon-chai": "^3.7.0",

"tslint": "6.1.3",
"typescript": "5.4.5"
"typescript": "5.5.3"
},

@@ -60,0 +76,0 @@ "nyc": {

@@ -23,13 +23,13 @@ ![build](https://github.com/yog27ray/logger4node/actions/workflows/node.js.yml/badge.svg?branch=master)

```
3. Create file level logger.
3. Create logger instance.
```ts
const fileLogger = applicationLogger.instance('File1');
const loggerInstance = applicationLogger.instance('Instance1');
```
4. Log information
```ts
fileLogger.error('This is test log');
loggerInstance.error('This is test log');
```
Output:
```text
Error: Application:File1 This is test log
Error: Application:Instance1 This is test log
```

@@ -39,4 +39,6 @@

1. **JSON Logs**: Logging in json provide more information and is recommended for production deployments.
Json logging provide `time`, `source`, `request`, `extraData`, `stack`.
1. **JSON Logs**: JSON logging is recommended for production deployments as it provides more detailed information.
JSON logs include fields such as `time`, `source`, `request`, `extraData`, and `stack`.
To enable JSON logging, use the following configuration:
```ts

@@ -47,7 +49,110 @@ applicationLogger.setJsonLogging(true);

.
fileLogger.error('This is test log');
loggerInstance.error('This is test log');
```
Output:
```text
{"level":"error","time":"2024-07-01T07:07:54.877Z","className":"Application:File1","source":{"caller":"callerFunctionName","fileName":"fileName.ts","path":"file path","line":"13","column":"10"},"message":"This is test log","request":{},"extra":{},"stack":""}
{
"level": "error",
"time": "2024-07-01T07:07:54.877Z",
"className": "Application:Instance1",
"source": {
"caller": "callerFunctionName",
"fileName": "fileName.ts",
"path": "file path",
"line": "13",
"column": "10"
},
"message": "This is a test log",
"request": {},
"extra": {},
"stack": ""
}
```
This format ensures that logs contain comprehensive information, making it easier to debug and monitor applications in production environments.
2. **Github Link**: This feature enhances the logging library by providing a direct GitHub link that redirects to the
exact location in the code where the log is generated. This allows users to easily navigate the entire codebase from the logs.
```ts
const applicationLogger = new Logger4Node(
'Application',
{
github: {
org: 'yog27ray',
repo: 'logger4node',
commitHash: 'githubCommitHash',
basePath: 'project/root/path'
},
});
```
1. commitHash: The specific commit hash of the code.
2. org: The GitHub organization name.
3. repo: The name of the repository.
4. AbasePath: The absolute path to the root folder of the project.
By configuring these parameters, the logger will generate links that point to the exact lines in the GitHub repository, simplifying code navigation and debugging.
3. **Multiple Logging Patter**: This feature allows you to set different log severities for different instances of the logger.
```ts
applicationLogger.setLogLevel(LogSeverity.ERROR);
applicationLogger.setLogPattern('Application:*');
applicationLogger.setLogSeverityPattern(LogSeverity.INFO, 'Application:Instance1,Application:Instance2');
applicationLogger.setLogSeverityPattern(LogSeverity.DEBUG, 'Application:Instance3');
```
In the example above:
1. The default logging level is set to ERROR for all application logs.
2. For the logger instances Instance1 and Instance2, logs will include INFO level messages.
3. For the logger instance Instance3, logs will include DEBUG level messages.
This setup enables more granular control over logging by specifying different severity levels for specific logger instances.
4. **Track Session Log**: Often, it’s useful to track all logs that correspond to a single session to better understand
the code flow. You can also pass additional information to be preserved throughout the session. Below is the
configuration to enable this feature:
1. With Express Server:
```ts
app.use(Logger4Node.Trace.requestHandler((req: Request) => {
const sessionInformation = { user: 'userId' };
return sessionInformation;
}));
.
.
.
loggerInstance.error('This is test log');
```
After enabling this configuration, every log will include `request.id` and `sessionInformation` in the request object.
This helps track all logs generated by an HTTP call.
Example Output:
```json
{
"level": "error",
"time": "2024-07-01T07:07:54.877Z",
"className": "Application:Instance1",
"source": {
"caller": "callerFunctionName",
"fileName": "fileName.ts",
"path": "file path",
"line": "13",
"column": "10"
},
"message": "This is a test log",
"request": {
"id": "a15e7fc5-46b2-417d-9523-37a7c4dd467e",
"user": "userId"
},
"extra": {},
"stack": ""
}
```
3. Without Express Server: You can also start a new session wherever you need it in your application.
```ts
Logger4Node.Trace.startNewRequest(() => {
// your application logic
}, { user: 'userId' });
```

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.loggerSpy = exports.stringLogsToJSON = exports.printLogWithNewLineAndSlashNCharacter = exports.printLogSingleLine = exports.printLogWithSpecialTabCharacter = exports.printLogWithBackSlashCharacter = exports.printLogWithMultipleEndCharacters = exports.printFatalLogsInDifferentType = exports.printLogsInDifferentType = exports.printLogsWithExtraFields = exports.printLogsInDifferentLevel = exports.wait = void 0;
exports.loggerSpy = void 0;
exports.wait = wait;
exports.printLogsInDifferentLevel = printLogsInDifferentLevel;
exports.printLogsWithExtraFields = printLogsWithExtraFields;
exports.printLogsInDifferentType = printLogsInDifferentType;
exports.printFatalLogsInDifferentType = printFatalLogsInDifferentType;
exports.printLogWithMultipleEndCharacters = printLogWithMultipleEndCharacters;
exports.printLogWithBackSlashCharacter = printLogWithBackSlashCharacter;
exports.printLogWithSpecialTabCharacter = printLogWithSpecialTabCharacter;
exports.printLogSingleLine = printLogSingleLine;
exports.printLogWithNewLineAndSlashNCharacter = printLogWithNewLineAndSlashNCharacter;
exports.stringLogsToJSON = stringLogsToJSON;
const node_fs_1 = __importDefault(require("node:fs"));

@@ -16,3 +27,2 @@ const tail_1 = require("tail");

}
exports.wait = wait;
async function printLogsInDifferentLevel(logger) {

@@ -26,3 +36,2 @@ logger.verbose('verbose log');

}
exports.printLogsInDifferentLevel = printLogsInDifferentLevel;
async function printLogsWithExtraFields(logger) {

@@ -32,3 +41,2 @@ logger.log(logger_1.LogSeverity.ERROR, { extraField: 'extraValue' }, 'verbose log');

}
exports.printLogsWithExtraFields = printLogsWithExtraFields;
async function printLogsInDifferentType(logger) {

@@ -38,3 +46,2 @@ logger.error('this is ', 1, true, { key1: 1, value: 2 });

}
exports.printLogsInDifferentType = printLogsInDifferentType;
async function printFatalLogsInDifferentType(logger) {

@@ -44,3 +51,2 @@ logger.fatal('this is ', 1, true, { key1: 1, value: 2 });

}
exports.printFatalLogsInDifferentType = printFatalLogsInDifferentType;
async function printLogWithMultipleEndCharacters(logger) {

@@ -50,3 +56,2 @@ logger.error('this is line1\nline2\nline2', { var: 1, var2: 2 });

}
exports.printLogWithMultipleEndCharacters = printLogWithMultipleEndCharacters;
async function printLogWithBackSlashCharacter(logger) {

@@ -56,3 +61,2 @@ logger.error('this is line1 \\"', { var: 1, var2: 2 });

}
exports.printLogWithBackSlashCharacter = printLogWithBackSlashCharacter;
async function printLogWithSpecialTabCharacter(logger) {

@@ -62,3 +66,2 @@ logger.error('this is line1 \t');

}
exports.printLogWithSpecialTabCharacter = printLogWithSpecialTabCharacter;
async function printLogSingleLine(logger) {

@@ -68,3 +71,2 @@ logger.error('this is string');

}
exports.printLogSingleLine = printLogSingleLine;
async function printLogWithNewLineAndSlashNCharacter(logger) {

@@ -86,3 +88,2 @@ try {

}
exports.printLogWithNewLineAndSlashNCharacter = printLogWithNewLineAndSlashNCharacter;
const spyConsoleLog = [];

@@ -115,3 +116,2 @@ const loggerSpy = {

}
exports.stringLogsToJSON = stringLogsToJSON;
//# sourceMappingURL=test-logs.js.map

@@ -6,3 +6,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = exports.setLogSeverityPattern = exports.setLogPattern = exports.DisplaySeverityMap = exports.LogLevel = exports.LogSeverity = void 0;
exports.Logger = exports.DisplaySeverityMap = exports.LogLevel = exports.LogSeverity = void 0;
exports.setLogPattern = setLogPattern;
exports.setLogSeverityPattern = setLogSeverityPattern;
const util_1 = __importDefault(require("util"));

@@ -75,3 +77,2 @@ const trace_1 = require("../trace/trace");

}
exports.setLogPattern = setLogPattern;
function setLogSeverityPattern(logSeverityPattern, level, pattern) {

@@ -84,3 +85,2 @@ logSeverityPattern[level].positive.splice(0, logSeverityPattern[level].positive.length);

}
exports.setLogSeverityPattern = setLogSeverityPattern;
class Logger {

@@ -87,0 +87,0 @@ static errorStack(...args) {

@@ -1,2 +0,1 @@

/// <reference types="node" />
import http from 'http';

@@ -3,0 +2,0 @@ declare interface RequestInfo {

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