@cambo-khode/log 1.0.0 → 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.
- package/README.md +107 -0
- package/package.json +5 -3
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @cambo-khode/log
|
|
2
|
+
|
|
3
|
+
A lightweight, colorful, and formatted console logging SDK for Node.js and TypeScript applications.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 🕒 **Automatic Timestamps** — Automatically prepends local time `[HH:MM:SS]` to every log.
|
|
10
|
+
- 🎨 **Colorized Output** — Built-in terminal colors for different log levels without extra heavy dependencies.
|
|
11
|
+
- 🏷️ **Log Levels** — Dedicated helpers for `info`, `success`, `warning`, `error`, and general `log`.
|
|
12
|
+
- ⚙️ **Configurable** — Customize app name, version, and default log color upon initialization.
|
|
13
|
+
- 📦 **TypeScript Ready** — Full type definitions out of the box.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Install using your favorite package manager:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# npm
|
|
23
|
+
npm install @cambo-khode/log
|
|
24
|
+
|
|
25
|
+
# yarn
|
|
26
|
+
yarn add @cambo-khode/log
|
|
27
|
+
|
|
28
|
+
# pnpm
|
|
29
|
+
pnpm add @cambo-khode/log
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { MySDK } from '@cambo-khode/log';
|
|
38
|
+
|
|
39
|
+
// 1. Initialize the logger
|
|
40
|
+
const logger = new MySDK({
|
|
41
|
+
appName: 'MyAwesomeApp',
|
|
42
|
+
version: '1.0.0',
|
|
43
|
+
color: 'cyan'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// 2. Start logging!
|
|
47
|
+
logger.log('This is a custom default message.');
|
|
48
|
+
logger.info('Database connection established.');
|
|
49
|
+
logger.success('Server started on port 3000!');
|
|
50
|
+
logger.warning('Memory usage is above 80%.');
|
|
51
|
+
logger.error('Failed to connect to redis cache.');
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Sample Output
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
[2:45:10 PM] [INFO] MyAwesomeApp v1.0.0 initialized
|
|
58
|
+
[2:45:10 PM] [LOG] This is a custom default message.
|
|
59
|
+
[2:45:10 PM] [INFO] Database connection established.
|
|
60
|
+
[2:45:10 PM] [SUCCESS] Server started on port 3000!
|
|
61
|
+
[2:45:10 PM] [WARNING] Memory usage is above 80%.
|
|
62
|
+
[2:45:10 PM] [ERROR] Failed to connect to redis cache.
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Configuration (`SDKConfig`)
|
|
68
|
+
|
|
69
|
+
You can pass an optional configuration object to `new MySDK(config)`:
|
|
70
|
+
|
|
71
|
+
| Option | Type | Default | Description |
|
|
72
|
+
| :--- | :--- | :--- | :--- |
|
|
73
|
+
| `appName` | `string` | `'My SDK'` | The name of your application. |
|
|
74
|
+
| `version` | `string` | `'1.0.0'` | The version string displayed on initialization. |
|
|
75
|
+
| `color` | `'red' \| 'green' \| 'yellow' \| 'blue' \| 'cyan' \| 'white'` | `'cyan'` | Default terminal color used for `.log()`. |
|
|
76
|
+
|
|
77
|
+
### Example with Custom Config
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { MySDK, SDKConfig } from '@cambo-khode/log';
|
|
81
|
+
|
|
82
|
+
const config: SDKConfig = {
|
|
83
|
+
appName: 'PaymentService',
|
|
84
|
+
version: '2.1.0',
|
|
85
|
+
color: 'yellow' // 'red' | 'green' | 'yellow' | 'blue' | 'cyan' | 'white'
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const logger = new MySDK(config);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Available Methods
|
|
94
|
+
|
|
95
|
+
| Method | Log Tag | Terminal Color | Best Used For |
|
|
96
|
+
| :--- | :--- | :--- | :--- |
|
|
97
|
+
| `logger.log(message)` | `[LOG]` | Custom (Default: `cyan`) | General purpose logs and events |
|
|
98
|
+
| `logger.info(message)` | `[INFO]` | `blue` | Informational status updates |
|
|
99
|
+
| `logger.success(message)` | `[SUCCESS]` | `green` | Successful actions, confirmations |
|
|
100
|
+
| `logger.warning(message)` | `[WARNING]` | `yellow` | Warnings, non-critical alerts |
|
|
101
|
+
| `logger.error(message)` | `[ERROR]` | `red` | Errors, crashes, failed operations |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
[MIT](LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cambo-khode/log",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Cambo Khode custom console logger SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"files": [
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
15
17
|
"scripts": {
|
|
16
18
|
"build": "tsc"
|
|
17
19
|
},
|
|
18
20
|
"license": "MIT"
|
|
19
|
-
}
|
|
21
|
+
}
|