Thanks to visit codestin.com
Credit goes to github.com

Skip to content

p-sw/nestlogged

Repository files navigation

NestJS Logging Decorators

This package provides some decorations to make NestJS logging simpler.
It only uses Logger provided by @nestjs/common package and some dependencies required for nestjs.

Installation

npm install nestlogged

or

yarn add nestlogged

More Info

Wiki


Contributor Guide

This project is a monorepo consisting of two packages: nestlogged and nestlogged-fastify. nestlogged is the base package containing the core functionalities, while nestlogged-fastify is a patched version with some code modified for compatibility with the Fastify platform.

Therefore, a special patching system is in place to synchronize code between the two packages. Please follow the workflows below when contributing.

Patch System Overview

  • packages/nestlogged/src: Contains the original source code. Most feature additions and bug fixes should be done here.
  • packages/nestlogged-fastify/src: Contains the source code with Fastify patches applied. This directory is generated by the patch:import command and is not tracked by Git.
  • packages/nestlogged-fastify/patch: Stores the .patch files that contain the differences between the original (nestlogged) and the modified (nestlogged-fastify) versions. Git only tracks the files in this directory.

Workflow 1: Setting Up the nestlogged-fastify Development Environment

When you first clone the repository, the nestlogged-fastify/src directory is empty. To modify or test the nestlogged-fastify package, you must first set up the development environment by running the following command:

# Copies the source code from nestlogged and applies the patches
# from the patch directory to create the nestlogged-fastify/src directory.
pnpm run patch:import

Workflow 2: Modifying nestlogged-fastify Directly

If you need to modify Fastify-specific code, follow these steps:

  1. If necessary, run pnpm run patch:import to ensure the nestlogged-fastify/src directory is up-to-date.

  2. Modify the desired file(s) within packages/nestlogged-fastify/src.

  3. Once your modifications are complete, run the following command to export the changes back into a .patch file:

    # Updates the .patch files in the nestlogged-fastify/patch/ directory
    # based on the modified contents of nestlogged-fastify/src.
    pnpm run patch:export

Workflow 3: Syncing Changes from nestlogged to nestlogged-fastify

This is the most critical workflow, used when you've modified a file in nestlogged and need to propagate those changes to nestlogged-fastify.

For example, if you have modified packages/nestlogged/src/logged/override.ts, run the following command to sync the changes:

# pnpm run patch:sync <relative/path/from/nestlogged/src>
pnpm run patch:sync logged/override.ts

Case A: Automatic Merge Success

If there are no conflicts, the script automatically merges the changes from nestlogged with the existing fastify patches. Afterward, it automatically exports a new .patch file with the updated content. Everything is handled automatically; you just need to commit the results.

Case B: Conflict Occurs

If the changes from nestlogged conflict with the existing patches, the script will fail and leave conflict markers (<<<<<<<, =======, >>>>>>>) in the corresponding nestlogged-fastify file, just like a standard git conflict.

In this case, you must manually resolve the conflict by following these steps:

  1. Open the file with the conflict (e.g., packages/nestlogged-fastify/src/logged/override.ts).

  2. Look for the conflict markers, merge the changes logically, and save the file.

  3. Once the conflict is resolved, you must run patch:export to generate a new, correct .patch file.

    pnpm run patch:export

The manually merged content has now been saved as the new patch.

Publishing Packages

Due to the dependency of nestlogged-fastify on nestlogged, a specific procedure must be followed to publish the packages correctly.

  1. Publish nestlogged: First, publish the base package. Make sure its version is correctly updated in packages/nestlogged/package.json.

  2. Update Dependency in nestlogged-fastify: Manually edit packages/nestlogged-fastify/package.json. Find the nestlogged dependency under dependencies and update its version to the one you just published.

    // packages/nestlogged-fastify/package.json
    "dependencies": {
      "nestlogged": "^3.8.0" // <-- Change this to the new version
    }
  3. Install Dependencies: Run pnpm install from the root of the project. This will update the pnpm-lock.yaml file and ensure your local node_modules has the correct version of nestlogged.

    pnpm install
  4. Build and Publish nestlogged-fastify: Now, you can build and publish the nestlogged-fastify package. The publish:fastify script automatically runs patch:import and the build process, ensuring all patches are applied correctly before publishing.

    pnpm run publish:fastify

Following these steps ensures that nestlogged-fastify is always published against the correct version of nestlogged.

About

A NestJS Logger Decorator Library

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published