Skip to content

Commit

Permalink
Merge pull request #3 from cabinetoffice/feature/NTRNL-242-logging-pa…
Browse files Browse the repository at this point in the history
…ckage-update

Update logging package and Readme
  • Loading branch information
Mouhajer-CO authored Nov 28, 2023
2 parents c6a1529 + 095b9f7 commit aa2d02c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
# Node Logging
# Logging

## Overview and Scope

The logging is a dedicated component in the software project responsible for recording and managing log entries for NodeJS projects. It separates the concerns of logging from the core application code and offers several advantages like clean code, customisation configurations of levels, formats etc and it can can be easily integrated with log analysis tools and external services. It will give us a reusable and consistent format and structure throughout the application/s, and thanks to that we can improve performance monitoring and security auditing.

The logger module integrates other best practice configurations and tools, such as Prettier for code formatting, a linter for code quality, and includes a Makefile for task automation, and other tools. These tools help maintain code quality, consistency, and automate routine development tasks.

## Installing

```sh
npm i @co-digital/logging
```

### Config variables

Following configs will need to be added as environment variables to the application

Key | Description | Example Value | Required |
----------------|--------------------------- |------------------------- |---------- |
LOG_LEVEL | Logging levels | `info` (Log only if info.level is less than or equal to this level) | True |
HUMAN | Formatting messages form (default JSON) | `true` (Enable human formatting for log messages) | False |

## Files Structure

Directory Path | Description
Expand Down Expand Up @@ -38,13 +53,16 @@ It also provides methods for request-based logging at each level, such as `debug

## Integration

To integrate the module for testing purposes into your Node.js project, use the following command:
`npm install username/repo#branchName --save`. Once it is installed, you need to create a `logger.ts` utility, as shown below, and use it when required. Obviously we are going to use the singleton pattern.
```sh
npm i @co-digital/logging
```

Once it is installed, you need to create a `logger.ts` utility, as shown below, and use it when required. Obviously we are going to use the singleton pattern.

```typescript
// logger.ts
import { ApplicationLogger } from "logging/lib/ApplicationLogger";
import { createLogger } from "logging";
import { ApplicationLogger } from "@co-digital/logging/lib/ApplicationLogger";
import { createLogger } from "@co-digital/logging";

import { APPLICATION_NAME } from "../config";

Expand All @@ -62,6 +80,17 @@ export const logger = (req: Request, _res: Response, next: NextFunction) => {
};
```

## ToDo
## Contributing

```sh
## Set Node/NPM env
nvm use

- Publishes the SDK on npm package registry
## Installing & Building
make build

## Testing & Coverage
make test
#or
make coverage
```
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@co-digital/node-logging",
"version": "1.0.0",
"name": "@co-digital/logging",
"version": "1.0.2",
"description": "A logging library for Node.JS applications in CO Digital.",
"homepage": "https://github.com/cabinetoffice/node-logging#README.md",
"main": "./lib/index.js",
Expand Down Expand Up @@ -48,5 +48,9 @@
},
"files": [
"./lib/**/*"
],
"keywords": [
"logging",
"winston"
]
}

0 comments on commit aa2d02c

Please sign in to comment.