@nexload-sdk/logger 1.0.1 โ†’ 1.0.2

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,124 @@
1
+ # @nexload-sdk/logger
2
+
3
+ <div align="center">
4
+ <img src="https://img.shields.io/badge/logger-pino--based-orange?style=flat-square" alt="logger" />
5
+ <img src="https://img.shields.io/badge/types-typescript-blue?style=flat-square" alt="typescript" />
6
+ <img src="https://img.shields.io/npm/v/@nexload-sdk/logger?style=flat-square" alt="npm version" />
7
+ <br><br>
8
+ <strong>Structured, high-performance logging with type safety, environment integration, and Next.js-ready wrappers.</strong>
9
+ </div>
10
+
11
+ ---
12
+
13
+ ## Features
14
+ - ๐Ÿš€ **Pino-powered:** Super-fast, versatile logger with pretty print out-of-the-box
15
+ - ๐Ÿ›ก๏ธ **Redacts sensitive fields:** Safe defaults for user/password/token/cookies
16
+ - ๐ŸŸฆ **TypeScript-first:** All logging operations and wrappers are fully typed
17
+ - ๐ŸŒ **Environment-aware:** Integrates `@nexload-sdk/env` for type-safe env config
18
+ - ๐Ÿ”Ž **Structured logs:** Timestamped, colored, and clearly formatted
19
+ - โš™๏ธ **Customizable:** Configure log level, service name, extra fields easily
20
+ - โšก **Next.js Friendly:** `withLogger()` helper makes SSR/data fetch logging a breeze
21
+ - ๐Ÿงฉ **Composable:** Use directly or via helper for operation tracking & perf
22
+
23
+ ---
24
+
25
+ ## Installation
26
+ ```bash
27
+ pnpm add @nexload-sdk/logger
28
+ # or
29
+ yarn add @nexload-sdk/logger
30
+ # or
31
+ npm install @nexload-sdk/logger
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Quick Start
37
+
38
+ ### Basic Logger Usage
39
+ ```typescript
40
+ import logger from '@nexload-sdk/logger';
41
+
42
+ logger.info('Service started');
43
+ logger.warn({ user: 'bob' }, 'Potential issue');
44
+ logger.error(new Error('Boom!'), 'Something failed');
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Advanced: Next.js/Operation Wrapper
50
+
51
+ Easily log SSR, API, or async operations โ€” complete with structured timing and error tracking.
52
+
53
+ ```typescript
54
+ import { withLogger } from '@nexload-sdk/logger';
55
+
56
+ export async function getServerSideProps() {
57
+ return withLogger({ route: '/home', type: 'get-data', functionName: 'getServerSideProps' }, async (timingShot) => {
58
+ timingShot('start-db');
59
+ // fetch DB...
60
+ timingShot('done-db');
61
+ return { props: { /* ... */ } };
62
+ });
63
+ }
64
+ ```
65
+
66
+ ---
67
+
68
+ ## API Reference
69
+
70
+ ### Default export: `logger`
71
+ - Fully-configured [pino](https://getpino.io/#/) instance
72
+ - Configured by env (`SERVICE_NAME`, `LOG_LEVEL`, ...), redact secrets by default
73
+ - Pretty/clean terminal output
74
+
75
+ ### `withLogger(options, fn)`
76
+ - Wrap sync/async code and get structured, perf-aware logs with automatic timing, error, completion logs
77
+ - Parameters:
78
+ - `options: { route: string, type: "render" | "get-data", functionName? }`
79
+ - `fn(timingShot) => T | Promise<T>` - Call `timingShot(name)` in your code for granular timings
80
+ - Returns: `Promise<T>`
81
+
82
+ ### Example error log
83
+ Logs errors with operation context:
84
+ ```typescript
85
+ await withLogger({ route: '/test', type: 'get-data', functionName: 'fetch' }, async () => {
86
+ throw new Error('fail')
87
+ });
88
+ // Output: ... { route: '/test', functionName: 'fetch', duration: '12.00ms' } Operation failed Error: fail
89
+ ```
90
+
91
+ ---
92
+
93
+ ## Configuration & Environment
94
+ - Uses `@nexload-sdk/env` for all env management
95
+ - By default, loads all variables in `$NodePreset` (i.e. `LOG_LEVEL`, `SERVICE_NAME`, ...)
96
+ - All sensitive fields like passwords/tokens/cookies are redacted from logs
97
+ - Formatting and fields customizable via standard pino config
98
+
99
+ ---
100
+
101
+ ## Best Practices
102
+ - Use `withLogger` for every major SSR/data/op in Next.js projects: automatic timing & errors
103
+ - Log structure, not raw strings: `{ userId, error }` โ€” better for search and alerts
104
+ - Set sensible LOG_LEVEL via env for prod/dev/test
105
+
106
+ ---
107
+
108
+ ## Contributing
109
+ 1. Fork this repo, create a feature branch (`feat/name`)
110
+ 2. Make your changes โ€” ensure all types, tests, and lint pass
111
+ 3. Use commit messages of the format: `feat(scope): your description`
112
+ 4. Open a pull request (PR) โ€” BugBot checks and feedback required
113
+
114
+ ---
115
+
116
+ ## License
117
+
118
+ MIT ยฉ GecutWeb Contributors
119
+
120
+ ---
121
+
122
+ ## Branding
123
+
124
+ Built by [NexLoad SDK](https://github.com/gecut/nexload-sdk) ยท Enabling modern, observable, and resilient applications with top-notch developer tools.