@dismissible/nestjs-logger 0.0.2-canary.738340d.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # @dismissible/nestjs-logger
2
+
3
+ A flexible logging module for NestJS applications in the Dismissible ecosystem.
4
+
5
+ > **Part of the Dismissible API** - This library is part of the [Dismissible API](https://dismissible.io) ecosystem. Visit [dismissible.io](https://dismissible.io) for more information and documentation.
6
+
7
+ ## Overview
8
+
9
+ This library provides a standardized logging interface (`IDismissibleLogger`) and a default console logger implementation. It's designed to be easily replaceable with custom logging implementations (e.g., Winston, Pino, etc.) while maintaining a consistent API across the Dismissible ecosystem.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @dismissible/nestjs-logger
15
+ ```
16
+
17
+ ## Getting Started
18
+
19
+ ### Basic Usage
20
+
21
+ The simplest way to use the logger is with the default console logger:
22
+
23
+ ```typescript
24
+ import { Module } from '@nestjs/common';
25
+ import { LoggerModule } from '@dismissible/nestjs-logger';
26
+
27
+ @Module({
28
+ imports: [
29
+ LoggerModule.forRoot({
30
+ // Uses default ConsoleLogger if not specified
31
+ }),
32
+ ],
33
+ })
34
+ export class AppModule {}
35
+ ```
36
+
37
+ ### Using the Logger in Your Services
38
+
39
+ ```typescript
40
+ import { Injectable, Inject } from '@nestjs/common';
41
+ import { DISMISSIBLE_LOGGER, IDismissibleLogger } from '@dismissible/nestjs-logger';
42
+
43
+ @Injectable()
44
+ export class MyService {
45
+ constructor(@Inject(DISMISSIBLE_LOGGER) private readonly logger: IDismissibleLogger) {}
46
+
47
+ doSomething() {
48
+ this.logger.debug('Debug message', { context: 'MyService' });
49
+ this.logger.info('Info message', { userId: 'user-123' });
50
+ this.logger.warn('Warning message', { itemId: 'item-456' });
51
+ this.logger.error('Error message', new Error('Something went wrong'), {
52
+ additionalContext: 'value',
53
+ });
54
+ }
55
+ }
56
+ ```
57
+
58
+ ### Custom Logger Implementation
59
+
60
+ You can provide your own logger implementation:
61
+
62
+ ```typescript
63
+ import { Module } from '@nestjs/common';
64
+ import { LoggerModule, IDismissibleLogger } from '@dismissible/nestjs-logger';
65
+ import * as winston from 'winston';
66
+
67
+ class WinstonLogger implements IDismissibleLogger {
68
+ private logger = winston.createLogger({
69
+ // Your Winston configuration
70
+ });
71
+
72
+ debug(message: string, context?: object): void {
73
+ this.logger.debug(message, context);
74
+ }
75
+
76
+ info(message: string, context?: object): void {
77
+ this.logger.info(message, context);
78
+ }
79
+
80
+ warn(message: string, context?: object): void {
81
+ this.logger.warn(message, context);
82
+ }
83
+
84
+ error(message: string, error?: Error, context?: object): void {
85
+ this.logger.error(message, { error, ...context });
86
+ }
87
+ }
88
+
89
+ @Module({
90
+ imports: [
91
+ LoggerModule.forRoot({
92
+ logger: WinstonLogger,
93
+ }),
94
+ ],
95
+ })
96
+ export class AppModule {}
97
+ ```
98
+
99
+ ## API Reference
100
+
101
+ ### IDismissibleLogger Interface
102
+
103
+ ```typescript
104
+ interface IDismissibleLogger {
105
+ debug(message: string, context?: object): void;
106
+ info(message: string, context?: object): void;
107
+ warn(message: string, context?: object): void;
108
+ error(message: string, error?: Error, context?: object): void;
109
+ }
110
+ ```
111
+
112
+ ### LoggerModule
113
+
114
+ #### `LoggerModule.forRoot(options)`
115
+
116
+ Configures the logger module with the provided options.
117
+
118
+ **Options:**
119
+
120
+ - `logger?: Type<IDismissibleLogger>` - Custom logger class (defaults to `Logger`)
121
+
122
+ **Returns:** `DynamicModule`
123
+
124
+ ## Global Module
125
+
126
+ The `LoggerModule` is registered as a global module, so you only need to import it once in your root module. The logger will be available throughout your application via dependency injection.
127
+
128
+ ## Related Packages
129
+
130
+ This logger is used by other Dismissible packages:
131
+
132
+ - `@dismissible/nestjs-dismissible` - Main dismissible service
133
+ - `@dismissible/nestjs-storage` - Storage adapters
134
+ - `@dismissible/nestjs-postgres-storage` - PostgreSQL storage adapter
135
+
136
+ ## License
137
+
138
+ MIT
package/jest.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ export default {
2
+ displayName: 'logger',
3
+ preset: '../../jest.preset.js',
4
+ testEnvironment: 'node',
5
+ transform: {
6
+ '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.json' }],
7
+ },
8
+ moduleFileExtensions: ['ts', 'js', 'html'],
9
+ coverageDirectory: '../../coverage/libs/logger',
10
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@dismissible/nestjs-logger",
3
+ "version": "0.0.2-canary.738340d.0",
4
+ "description": "Console logger module for Dismissible applications",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./src/index.mjs",
10
+ "require": "./src/index.js",
11
+ "types": "./src/index.d.ts"
12
+ }
13
+ },
14
+ "dependencies": {},
15
+ "peerDependencies": {
16
+ "@nestjs/common": "^11.0.0",
17
+ "@nestjs/core": "^11.0.0",
18
+ "class-validator": "^0.14.0",
19
+ "class-transformer": "^0.5.0"
20
+ },
21
+ "peerDependenciesMeta": {
22
+ "@nestjs/common": {
23
+ "optional": false
24
+ },
25
+ "@nestjs/core": {
26
+ "optional": false
27
+ },
28
+ "class-validator": {
29
+ "optional": false
30
+ },
31
+ "class-transformer": {
32
+ "optional": false
33
+ }
34
+ },
35
+ "keywords": [
36
+ "nestjs",
37
+ "logger",
38
+ "logging"
39
+ ],
40
+ "author": "",
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": ""
45
+ }
46
+ }
package/project.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "logger",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/logger/src",
5
+ "projectType": "library",
6
+ "tags": [],
7
+ "targets": {
8
+ "build": {
9
+ "executor": "@nx/js:tsc",
10
+ "outputs": ["{options.outputPath}"],
11
+ "options": {
12
+ "outputPath": "dist/libs/logger",
13
+ "main": "libs/logger/src/index.ts",
14
+ "tsConfig": "libs/logger/tsconfig.lib.json",
15
+ "assets": ["libs/logger/package.json", "libs/logger/README.md"],
16
+ "generatePackageJson": true
17
+ }
18
+ },
19
+ "lint": {
20
+ "executor": "@nx/eslint:lint",
21
+ "outputs": ["{options.outputFile}"],
22
+ "options": {
23
+ "lintFilePatterns": ["libs/logger/**/*.ts"]
24
+ }
25
+ },
26
+ "test": {
27
+ "executor": "@nx/jest:jest",
28
+ "outputs": ["{workspaceRoot}/coverage/libs/logger"],
29
+ "options": {
30
+ "jestConfig": "libs/logger/jest.config.ts",
31
+ "passWithNoTests": true
32
+ }
33
+ },
34
+ "npm-publish": {
35
+ "executor": "nx:run-commands",
36
+ "options": {
37
+ "command": "npm publish --access public",
38
+ "cwd": "dist/libs/logger"
39
+ }
40
+ }
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './logger';
2
+ export * from './logger.interface';
3
+ export * from './logger.module';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Injection token for the logger provider.
3
+ */
4
+ export const DISMISSIBLE_LOGGER = Symbol('DISMISSIBLE_LOGGER');
5
+
6
+ /**
7
+ * Interface for logger providers.
8
+ */
9
+ export interface IDismissibleLogger {
10
+ /**
11
+ * Log a debug message.
12
+ */
13
+ debug(message: string, context?: object): void;
14
+
15
+ /**
16
+ * Log an info message.
17
+ */
18
+ info(message: string, context?: object): void;
19
+
20
+ /**
21
+ * Log a warning message.
22
+ */
23
+ warn(message: string, context?: object): void;
24
+
25
+ /**
26
+ * Log an error message.
27
+ */
28
+ error(message: string, error?: Error, context?: object): void;
29
+ }
@@ -0,0 +1,25 @@
1
+ import { DynamicModule, Module, Type } from '@nestjs/common';
2
+ import { DISMISSIBLE_LOGGER, IDismissibleLogger } from './logger.interface';
3
+ import { Logger } from './logger';
4
+
5
+ export type IDismissibleLoggerModuleOptions = {
6
+ /** Custom logger provider implementation */
7
+ logger?: Type<IDismissibleLogger>;
8
+ };
9
+
10
+ @Module({})
11
+ export class LoggerModule {
12
+ static forRoot(options: IDismissibleLoggerModuleOptions): DynamicModule {
13
+ return {
14
+ module: LoggerModule,
15
+ providers: [
16
+ {
17
+ provide: DISMISSIBLE_LOGGER,
18
+ useClass: options.logger ?? Logger,
19
+ },
20
+ ],
21
+ exports: [DISMISSIBLE_LOGGER],
22
+ global: true,
23
+ };
24
+ }
25
+ }
package/src/logger.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { ConsoleLogger } from '@nestjs/common';
2
+ import { IDismissibleLogger } from './logger.interface';
3
+
4
+ export class Logger extends ConsoleLogger implements IDismissibleLogger {
5
+ info(message: string, context?: any[]): void {
6
+ super.log(message, context);
7
+ }
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.lib.json"
8
+ }
9
+ ],
10
+ "compilerOptions": {
11
+ "esModuleInterop": true
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "declaration": true,
6
+ "module": "commonjs",
7
+ "types": ["node"],
8
+ "emitDecoratorMetadata": true,
9
+ "experimentalDecorators": true,
10
+ "target": "ES2021"
11
+ },
12
+ "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"],
13
+ "include": ["src/**/*.ts"]
14
+ }