evlog 0.0.0-reserved → 0.1.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.
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Environment context automatically included in every log event
3
+ */
4
+ interface EnvironmentContext {
5
+ /** Service name (auto-detected from package.json or configurable) */
6
+ service: string;
7
+ /** Environment: 'development', 'production', 'test', etc. */
8
+ environment: 'development' | 'production' | 'test' | string;
9
+ /** Application version (auto-detected from package.json) */
10
+ version?: string;
11
+ /** Git commit hash (auto-detected from CI/CD env vars) */
12
+ commitHash?: string;
13
+ /** Deployment region (auto-detected from cloud provider env vars) */
14
+ region?: string;
15
+ }
16
+ /**
17
+ * Logger configuration options
18
+ */
19
+ interface LoggerConfig {
20
+ /** Environment context overrides */
21
+ env?: Partial<EnvironmentContext>;
22
+ /** Enable pretty printing (auto-detected: true in dev, false in prod) */
23
+ pretty?: boolean;
24
+ }
25
+ /**
26
+ * Base structure for all wide events
27
+ */
28
+ interface BaseWideEvent {
29
+ timestamp: string;
30
+ level: 'info' | 'error' | 'warn' | 'debug';
31
+ service: string;
32
+ environment: string;
33
+ version?: string;
34
+ commitHash?: string;
35
+ region?: string;
36
+ }
37
+ /**
38
+ * Wide event with arbitrary additional fields
39
+ */
40
+ type WideEvent = BaseWideEvent & Record<string, unknown>;
41
+ /**
42
+ * Request-scoped logger for building wide events
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const logger = useLogger(event)
47
+ * logger.set({ user: { id: '123' } })
48
+ * logger.set({ cart: { items: 3 } })
49
+ * // emit() is called automatically by the plugin
50
+ * ```
51
+ */
52
+ interface RequestLogger {
53
+ /**
54
+ * Add context to the wide event (shallow merge)
55
+ */
56
+ set: <T extends Record<string, unknown>>(context: T) => void;
57
+ /**
58
+ * Log an error and capture its details
59
+ */
60
+ error: (error: Error | string, context?: Record<string, unknown>) => void;
61
+ /**
62
+ * Emit the final wide event with all accumulated context
63
+ */
64
+ emit: (overrides?: Record<string, unknown>) => void;
65
+ /**
66
+ * Get the current accumulated context
67
+ */
68
+ getContext: () => Record<string, unknown>;
69
+ }
70
+ /**
71
+ * Log level type
72
+ */
73
+ type LogLevel = 'info' | 'error' | 'warn' | 'debug';
74
+ /**
75
+ * Simple logging API - as easy as console.log
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * log.info('auth', 'User logged in')
80
+ * log.error({ action: 'payment', error: 'failed' })
81
+ * ```
82
+ */
83
+ interface Log {
84
+ /**
85
+ * Log an info message or wide event
86
+ * @example log.info('auth', 'User logged in')
87
+ * @example log.info({ action: 'login', userId: '123' })
88
+ */
89
+ info(tag: string, message: string): void;
90
+ info(event: Record<string, unknown>): void;
91
+ /**
92
+ * Log an error message or wide event
93
+ * @example log.error('payment', 'Payment failed')
94
+ * @example log.error({ action: 'payment', error: 'declined' })
95
+ */
96
+ error(tag: string, message: string): void;
97
+ error(event: Record<string, unknown>): void;
98
+ /**
99
+ * Log a warning message or wide event
100
+ * @example log.warn('api', 'Rate limit approaching')
101
+ * @example log.warn({ action: 'api', remaining: 10 })
102
+ */
103
+ warn(tag: string, message: string): void;
104
+ warn(event: Record<string, unknown>): void;
105
+ /**
106
+ * Log a debug message or wide event
107
+ * @example log.debug('cache', 'Cache miss')
108
+ * @example log.debug({ action: 'cache', key: 'user_123' })
109
+ */
110
+ debug(tag: string, message: string): void;
111
+ debug(event: Record<string, unknown>): void;
112
+ }
113
+ /**
114
+ * Error options for creating structured errors
115
+ */
116
+ interface ErrorOptions {
117
+ /** What actually happened */
118
+ message: string;
119
+ /** Why this error occurred */
120
+ why?: string;
121
+ /** How to fix this issue */
122
+ fix?: string;
123
+ /** Link to documentation or more information */
124
+ link?: string;
125
+ /** The original error that caused this */
126
+ cause?: Error;
127
+ }
128
+ /**
129
+ * H3 event context with evlog logger attached
130
+ */
131
+ interface EvlogEventContext {
132
+ log?: RequestLogger;
133
+ }
134
+
135
+ export type { BaseWideEvent, EnvironmentContext, ErrorOptions, EvlogEventContext, Log, LogLevel, LoggerConfig, RequestLogger, WideEvent };
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,43 @@
1
+ import { EnvironmentContext } from './types.mjs';
2
+
3
+ /**
4
+ * Format duration for display
5
+ * < 1s: shows milliseconds (e.g., "42ms")
6
+ * >= 1s: shows seconds (e.g., "1.5s")
7
+ */
8
+ declare function formatDuration(ms: number): string;
9
+ /**
10
+ * Check if running on server
11
+ */
12
+ declare function isServer(): boolean;
13
+ /**
14
+ * Check if running on client
15
+ */
16
+ declare function isClient(): boolean;
17
+ /**
18
+ * Check if in development mode
19
+ */
20
+ declare function isDev(): boolean;
21
+ /**
22
+ * Auto-detect environment context from env variables
23
+ */
24
+ declare function detectEnvironment(): Partial<EnvironmentContext>;
25
+ declare const colors: {
26
+ readonly reset: "\u001B[0m";
27
+ readonly bold: "\u001B[1m";
28
+ readonly dim: "\u001B[2m";
29
+ readonly red: "\u001B[31m";
30
+ readonly green: "\u001B[32m";
31
+ readonly yellow: "\u001B[33m";
32
+ readonly blue: "\u001B[34m";
33
+ readonly magenta: "\u001B[35m";
34
+ readonly cyan: "\u001B[36m";
35
+ readonly white: "\u001B[37m";
36
+ readonly gray: "\u001B[90m";
37
+ };
38
+ /**
39
+ * Get color for log level
40
+ */
41
+ declare function getLevelColor(level: string): string;
42
+
43
+ export { colors, detectEnvironment, formatDuration, getLevelColor, isClient, isDev, isServer };
@@ -0,0 +1,43 @@
1
+ import { EnvironmentContext } from './types.js';
2
+
3
+ /**
4
+ * Format duration for display
5
+ * < 1s: shows milliseconds (e.g., "42ms")
6
+ * >= 1s: shows seconds (e.g., "1.5s")
7
+ */
8
+ declare function formatDuration(ms: number): string;
9
+ /**
10
+ * Check if running on server
11
+ */
12
+ declare function isServer(): boolean;
13
+ /**
14
+ * Check if running on client
15
+ */
16
+ declare function isClient(): boolean;
17
+ /**
18
+ * Check if in development mode
19
+ */
20
+ declare function isDev(): boolean;
21
+ /**
22
+ * Auto-detect environment context from env variables
23
+ */
24
+ declare function detectEnvironment(): Partial<EnvironmentContext>;
25
+ declare const colors: {
26
+ readonly reset: "\u001B[0m";
27
+ readonly bold: "\u001B[1m";
28
+ readonly dim: "\u001B[2m";
29
+ readonly red: "\u001B[31m";
30
+ readonly green: "\u001B[32m";
31
+ readonly yellow: "\u001B[33m";
32
+ readonly blue: "\u001B[34m";
33
+ readonly magenta: "\u001B[35m";
34
+ readonly cyan: "\u001B[36m";
35
+ readonly white: "\u001B[37m";
36
+ readonly gray: "\u001B[90m";
37
+ };
38
+ /**
39
+ * Get color for log level
40
+ */
41
+ declare function getLevelColor(level: string): string;
42
+
43
+ export { colors, detectEnvironment, formatDuration, getLevelColor, isClient, isDev, isServer };
package/dist/utils.mjs ADDED
@@ -0,0 +1,57 @@
1
+ function formatDuration(ms) {
2
+ if (ms < 1e3) {
3
+ return `${Math.round(ms)}ms`;
4
+ }
5
+ return `${(ms / 1e3).toFixed(2)}s`;
6
+ }
7
+ function isServer() {
8
+ return typeof window === "undefined";
9
+ }
10
+ function isClient() {
11
+ return typeof window !== "undefined";
12
+ }
13
+ function isDev() {
14
+ if (typeof process !== "undefined" && process.env.NODE_ENV) {
15
+ return process.env.NODE_ENV !== "production";
16
+ }
17
+ return true;
18
+ }
19
+ function detectEnvironment() {
20
+ const env = typeof process !== "undefined" ? process.env : {};
21
+ return {
22
+ environment: env.NODE_ENV || "development",
23
+ service: env.SERVICE_NAME || "app",
24
+ version: env.APP_VERSION,
25
+ commitHash: env.COMMIT_SHA || env.GITHUB_SHA || env.VERCEL_GIT_COMMIT_SHA || env.CF_PAGES_COMMIT_SHA,
26
+ region: env.VERCEL_REGION || env.AWS_REGION || env.FLY_REGION || env.CF_REGION
27
+ };
28
+ }
29
+ const colors = {
30
+ reset: "\x1B[0m",
31
+ bold: "\x1B[1m",
32
+ dim: "\x1B[2m",
33
+ red: "\x1B[31m",
34
+ green: "\x1B[32m",
35
+ yellow: "\x1B[33m",
36
+ blue: "\x1B[34m",
37
+ magenta: "\x1B[35m",
38
+ cyan: "\x1B[36m",
39
+ white: "\x1B[37m",
40
+ gray: "\x1B[90m"
41
+ };
42
+ function getLevelColor(level) {
43
+ switch (level) {
44
+ case "error":
45
+ return colors.red;
46
+ case "warn":
47
+ return colors.yellow;
48
+ case "info":
49
+ return colors.cyan;
50
+ case "debug":
51
+ return colors.gray;
52
+ default:
53
+ return colors.white;
54
+ }
55
+ }
56
+
57
+ export { colors, detectEnvironment, formatDuration, getLevelColor, isClient, isDev, isServer };
package/package.json CHANGED
@@ -1,7 +1,95 @@
1
1
  {
2
2
  "name": "evlog",
3
- "version": "0.0.0-reserved",
4
- "description": "Placeholder package",
5
- "main": "index.js",
6
- "license": "MIT"
7
- }
3
+ "version": "0.1.0",
4
+ "description": "Wide event logging library with structured error handling. Inspired by LoggingSucks.",
5
+ "author": "HugoRCD <contact@hrcd.fr>",
6
+ "homepage": "https://github.com/HugoRCD/evlog",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/HugoRCD/evlog.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/HugoRCD/evlog/issues"
13
+ },
14
+ "keywords": [
15
+ "logging",
16
+ "wide-events",
17
+ "structured-logging",
18
+ "errors",
19
+ "nuxt",
20
+ "nitro",
21
+ "typescript"
22
+ ],
23
+ "license": "MIT",
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.mts",
28
+ "import": "./dist/index.mjs"
29
+ },
30
+ "./nuxt": {
31
+ "types": "./dist/nuxt/module.d.mts",
32
+ "import": "./dist/nuxt/module.mjs"
33
+ },
34
+ "./nitro": {
35
+ "types": "./dist/nitro/plugin.d.mts",
36
+ "import": "./dist/nitro/plugin.mjs"
37
+ }
38
+ },
39
+ "main": "./dist/index.mjs",
40
+ "types": "./dist/index.d.mts",
41
+ "typesVersions": {
42
+ "*": {
43
+ ".": [
44
+ "./dist/index.d.mts"
45
+ ],
46
+ "nuxt": [
47
+ "./dist/nuxt/module.d.mts"
48
+ ],
49
+ "nitro": [
50
+ "./dist/nitro/plugin.d.mts"
51
+ ]
52
+ }
53
+ },
54
+ "files": [
55
+ "dist",
56
+ "README.md"
57
+ ],
58
+ "scripts": {
59
+ "build": "unbuild",
60
+ "dev:prepare": "unbuild --stub",
61
+ "release": "bun run lint && bun run test && bun run build && changelogen --release && npm publish && git push --follow-tags",
62
+ "lint": "eslint .",
63
+ "lint:fix": "eslint . --fix",
64
+ "test": "vitest run",
65
+ "test:watch": "vitest watch",
66
+ "test:coverage": "vitest run --coverage",
67
+ "typecheck": "echo 'Typecheck handled by build'"
68
+ },
69
+ "dependencies": {
70
+ "@nuxt/kit": "^4.3.0"
71
+ },
72
+ "devDependencies": {
73
+ "@nuxt/devtools": "^3.1.1",
74
+ "@nuxt/schema": "^4.3.0",
75
+ "@nuxt/test-utils": "^3.23.0",
76
+ "changelogen": "^0.6.2",
77
+ "h3": "^1.15.0",
78
+ "nitropack": "^2.13.0",
79
+ "nuxt": "^4.3.0",
80
+ "typescript": "^5.9.3",
81
+ "unbuild": "^3.5.0"
82
+ },
83
+ "peerDependencies": {
84
+ "h3": "^1.13.0",
85
+ "nitropack": "^2.10.0"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "h3": {
89
+ "optional": true
90
+ },
91
+ "nitropack": {
92
+ "optional": true
93
+ }
94
+ }
95
+ }
package/index.js DELETED
@@ -1 +0,0 @@
1
- // placeholder