@dismissible/nestjs-logger 0.0.1

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/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@dismissible/nestjs-logger",
3
+ "version": "0.0.1",
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
+ "files": [
15
+ "src",
16
+ "README.md"
17
+ ],
18
+ "dependencies": {},
19
+ "peerDependencies": {
20
+ "@nestjs/common": "^11.0.0",
21
+ "@nestjs/core": "^11.0.0",
22
+ "class-validator": "^0.14.0",
23
+ "class-transformer": "^0.5.0"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "@nestjs/common": {
27
+ "optional": false
28
+ },
29
+ "@nestjs/core": {
30
+ "optional": false
31
+ },
32
+ "class-validator": {
33
+ "optional": false
34
+ },
35
+ "class-transformer": {
36
+ "optional": false
37
+ }
38
+ },
39
+ "keywords": [
40
+ "nestjs",
41
+ "logger",
42
+ "logging"
43
+ ],
44
+ "author": "",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/DismissibleIo/dismissible-api"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "type": "commonjs"
54
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './logger';
2
+ export * from './logger.interface';
3
+ export * from './logger.module';
4
+ export * from './null-logger';
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./logger"), exports);
5
+ tslib_1.__exportStar(require("./logger.interface"), exports);
6
+ tslib_1.__exportStar(require("./logger.module"), exports);
7
+ tslib_1.__exportStar(require("./null-logger"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/logger/src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,6DAAmC;AACnC,0DAAgC;AAChC,wDAA8B"}
@@ -0,0 +1,5 @@
1
+ import { ConsoleLogger } from '@nestjs/common';
2
+ import { IDismissibleLogger } from './logger.interface';
3
+ export declare class Logger extends ConsoleLogger implements IDismissibleLogger {
4
+ info(message: string, context?: any[]): void;
5
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Injection token for the logger provider.
3
+ */
4
+ export declare const DISMISSIBLE_LOGGER: unique symbol;
5
+ /**
6
+ * Interface for logger providers.
7
+ */
8
+ export interface IDismissibleLogger {
9
+ /**
10
+ * Log a debug message.
11
+ */
12
+ debug(message: string, context?: object): void;
13
+ /**
14
+ * Log an info message.
15
+ */
16
+ info(message: string, context?: object): void;
17
+ /**
18
+ * Log a warning message.
19
+ */
20
+ warn(message: string, context?: object): void;
21
+ /**
22
+ * Log an error message.
23
+ */
24
+ error(message: string, error?: Error, context?: object): void;
25
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DISMISSIBLE_LOGGER = void 0;
4
+ /**
5
+ * Injection token for the logger provider.
6
+ */
7
+ exports.DISMISSIBLE_LOGGER = Symbol('DISMISSIBLE_LOGGER');
8
+ //# sourceMappingURL=logger.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.interface.js","sourceRoot":"","sources":["../../../../libs/logger/src/logger.interface.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
package/src/logger.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ class Logger extends common_1.ConsoleLogger {
6
+ info(message, context) {
7
+ super.log(message, context);
8
+ }
9
+ }
10
+ exports.Logger = Logger;
11
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../libs/logger/src/logger.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAG/C,MAAa,MAAO,SAAQ,sBAAa;IACvC,IAAI,CAAC,OAAe,EAAE,OAAe;QACnC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;CACF;AAJD,wBAIC"}
@@ -0,0 +1,9 @@
1
+ import { DynamicModule, Type } from '@nestjs/common';
2
+ import { IDismissibleLogger } from './logger.interface';
3
+ export type IDismissibleLoggerModuleOptions = {
4
+ /** Custom logger provider implementation */
5
+ logger?: Type<IDismissibleLogger>;
6
+ };
7
+ export declare class LoggerModule {
8
+ static forRoot(options: IDismissibleLoggerModuleOptions): DynamicModule;
9
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var LoggerModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.LoggerModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const logger_interface_1 = require("./logger.interface");
8
+ const logger_1 = require("./logger");
9
+ let LoggerModule = LoggerModule_1 = class LoggerModule {
10
+ static forRoot(options) {
11
+ return {
12
+ module: LoggerModule_1,
13
+ providers: [
14
+ {
15
+ provide: logger_interface_1.DISMISSIBLE_LOGGER,
16
+ useClass: options.logger ?? logger_1.Logger,
17
+ },
18
+ ],
19
+ exports: [logger_interface_1.DISMISSIBLE_LOGGER],
20
+ global: true,
21
+ };
22
+ }
23
+ };
24
+ exports.LoggerModule = LoggerModule;
25
+ exports.LoggerModule = LoggerModule = LoggerModule_1 = tslib_1.__decorate([
26
+ (0, common_1.Module)({})
27
+ ], LoggerModule);
28
+ //# sourceMappingURL=logger.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.module.js","sourceRoot":"","sources":["../../../../libs/logger/src/logger.module.ts"],"names":[],"mappings":";;;;;AAAA,2CAA6D;AAC7D,yDAA4E;AAC5E,qCAAkC;AAQ3B,IAAM,YAAY,oBAAlB,MAAM,YAAY;IACvB,MAAM,CAAC,OAAO,CAAC,OAAwC;QACrD,OAAO;YACL,MAAM,EAAE,cAAY;YACpB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,qCAAkB;oBAC3B,QAAQ,EAAE,OAAO,CAAC,MAAM,IAAI,eAAM;iBACnC;aACF;YACD,OAAO,EAAE,CAAC,qCAAkB,CAAC;YAC7B,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF,CAAA;AAdY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,YAAY,CAcxB"}
@@ -0,0 +1,7 @@
1
+ import { IDismissibleLogger } from './logger.interface';
2
+ export declare class NullLogger implements IDismissibleLogger {
3
+ info(_message: string, _context?: object): void;
4
+ error(_message: string, _context?: object): void;
5
+ warn(_message: string, _context?: object): void;
6
+ debug(_message: string, _context?: object): void;
7
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NullLogger = void 0;
4
+ class NullLogger {
5
+ info(_message, _context) {
6
+ /* empty */
7
+ }
8
+ error(_message, _context) {
9
+ /* empty */
10
+ }
11
+ warn(_message, _context) {
12
+ /* empty */
13
+ }
14
+ debug(_message, _context) {
15
+ /* empty */
16
+ }
17
+ }
18
+ exports.NullLogger = NullLogger;
19
+ //# sourceMappingURL=null-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"null-logger.js","sourceRoot":"","sources":["../../../../libs/logger/src/null-logger.ts"],"names":[],"mappings":";;;AAEA,MAAa,UAAU;IACrB,IAAI,CAAC,QAAgB,EAAE,QAAiB;QACtC,WAAW;IACb,CAAC;IACD,KAAK,CAAC,QAAgB,EAAE,QAAiB;QACvC,WAAW;IACb,CAAC;IACD,IAAI,CAAC,QAAgB,EAAE,QAAiB;QACtC,WAAW;IACb,CAAC;IACD,KAAK,CAAC,QAAgB,EAAE,QAAiB;QACvC,WAAW;IACb,CAAC;CACF;AAbD,gCAaC"}