axon-logger 1.0.2 → 1.0.3

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.
@@ -4,10 +4,11 @@
4
4
 
5
5
  AXON Logger version 1.0.1+ is fully compatible with browser environments (React, Next.js, Vue, Angular, etc.). The framework automatically detects the environment and uses appropriate storage mechanisms.
6
6
 
7
- ## What's Changed in v1.0.1
7
+ ## What's Changed in v1.0.2
8
8
 
9
- ✅ **Fixed**: Conditional imports for Node.js-only modules (`fs`, `path`)
10
- ✅ **Fixed**: Browser bundlers (webpack, Vite, etc.) no longer throw "Can't resolve 'fs'" errors
9
+ ✅ **Fixed**: Conditional imports for Node.js-only modules (`fs`, `path`) in FileManager
10
+ ✅ **Fixed**: Browser bundlers (webpack, Vite, Turbopack) no longer throw "Can't resolve 'fs'" errors
11
+ ✅ **Fixed**: Next.js 16 Turbopack compatibility
11
12
  ✅ **Added**: Automatic environment detection
12
13
  ✅ **Added**: Browser-specific storage using localStorage/IndexedDB
13
14
 
@@ -294,25 +295,18 @@ AXON automatically uses the best available storage:
294
295
 
295
296
  ### Issue: "Can't resolve 'fs'" error in Next.js
296
297
 
297
- **Solution**: Update to axon-logger v1.0.1+
298
+ **Solution**: Update to axon-logger v1.0.2+
298
299
 
299
- If still seeing errors, add to `next.config.ts`:
300
+ ```bash
301
+ npm install axon-logger@latest
302
+ ```
300
303
 
301
- ```typescript
302
- const nextConfig = {
303
- webpack: (config, { isServer }) => {
304
- if (!isServer) {
305
- config.resolve.fallback = {
306
- ...config.resolve.fallback,
307
- fs: false,
308
- path: false,
309
- };
310
- }
311
- return config;
312
- },
313
- };
304
+ If still seeing errors after update, try clearing cache:
314
305
 
315
- export default nextConfig;
306
+ ```bash
307
+ rm -rf .next node_modules
308
+ npm install
309
+ npm run build
316
310
  ```
317
311
 
318
312
  ### Issue: Logs not persisting across page reloads
@@ -417,29 +411,23 @@ setInterval(async () => {
417
411
  }, 30000); // Every 30 seconds
418
412
  ```
419
413
 
420
- ## Migration from v1.0.0 to v1.0.1
414
+ ## Migration from v1.0.0 to v1.0.2
421
415
 
422
416
  No breaking changes! Just update:
423
417
 
424
418
  ```bash
425
- npm update axon-logger
419
+ npm install axon-logger@latest
426
420
  ```
427
421
 
428
- If you were using webpack fallbacks, you can remove them:
422
+ Clear build cache if needed:
429
423
 
430
- ```typescript
431
- // next.config.ts - CAN BE REMOVED in v1.0.1+
432
- const nextConfig = {
433
- webpack: (config, { isServer }) => {
434
- if (!isServer) {
435
- config.resolve.fallback = {
436
- fs: false, // ← No longer needed
437
- path: false // ← No longer needed
438
- };
439
- }
440
- return config;
441
- },
442
- };
424
+ ```bash
425
+ # Next.js
426
+ rm -rf .next
427
+
428
+ # General
429
+ rm -rf node_modules
430
+ npm install
443
431
  ```
444
432
 
445
433
  ## Browser Support
@@ -479,7 +467,7 @@ See full examples at:
479
467
 
480
468
  - **NPM**: https://www.npmjs.com/package/axon-logger
481
469
  - **Issues**: Report via npm package page
482
- - **Version**: 1.0.1+
470
+ - **Version**: 1.0.2+ (Browser compatible)
483
471
 
484
472
  ## License
485
473
 
@@ -0,0 +1,240 @@
1
+ # AXON Logger - Quick Start for AI Assistants
2
+
3
+ ## TL;DR
4
+
5
+ ```bash
6
+ npm install axon-logger
7
+ ```
8
+
9
+ ```typescript
10
+ import { Logger, LogLevel } from 'axon-logger';
11
+
12
+ const logger = new Logger({
13
+ outputPath: './logs/app.txt', // Node.js: file path | Browser: storage key
14
+ level: LogLevel.INFO
15
+ });
16
+
17
+ logger.info('Hello AXON');
18
+ await logger.flush();
19
+ ```
20
+
21
+ ## Key Points
22
+
23
+ ✅ **Works in both Node.js and Browser** (React, Next.js, Vue, Angular)
24
+ ✅ **No configuration needed** for browser environments
25
+ ✅ **30-60% fewer tokens** than JSON logging
26
+ ✅ **Automatic environment detection**
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install axon-logger
32
+ ```
33
+
34
+ ## Node.js Usage
35
+
36
+ ```typescript
37
+ import { Logger, LogLevel } from 'axon-logger';
38
+
39
+ const logger = new Logger({
40
+ outputPath: './logs/app.txt',
41
+ level: LogLevel.INFO
42
+ });
43
+
44
+ logger.info('Application started');
45
+ logger.error('Error occurred', { code: 500 });
46
+
47
+ await logger.flush();
48
+ await logger.close();
49
+ ```
50
+
51
+ ## Browser Usage (React, Next.js, Vue, Angular)
52
+
53
+ ```typescript
54
+ import { Logger, LogLevel } from 'axon-logger';
55
+
56
+ // Automatically uses localStorage/IndexedDB
57
+ const logger = new Logger({
58
+ outputPath: 'app-logs', // Storage key, not file path
59
+ level: LogLevel.INFO
60
+ });
61
+
62
+ logger.info('User action', { action: 'click' });
63
+ await logger.flush();
64
+ ```
65
+
66
+ ## Next.js Client Component
67
+
68
+ ```typescript
69
+ 'use client';
70
+
71
+ import { Logger, LogLevel } from 'axon-logger';
72
+
73
+ const logger = new Logger({
74
+ outputPath: 'nextjs-logs',
75
+ level: LogLevel.INFO
76
+ });
77
+
78
+ export default function MyComponent() {
79
+ const handleClick = () => {
80
+ logger.info('Button clicked');
81
+ };
82
+
83
+ return <button onClick={handleClick}>Click Me</button>;
84
+ }
85
+ ```
86
+
87
+ ## Configuration Options
88
+
89
+ ```typescript
90
+ const logger = new Logger({
91
+ outputPath: './logs/app.txt', // Required
92
+ level: LogLevel.INFO, // Required
93
+ maxFileSize: 10 * 1024 * 1024, // Optional: 10MB
94
+ rotationInterval: 'daily', // Optional: 'hourly' | 'daily' | 'weekly' | 'none'
95
+ bufferSize: 100, // Optional: buffer entries
96
+ flushInterval: 5000, // Optional: auto-flush ms
97
+ omitNullValues: true, // Optional: skip nulls
98
+ fieldAliases: { // Optional: shorten fields
99
+ timestamp: 't',
100
+ level: 'l',
101
+ message: 'm'
102
+ }
103
+ });
104
+ ```
105
+
106
+ ## Log Levels
107
+
108
+ ```typescript
109
+ logger.debug('Debug info'); // LogLevel.DEBUG (0)
110
+ logger.info('Information'); // LogLevel.INFO (1)
111
+ logger.warn('Warning'); // LogLevel.WARN (2)
112
+ logger.error('Error'); // LogLevel.ERROR (3)
113
+ logger.fatal('Critical error'); // LogLevel.FATAL (4)
114
+ ```
115
+
116
+ ## Advanced Features
117
+
118
+ ### Section Markers
119
+
120
+ ```typescript
121
+ logger.mark('payment-start');
122
+ logger.info('Processing payment');
123
+ logger.mark('payment-end');
124
+ ```
125
+
126
+ ### Global Metadata
127
+
128
+ ```typescript
129
+ logger.setGlobalMetadata({
130
+ appVersion: '1.0.0',
131
+ environment: 'production'
132
+ });
133
+
134
+ logger.info('Event'); // Includes global metadata
135
+ ```
136
+
137
+ ### Download Logs (Browser)
138
+
139
+ ```typescript
140
+ const fileManager = logger.getFileManager();
141
+ if ('downloadLogs' in fileManager) {
142
+ await fileManager.downloadLogs();
143
+ }
144
+ ```
145
+
146
+ ## Common Patterns
147
+
148
+ ### Express.js Middleware
149
+
150
+ ```typescript
151
+ app.use((req, res, next) => {
152
+ logger.info('Request', {
153
+ method: req.method,
154
+ path: req.path
155
+ });
156
+ next();
157
+ });
158
+ ```
159
+
160
+ ### Error Handling
161
+
162
+ ```typescript
163
+ try {
164
+ // ... code
165
+ } catch (error) {
166
+ logger.error('Operation failed', {
167
+ error: error.message,
168
+ stack: error.stack
169
+ });
170
+ }
171
+ ```
172
+
173
+ ### Cleanup on Shutdown
174
+
175
+ ```typescript
176
+ process.on('SIGTERM', async () => {
177
+ await logger.flush();
178
+ await logger.close();
179
+ process.exit(0);
180
+ });
181
+ ```
182
+
183
+ ## Troubleshooting
184
+
185
+ ### "Can't resolve 'fs'" in Next.js
186
+
187
+ **Solution**: Update to latest version
188
+
189
+ ```bash
190
+ npm install axon-logger@latest
191
+ rm -rf .next
192
+ npm run build
193
+ ```
194
+
195
+ ### Logs not persisting
196
+
197
+ **Solution**: Call flush before exit
198
+
199
+ ```typescript
200
+ await logger.flush();
201
+ ```
202
+
203
+ ## TOON Format Example
204
+
205
+ Input:
206
+ ```typescript
207
+ logger.info('User login', { userId: 123, email: 'user@example.com' });
208
+ ```
209
+
210
+ Output (TOON):
211
+ ```
212
+ timestamp: 1705334400000, level: INFO, message: User login, userId: 123, email: user@example.com
213
+ ```
214
+
215
+ vs JSON (more tokens):
216
+ ```json
217
+ {"timestamp":1705334400000,"level":"INFO","message":"User login","userId":123,"email":"user@example.com"}
218
+ ```
219
+
220
+ ## Performance
221
+
222
+ - **Token Reduction**: 30-60% vs JSON
223
+ - **Throughput**: 80,000+ logs/second
224
+ - **Memory**: ~1-2MB per 1000 entries
225
+ - **Latency**: <1ms per log (buffered)
226
+
227
+ ## Documentation
228
+
229
+ - **Full Guide**: `INTEGRATION_GUIDE.md`
230
+ - **Browser Guide**: `BROWSER_COMPATIBILITY.md`
231
+ - **API Docs**: `docs/API.md`
232
+ - **NPM**: https://www.npmjs.com/package/axon-logger
233
+
234
+ ## Version
235
+
236
+ Current: **1.0.2** (Browser compatible)
237
+
238
+ ## License
239
+
240
+ MIT - Free for commercial and personal use
package/dist/index.d.ts CHANGED
@@ -5,7 +5,10 @@
5
5
  export { Logger, LogLevel, LogEntry, LoggerConfig, ResolvedConfig, Environment, MetadataFilter, DEFAULT_CONFIG, detectEnvironment, loadFromEnvironment, loadFromFile, mergeConfigurations } from './logger';
6
6
  export { TOONSerializer, TOONSerializerConfig } from './serializer';
7
7
  export { TOONParser, StreamingParser } from './parser';
8
- export { FileManager, BrowserFileManager, FileManagerConfig, RotationMetadata } from './file-manager';
8
+ export { BrowserFileManager, FileManagerConfig, RotationMetadata } from './file-manager';
9
+ export type { FileManager } from './file-manager/FileManager';
10
+ export type { LogExtractor } from './extractor/LogExtractor';
9
11
  export { TokenCounter } from './utils';
10
- export { LogExtractor } from './extractor';
12
+ export declare const loadFileManager: () => Promise<typeof import("./file-manager").FileManager>;
13
+ export declare const loadLogExtractor: () => Promise<typeof import("./extractor/LogExtractor").LogExtractor>;
11
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,WAAW,EACX,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,cAAc,EACd,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,UAAU,EACV,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,YAAY,EACb,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,YAAY,EACb,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,WAAW,EACX,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,cAAc,EACd,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,UAAU,EACV,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EACL,YAAY,EACb,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,eAAe,4DAM3B,CAAC;AAEF,eAAO,MAAM,gBAAgB,uEAM5B,CAAC"}
package/dist/index.js CHANGED
@@ -3,8 +3,41 @@
3
3
  * AXON - Token-Oriented Logging Framework
4
4
  * Main export file
5
5
  */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
6
39
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.LogExtractor = exports.TokenCounter = exports.BrowserFileManager = exports.FileManager = exports.StreamingParser = exports.TOONParser = exports.TOONSerializer = exports.mergeConfigurations = exports.loadFromFile = exports.loadFromEnvironment = exports.detectEnvironment = exports.DEFAULT_CONFIG = exports.LogLevel = exports.Logger = void 0;
40
+ exports.loadLogExtractor = exports.loadFileManager = exports.TokenCounter = exports.BrowserFileManager = exports.StreamingParser = exports.TOONParser = exports.TOONSerializer = exports.mergeConfigurations = exports.loadFromFile = exports.loadFromEnvironment = exports.detectEnvironment = exports.DEFAULT_CONFIG = exports.LogLevel = exports.Logger = void 0;
8
41
  // Logger exports
9
42
  var logger_1 = require("./logger");
10
43
  Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
@@ -23,12 +56,25 @@ Object.defineProperty(exports, "TOONParser", { enumerable: true, get: function (
23
56
  Object.defineProperty(exports, "StreamingParser", { enumerable: true, get: function () { return parser_1.StreamingParser; } });
24
57
  // File Manager exports
25
58
  var file_manager_1 = require("./file-manager");
26
- Object.defineProperty(exports, "FileManager", { enumerable: true, get: function () { return file_manager_1.FileManager; } });
27
59
  Object.defineProperty(exports, "BrowserFileManager", { enumerable: true, get: function () { return file_manager_1.BrowserFileManager; } });
28
60
  // Utils exports
29
61
  var utils_1 = require("./utils");
30
62
  Object.defineProperty(exports, "TokenCounter", { enumerable: true, get: function () { return utils_1.TokenCounter; } });
31
- // Extractor exports
32
- var extractor_1 = require("./extractor");
33
- Object.defineProperty(exports, "LogExtractor", { enumerable: true, get: function () { return extractor_1.LogExtractor; } });
63
+ // Dynamic imports for Node.js only (prevents bundling in browser)
64
+ const loadFileManager = async () => {
65
+ if (typeof window !== 'undefined') {
66
+ throw new Error('FileManager is only available in Node.js. Use BrowserFileManager for browser environments.');
67
+ }
68
+ const { FileManager } = await Promise.resolve().then(() => __importStar(require('./file-manager/FileManager')));
69
+ return FileManager;
70
+ };
71
+ exports.loadFileManager = loadFileManager;
72
+ const loadLogExtractor = async () => {
73
+ if (typeof window !== 'undefined') {
74
+ throw new Error('LogExtractor is only available in Node.js.');
75
+ }
76
+ const { LogExtractor } = await Promise.resolve().then(() => __importStar(require('./extractor/LogExtractor')));
77
+ return LogExtractor;
78
+ };
79
+ exports.loadLogExtractor = loadLogExtractor;
34
80
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";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EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAChH,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,wDAAa,4BAA4B,GAAC,CAAC;IACnE,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AANW,QAAA,eAAe,mBAM1B;AAEK,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;IACzC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,EAAE,YAAY,EAAE,GAAG,wDAAa,0BAA0B,GAAC,CAAC;IAClE,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AANW,QAAA,gBAAgB,oBAM3B"}
package/package.json CHANGED
@@ -1,12 +1,24 @@
1
1
  {
2
2
  "name": "axon-logger",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A token-efficient logging framework using TOON (Token-Oriented Object Notation) format",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "browser": "./dist/index.js",
11
+ "node": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
7
16
  "browser": {
17
+ "./dist/file-manager/FileManager.js": "./dist/file-manager/BrowserFileManager.js",
8
18
  "./dist/extractor/LogExtractor.js": false,
9
- "./dist/cli/axon-cli.js": false
19
+ "./dist/cli/axon-cli.js": false,
20
+ "fs": false,
21
+ "path": false
10
22
  },
11
23
  "scripts": {
12
24
  "build": "tsc",