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.
npm install nestlogged
or
yarn add nestlogged
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.
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 thepatch: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.
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
If you need to modify Fastify-specific code, follow these steps:
-
If necessary, run
pnpm run patch:import
to ensure thenestlogged-fastify/src
directory is up-to-date. -
Modify the desired file(s) within
packages/nestlogged-fastify/src
. -
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
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:
-
Open the file with the conflict (e.g.,
packages/nestlogged-fastify/src/logged/override.ts
). -
Look for the conflict markers, merge the changes logically, and save the file.
-
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.
Due to the dependency of nestlogged-fastify
on nestlogged
, a specific procedure must be followed to publish the packages correctly.
-
Publish
nestlogged
: First, publish the base package. Make sure its version is correctly updated inpackages/nestlogged/package.json
. -
Update Dependency in
nestlogged-fastify
: Manually editpackages/nestlogged-fastify/package.json
. Find thenestlogged
dependency underdependencies
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 }
-
Install Dependencies: Run
pnpm install
from the root of the project. This will update thepnpm-lock.yaml
file and ensure your localnode_modules
has the correct version ofnestlogged
.pnpm install
-
Build and Publish
nestlogged-fastify
: Now, you can build and publish thenestlogged-fastify
package. Thepublish:fastify
script automatically runspatch: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
.