modelmix 1.2.2 → 2.0.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.
- package/README.md +91 -50
- package/demo/custom.mjs +28 -0
- package/demo/demo.mjs +27 -16
- package/demo/node_modules/.package-lock.json +29 -0
- package/demo/node_modules/debug/LICENSE +20 -0
- package/demo/node_modules/debug/README.md +481 -0
- package/demo/node_modules/debug/node_modules/ms/index.js +162 -0
- package/demo/node_modules/debug/node_modules/ms/license.md +21 -0
- package/demo/node_modules/debug/node_modules/ms/package.json +37 -0
- package/demo/node_modules/debug/node_modules/ms/readme.md +60 -0
- package/demo/node_modules/debug/package.json +59 -0
- package/demo/node_modules/debug/src/browser.js +269 -0
- package/demo/node_modules/debug/src/common.js +274 -0
- package/demo/node_modules/debug/src/index.js +10 -0
- package/demo/node_modules/debug/src/node.js +263 -0
- package/demo/node_modules/lemonlog/README.md +133 -0
- package/demo/node_modules/lemonlog/demo/demo.js +31 -0
- package/demo/node_modules/lemonlog/index.js +94 -0
- package/demo/node_modules/lemonlog/package.json +31 -0
- package/demo/package-lock.json +30 -0
- package/demo/package.json +1 -0
- package/demo/stream.mjs +87 -0
- package/index.js +189 -70
- package/package.json +6 -2
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module dependencies.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const tty = require('tty');
|
|
6
|
+
const util = require('util');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This is the Node.js implementation of `debug()`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
exports.init = init;
|
|
13
|
+
exports.log = log;
|
|
14
|
+
exports.formatArgs = formatArgs;
|
|
15
|
+
exports.save = save;
|
|
16
|
+
exports.load = load;
|
|
17
|
+
exports.useColors = useColors;
|
|
18
|
+
exports.destroy = util.deprecate(
|
|
19
|
+
() => {},
|
|
20
|
+
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Colors.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
31
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
32
|
+
const supportsColor = require('supports-color');
|
|
33
|
+
|
|
34
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
35
|
+
exports.colors = [
|
|
36
|
+
20,
|
|
37
|
+
21,
|
|
38
|
+
26,
|
|
39
|
+
27,
|
|
40
|
+
32,
|
|
41
|
+
33,
|
|
42
|
+
38,
|
|
43
|
+
39,
|
|
44
|
+
40,
|
|
45
|
+
41,
|
|
46
|
+
42,
|
|
47
|
+
43,
|
|
48
|
+
44,
|
|
49
|
+
45,
|
|
50
|
+
56,
|
|
51
|
+
57,
|
|
52
|
+
62,
|
|
53
|
+
63,
|
|
54
|
+
68,
|
|
55
|
+
69,
|
|
56
|
+
74,
|
|
57
|
+
75,
|
|
58
|
+
76,
|
|
59
|
+
77,
|
|
60
|
+
78,
|
|
61
|
+
79,
|
|
62
|
+
80,
|
|
63
|
+
81,
|
|
64
|
+
92,
|
|
65
|
+
93,
|
|
66
|
+
98,
|
|
67
|
+
99,
|
|
68
|
+
112,
|
|
69
|
+
113,
|
|
70
|
+
128,
|
|
71
|
+
129,
|
|
72
|
+
134,
|
|
73
|
+
135,
|
|
74
|
+
148,
|
|
75
|
+
149,
|
|
76
|
+
160,
|
|
77
|
+
161,
|
|
78
|
+
162,
|
|
79
|
+
163,
|
|
80
|
+
164,
|
|
81
|
+
165,
|
|
82
|
+
166,
|
|
83
|
+
167,
|
|
84
|
+
168,
|
|
85
|
+
169,
|
|
86
|
+
170,
|
|
87
|
+
171,
|
|
88
|
+
172,
|
|
89
|
+
173,
|
|
90
|
+
178,
|
|
91
|
+
179,
|
|
92
|
+
184,
|
|
93
|
+
185,
|
|
94
|
+
196,
|
|
95
|
+
197,
|
|
96
|
+
198,
|
|
97
|
+
199,
|
|
98
|
+
200,
|
|
99
|
+
201,
|
|
100
|
+
202,
|
|
101
|
+
203,
|
|
102
|
+
204,
|
|
103
|
+
205,
|
|
104
|
+
206,
|
|
105
|
+
207,
|
|
106
|
+
208,
|
|
107
|
+
209,
|
|
108
|
+
214,
|
|
109
|
+
215,
|
|
110
|
+
220,
|
|
111
|
+
221
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Build up the default `inspectOpts` object from the environment variables.
|
|
120
|
+
*
|
|
121
|
+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
125
|
+
return /^debug_/i.test(key);
|
|
126
|
+
}).reduce((obj, key) => {
|
|
127
|
+
// Camel-case
|
|
128
|
+
const prop = key
|
|
129
|
+
.substring(6)
|
|
130
|
+
.toLowerCase()
|
|
131
|
+
.replace(/_([a-z])/g, (_, k) => {
|
|
132
|
+
return k.toUpperCase();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Coerce string value into JS value
|
|
136
|
+
let val = process.env[key];
|
|
137
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
138
|
+
val = true;
|
|
139
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
140
|
+
val = false;
|
|
141
|
+
} else if (val === 'null') {
|
|
142
|
+
val = null;
|
|
143
|
+
} else {
|
|
144
|
+
val = Number(val);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
obj[prop] = val;
|
|
148
|
+
return obj;
|
|
149
|
+
}, {});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
function useColors() {
|
|
156
|
+
return 'colors' in exports.inspectOpts ?
|
|
157
|
+
Boolean(exports.inspectOpts.colors) :
|
|
158
|
+
tty.isatty(process.stderr.fd);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Adds ANSI color escape codes if enabled.
|
|
163
|
+
*
|
|
164
|
+
* @api public
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
function formatArgs(args) {
|
|
168
|
+
const {namespace: name, useColors} = this;
|
|
169
|
+
|
|
170
|
+
if (useColors) {
|
|
171
|
+
const c = this.color;
|
|
172
|
+
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
173
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
174
|
+
|
|
175
|
+
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
176
|
+
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
177
|
+
} else {
|
|
178
|
+
args[0] = getDate() + name + ' ' + args[0];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getDate() {
|
|
183
|
+
if (exports.inspectOpts.hideDate) {
|
|
184
|
+
return '';
|
|
185
|
+
}
|
|
186
|
+
return new Date().toISOString() + ' ';
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
function log(...args) {
|
|
194
|
+
return process.stderr.write(util.format(...args) + '\n');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Save `namespaces`.
|
|
199
|
+
*
|
|
200
|
+
* @param {String} namespaces
|
|
201
|
+
* @api private
|
|
202
|
+
*/
|
|
203
|
+
function save(namespaces) {
|
|
204
|
+
if (namespaces) {
|
|
205
|
+
process.env.DEBUG = namespaces;
|
|
206
|
+
} else {
|
|
207
|
+
// If you set a process.env field to null or undefined, it gets cast to the
|
|
208
|
+
// string 'null' or 'undefined'. Just delete instead.
|
|
209
|
+
delete process.env.DEBUG;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Load `namespaces`.
|
|
215
|
+
*
|
|
216
|
+
* @return {String} returns the previously persisted debug modes
|
|
217
|
+
* @api private
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
function load() {
|
|
221
|
+
return process.env.DEBUG;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Init logic for `debug` instances.
|
|
226
|
+
*
|
|
227
|
+
* Create a new `inspectOpts` object in case `useColors` is set
|
|
228
|
+
* differently for a particular `debug` instance.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
function init(debug) {
|
|
232
|
+
debug.inspectOpts = {};
|
|
233
|
+
|
|
234
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
235
|
+
for (let i = 0; i < keys.length; i++) {
|
|
236
|
+
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
module.exports = require('./common')(exports);
|
|
241
|
+
|
|
242
|
+
const {formatters} = module.exports;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
formatters.o = function (v) {
|
|
249
|
+
this.inspectOpts.colors = this.useColors;
|
|
250
|
+
return util.inspect(v, this.inspectOpts)
|
|
251
|
+
.split('\n')
|
|
252
|
+
.map(str => str.trim())
|
|
253
|
+
.join(' ');
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
formatters.O = function (v) {
|
|
261
|
+
this.inspectOpts.colors = this.useColors;
|
|
262
|
+
return util.inspect(v, this.inspectOpts);
|
|
263
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# 🍋 LemonLog - Simplify Your Node.js Logging
|
|
2
|
+
|
|
3
|
+
Welcome to **LemonLog**! The zesty, easy-to-use logging solution for your Node.js applications. Whether you're debugging your latest feature or keeping an eye on production issues, LemonLog is here to brighten your day (and your console) with colorful, structured logs. 🌈
|
|
4
|
+
|
|
5
|
+
## 🌟 Features
|
|
6
|
+
|
|
7
|
+
- **Simple Setup**: Get up and running in no time. LemonLog is all about simplicity.
|
|
8
|
+
- **Colorful Logs**: Make your logs more readable with automatic color coding. Info, debug, warn, and error logs each have their own vibrant hue.
|
|
9
|
+
- **Console Bindings**: LemonLog ties neatly into the console, ensuring that your logs are both beautiful and functional.
|
|
10
|
+
- **Custom Callbacks**: Handle errors and debug information your way with custom callbacks.
|
|
11
|
+
- **Flexible**: Whether you're writing a quick script or a complex application, LemonLog adapts to your needs.
|
|
12
|
+
- **Full Depth Inspect**: Allows you to inspect deeply nested objects with ease. You can quickly and clearly see the structure of your data.
|
|
13
|
+
|
|
14
|
+
## 🚀 Getting Started
|
|
15
|
+
|
|
16
|
+
1. **Install LemonLog**
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install lemonlog
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. **Usage**
|
|
23
|
+
|
|
24
|
+
First, require and create a new instance of LemonLog in your project:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
const log = require('lemonlog')('MyApp');
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or
|
|
31
|
+
```javascript
|
|
32
|
+
import LemonLog from 'lemonlog';
|
|
33
|
+
const log = new LemonLog('MyApp');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then, log away:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
log.info('This is an info message!');
|
|
40
|
+
log.debug('Here’s something you might find interesting...', { emoji: "🎁" });
|
|
41
|
+
log.inspect('Inspecting a deeply nested object', { a: { b: { c: { d: 1 } } } });
|
|
42
|
+
log.warn('Warning! Warning! 🚨');
|
|
43
|
+
log.error('Oops! Something went wrong. 🔥');
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Use DEBUG to filter logs:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
$ DEBUG=* node demo/demo.js
|
|
51
|
+
myApp:info ------ This is an info message { a: 1 } +0ms
|
|
52
|
+
myApp:debug ----- This is a debug message +0ms
|
|
53
|
+
myApp:inspect --- [
|
|
54
|
+
myApp:inspect --- 'This is a full json depth inspect message',
|
|
55
|
+
myApp:inspect --- {
|
|
56
|
+
myApp:inspect --- a: { b: { c: { d: 1 } } }
|
|
57
|
+
myApp:inspect --- }
|
|
58
|
+
myApp:inspect --- ] +0ms
|
|
59
|
+
myApp:warn ------ This is a warning +0ms
|
|
60
|
+
myApp:error ----- This is an error +0ms
|
|
61
|
+
myApp:debug ----- [ 'Custom success message' ]
|
|
62
|
+
myApp:debug ----- { return: 'ok' } +0ms
|
|
63
|
+
myApp:error ----- { return: 'error' }
|
|
64
|
+
myApp:error ----- [ 'Custom error message' ]
|
|
65
|
+
myApp:error ----- null +0ms
|
|
66
|
+
myApp:debug ----- Success: { return: 'ok' } +1ms
|
|
67
|
+
myApp:error ----- { return: 'error' }
|
|
68
|
+
myApp:error ----- null +1ms
|
|
69
|
+
|
|
70
|
+
$ DEBUG=myApp:error* node demo/demo.js
|
|
71
|
+
myApp:error ----- This is an error +0ms
|
|
72
|
+
myApp:error ----- { return: 'error' }
|
|
73
|
+
myApp:error ----- [ 'Custom error message' ]
|
|
74
|
+
myApp:error ----- null +0ms
|
|
75
|
+
myApp:error ----- { return: 'error' }
|
|
76
|
+
myApp:error ----- null +1ms
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
3. **Customize Your Callbacks**
|
|
80
|
+
|
|
81
|
+
Handle logs with your own custom logic:
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
async function someAsyncFunction(fail, cbk) {
|
|
85
|
+
|
|
86
|
+
if (fail) {
|
|
87
|
+
cbk({ return: "error" }, null);
|
|
88
|
+
} else {
|
|
89
|
+
cbk(null, { return: "ok" });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Custom callback example
|
|
94
|
+
someAsyncFunction(false, log.callback("Custom success message"));
|
|
95
|
+
|
|
96
|
+
someAsyncFunction(true, log.callback("Custom error message"));
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
// Exec example
|
|
100
|
+
someAsyncFunction(false, log.exec(result => {
|
|
101
|
+
log.debug('Success:', result);
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
someAsyncFunction(true, log.exec(result => {
|
|
105
|
+
log.debug('Error:', result);
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 🍋 Why LemonLog?
|
|
111
|
+
|
|
112
|
+
We believe that logging shouldn't just be about capturing information. It should be a delightful part of your development process. With LemonLog, we aim to bring a little joy and color to your console, making it easier and more fun to sift through your logs.
|
|
113
|
+
|
|
114
|
+
## 🤝 Contributing
|
|
115
|
+
|
|
116
|
+
Got ideas on how to make LemonLog even better? We'd love to hear from you! Check out our contribution guidelines to get started.
|
|
117
|
+
|
|
118
|
+
## Keep It Zesty!
|
|
119
|
+
|
|
120
|
+
Thank you for choosing LemonLog for your logging needs. We hope it adds a splash of color to your projects and makes logging something to look forward to.
|
|
121
|
+
|
|
122
|
+
Happy coding!
|
|
123
|
+
|
|
124
|
+
## 📄 License
|
|
125
|
+
The MIT License (MIT)
|
|
126
|
+
|
|
127
|
+
Copyright (c) Martin Clasen
|
|
128
|
+
|
|
129
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
130
|
+
|
|
131
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
132
|
+
|
|
133
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const log = require('../index')('myApp');
|
|
2
|
+
|
|
3
|
+
log.info('This is an info message', { a: 1 });
|
|
4
|
+
log.debug('This is a debug message');
|
|
5
|
+
log.inspect('This is a full json depth inspect message', { a: { b: { c: { d: 1 } } } });
|
|
6
|
+
log.warn('This is a warning');
|
|
7
|
+
log.error('This is an error');
|
|
8
|
+
|
|
9
|
+
async function someAsyncFunction(fail, cbk) {
|
|
10
|
+
|
|
11
|
+
if (fail) {
|
|
12
|
+
cbk({ return: "error" }, null);
|
|
13
|
+
} else {
|
|
14
|
+
cbk(null, { return: "ok" });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Custom callback example
|
|
19
|
+
someAsyncFunction(false, log.callback("Custom success message"));
|
|
20
|
+
|
|
21
|
+
someAsyncFunction(true, log.callback("Custom error message"));
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// Exec example
|
|
25
|
+
someAsyncFunction(false, log.exec(result => {
|
|
26
|
+
log.debug('Success:', result);
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
someAsyncFunction(true, log.exec(result => {
|
|
30
|
+
log.debug('Error:', result);
|
|
31
|
+
}));
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const debug = require('debug');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
|
|
4
|
+
class LemonLogClass {
|
|
5
|
+
constructor(name) {
|
|
6
|
+
const pad = '-----------------';
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.loggers = {
|
|
9
|
+
info: debug(this.rpad(`${name}:info `, pad)),
|
|
10
|
+
debug: debug(this.rpad(`${name}:debug `, pad)),
|
|
11
|
+
inspect: debug(this.rpad(`${name}:inspect `, pad)),
|
|
12
|
+
warn: debug(this.rpad(`${name}:warn `, pad)),
|
|
13
|
+
error: debug(this.rpad(`${name}:error `, pad)),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Set up console bindings
|
|
17
|
+
this._setupConsoleBindings();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
info(...args) {
|
|
21
|
+
this.loggers.info(...args);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
inspect(...args) {
|
|
25
|
+
this.loggers.inspect(util.inspect(args, { showHidden: false, depth: null, colors: true }))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
debug(...args) {
|
|
29
|
+
this.loggers.debug(...args);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
warn(...args) {
|
|
33
|
+
this.loggers.warn(...args);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
error(...args) {
|
|
37
|
+
this.loggers.error(...args);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
rpad(str, pad) {
|
|
41
|
+
return (str + pad).substring(0, pad.length);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_setupConsoleBindings() {
|
|
45
|
+
const { info, debug, warn, error, inspect } = this.loggers;
|
|
46
|
+
info.log = console.info.bind(console);
|
|
47
|
+
debug.log = console.log.bind(console);
|
|
48
|
+
inspect.log = console.log.bind(console);
|
|
49
|
+
warn.log = console.log.bind(console);
|
|
50
|
+
error.log = console.error.bind(console);
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Optional: Set colors
|
|
54
|
+
info.color = 6;
|
|
55
|
+
debug.color = 2;
|
|
56
|
+
warn.color = 5;
|
|
57
|
+
error.color = 1;
|
|
58
|
+
inspect.color = 12;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
callback() {
|
|
62
|
+
const { error, debug } = this.loggers;
|
|
63
|
+
let args = Array.from(arguments);
|
|
64
|
+
return function (err, r) {
|
|
65
|
+
if (err !== null) {
|
|
66
|
+
error("%O\n%O\n%O", err, args, r);
|
|
67
|
+
} else {
|
|
68
|
+
debug("%O\n%O", args, r);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exec(cbk = () => { }) {
|
|
74
|
+
const { error } = this.loggers;
|
|
75
|
+
return function (err, r) {
|
|
76
|
+
if (err !== null) {
|
|
77
|
+
error("%O\n%O", err, r);
|
|
78
|
+
} else {
|
|
79
|
+
cbk(r);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Wrapper function to support both constructor and function usage
|
|
86
|
+
function LemonLog(name) {
|
|
87
|
+
if (this instanceof LemonLog) {
|
|
88
|
+
return this;
|
|
89
|
+
} else {
|
|
90
|
+
return new LemonLogClass(name);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = LemonLog;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lemonlog",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "🍋 LemonLog - Simplify Your Node.js Logging",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/clasen/LemonLog.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"logging",
|
|
12
|
+
"log",
|
|
13
|
+
"debug",
|
|
14
|
+
"console log",
|
|
15
|
+
"error handling",
|
|
16
|
+
"development",
|
|
17
|
+
"tools",
|
|
18
|
+
"lemon",
|
|
19
|
+
"inspect",
|
|
20
|
+
"full depth"
|
|
21
|
+
],
|
|
22
|
+
"author": "Martin Clasen",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/clasen/LemonLog/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/clasen/LemonLog#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"debug": "^4.3.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/demo/package-lock.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^0.20.9",
|
|
13
13
|
"dotenv": "^16.4.5",
|
|
14
|
+
"lemonlog": "^1.1.2",
|
|
14
15
|
"openai": "^4.47.1"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
@@ -94,6 +95,27 @@
|
|
|
94
95
|
"node": ">= 0.8"
|
|
95
96
|
}
|
|
96
97
|
},
|
|
98
|
+
"node_modules/debug": {
|
|
99
|
+
"version": "4.3.4",
|
|
100
|
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
|
101
|
+
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
|
102
|
+
"dependencies": {
|
|
103
|
+
"ms": "2.1.2"
|
|
104
|
+
},
|
|
105
|
+
"engines": {
|
|
106
|
+
"node": ">=6.0"
|
|
107
|
+
},
|
|
108
|
+
"peerDependenciesMeta": {
|
|
109
|
+
"supports-color": {
|
|
110
|
+
"optional": true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"node_modules/debug/node_modules/ms": {
|
|
115
|
+
"version": "2.1.2",
|
|
116
|
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
|
117
|
+
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
118
|
+
},
|
|
97
119
|
"node_modules/delayed-stream": {
|
|
98
120
|
"version": "1.0.0",
|
|
99
121
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
|
@@ -167,6 +189,14 @@
|
|
|
167
189
|
"ms": "^2.0.0"
|
|
168
190
|
}
|
|
169
191
|
},
|
|
192
|
+
"node_modules/lemonlog": {
|
|
193
|
+
"version": "1.1.2",
|
|
194
|
+
"resolved": "https://registry.npmjs.org/lemonlog/-/lemonlog-1.1.2.tgz",
|
|
195
|
+
"integrity": "sha512-ztAM2mVrr9+CLoKvXKCJeGb6jNNDZUnATlcIouFuj7ymyNKXXZhx4gXyQ5lsW6oLx5KXKb/vLclXVdcqJ5sHVA==",
|
|
196
|
+
"dependencies": {
|
|
197
|
+
"debug": "^4.3.4"
|
|
198
|
+
}
|
|
199
|
+
},
|
|
170
200
|
"node_modules/mime-db": {
|
|
171
201
|
"version": "1.52.0",
|
|
172
202
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
package/demo/package.json
CHANGED
package/demo/stream.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
2
|
+
|
|
3
|
+
import { ModelMix, MixOpenAI, MixAnthropic, MixPerplexity, MixOllama } from '../index.js';
|
|
4
|
+
|
|
5
|
+
const env = process.env;
|
|
6
|
+
|
|
7
|
+
const mmix = new ModelMix({
|
|
8
|
+
options: {
|
|
9
|
+
max_tokens: 100,
|
|
10
|
+
},
|
|
11
|
+
config: {
|
|
12
|
+
system: 'You are ALF from Melmac.',
|
|
13
|
+
max_history: 2
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
mmix.attach(new MixOpenAI({
|
|
18
|
+
config: {
|
|
19
|
+
apiKey: env.OPENAI_API_KEY,
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
mmix.attach(new MixAnthropic({ config: { apiKey: env.ANTHROPIC_API_KEY } }));
|
|
24
|
+
|
|
25
|
+
mmix.attach(new MixPerplexity({
|
|
26
|
+
config: {
|
|
27
|
+
apiKey: env.PPLX_API_KEY
|
|
28
|
+
},
|
|
29
|
+
system: "You are my personal assistant."
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
mmix.attach(new MixOllama({
|
|
33
|
+
config: {
|
|
34
|
+
url: 'http://localhost:11434/api/chat',
|
|
35
|
+
prefix: ['openhermes2'],
|
|
36
|
+
system: 'You are ALF, soy de Melmac.',
|
|
37
|
+
},
|
|
38
|
+
options: {
|
|
39
|
+
temperature: 0,
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
mmix.attach(new MixOllama({
|
|
44
|
+
config: {
|
|
45
|
+
url: 'http://localhost:11434/api/chat',
|
|
46
|
+
prefix: ['llava'],
|
|
47
|
+
},
|
|
48
|
+
options: {
|
|
49
|
+
temperature: 0,
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
await mmix.create('gpt-4o')
|
|
55
|
+
.addImage('./watson.png')
|
|
56
|
+
.addText('describe')
|
|
57
|
+
.stream((data) => { console.log(data.message); });
|
|
58
|
+
|
|
59
|
+
await mmix.create('claude-3-haiku-20240307')
|
|
60
|
+
.addImage('./watson.png')
|
|
61
|
+
.addText('describe')
|
|
62
|
+
.stream((data) => { console.log(data.message); });
|
|
63
|
+
|
|
64
|
+
await mmix.create('llava:latest')
|
|
65
|
+
.addImage('./watson.png')
|
|
66
|
+
.addText('describe')
|
|
67
|
+
.stream((data) => { console.log(data.message); });
|
|
68
|
+
|
|
69
|
+
await mmix.create('pplx-70b-online')
|
|
70
|
+
.addText('Who is the president of salvador?')
|
|
71
|
+
.stream((data) => { console.log(data.message); });
|
|
72
|
+
|
|
73
|
+
await mmix.create('openhermes2-mistral:latest')
|
|
74
|
+
.addText('Who is the president of salvador?')
|
|
75
|
+
.stream((data) => { console.log(data.message); });
|
|
76
|
+
|
|
77
|
+
console.log(r)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
// await mmix.create('claude-3-haiku-20240307')
|
|
82
|
+
// // .addImage("./watson.png")
|
|
83
|
+
// .addText("hola!").stream((data) => {
|
|
84
|
+
// console.log("Streaming data:", data);
|
|
85
|
+
// });
|
|
86
|
+
|
|
87
|
+
// console.log(await gpt.raw());
|