log-queue 2.1.0 → 3.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 +2 -1
- package/app.js +11 -0
- package/appenders/http.js +103 -0
- package/package.json +3 -2
- package/test/package.js +4 -2
- package/tests/http.js +9 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
[](https://nodei.co/npm/log-queue/)
|
|
8
8
|
|
|
9
|
-
Logging
|
|
9
|
+
Logging to console, log4js-tagline and http.
|
|
10
10
|
|
|
11
11
|
Mocha Test
|
|
12
12
|
---------
|
|
@@ -18,5 +18,6 @@ General Setup Test
|
|
|
18
18
|
---------
|
|
19
19
|
```
|
|
20
20
|
npm run test_logs
|
|
21
|
+
npm run test_http
|
|
21
22
|
|
|
22
23
|
```
|
package/app.js
CHANGED
|
@@ -72,4 +72,15 @@ exports = module.exports = class LogQueue {
|
|
|
72
72
|
throw e
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
server(props = {}) {
|
|
77
|
+
let t = this, fname = "LogQueue.server"
|
|
78
|
+
try {
|
|
79
|
+
t.logObj.server(props)
|
|
80
|
+
} catch (e) {
|
|
81
|
+
e.message = `${fname} error: ${e.message}`
|
|
82
|
+
console.log(e.message)
|
|
83
|
+
throw e
|
|
84
|
+
}
|
|
85
|
+
}
|
|
75
86
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* @author Jim Manton: jrman@risebroadband.net
|
|
2
|
+
* @since 2023-03-22
|
|
3
|
+
* http.js
|
|
4
|
+
|
|
5
|
+
look here: https://stackoverflow.com/questions/6084360/using-node-js-as-a-simple-web-server
|
|
6
|
+
|
|
7
|
+
const http = require('http');
|
|
8
|
+
|
|
9
|
+
const hostname = '127.0.0.1';
|
|
10
|
+
const port = 3000;
|
|
11
|
+
|
|
12
|
+
const server = http.createServer((req, res) => {
|
|
13
|
+
res.statusCode = 200;
|
|
14
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
15
|
+
res.end('Hello World');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
server.listen(port, hostname, () => {
|
|
19
|
+
console.log(`Server running at http://${hostname}:${port}/`);
|
|
20
|
+
});
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const { red } = require('colors');
|
|
24
|
+
const http = require('http');
|
|
25
|
+
|
|
26
|
+
exports = module.exports = class log_http {
|
|
27
|
+
constructor(props) {
|
|
28
|
+
var t = this, fname = `http.constructor`
|
|
29
|
+
try {
|
|
30
|
+
if (typeof props.hostname == "undefined")
|
|
31
|
+
throw new Error(`hostname is not defined`)
|
|
32
|
+
if (typeof props.port == "undefined")
|
|
33
|
+
throw new Error(`port is not defined`)
|
|
34
|
+
props.colors.disable()
|
|
35
|
+
t.hostname = props.hostname
|
|
36
|
+
t.port = props.port
|
|
37
|
+
t.output = []
|
|
38
|
+
t.res = null
|
|
39
|
+
t.req = null
|
|
40
|
+
|
|
41
|
+
t.logMsg = t.logMsg.bind(t)
|
|
42
|
+
t.server = t.server.bind(t)
|
|
43
|
+
|
|
44
|
+
return t
|
|
45
|
+
} catch (e) {
|
|
46
|
+
e.message = `${fname} error: ${e.message}`
|
|
47
|
+
throw (e)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
logMsg(props = {}) {
|
|
52
|
+
let t = this, fname = "http.logMsg"
|
|
53
|
+
try {
|
|
54
|
+
t.output.push(`${JSON.stringify(props)}`)
|
|
55
|
+
} catch (e) {
|
|
56
|
+
e.message = `${fname} error: ${e.message}`
|
|
57
|
+
console.log(e.message)
|
|
58
|
+
throw e
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
server() {
|
|
63
|
+
let t = this, fname = "http.server", colr, dat_js, bc
|
|
64
|
+
|
|
65
|
+
t.server = http.createServer((req, res) => {
|
|
66
|
+
t.res = res
|
|
67
|
+
t.req = req
|
|
68
|
+
t.res.statusCode = 200;
|
|
69
|
+
t.res.setHeader('Content-Type', 'text/html');
|
|
70
|
+
t.res.write('<div align=center style="width:30%;">Log Messages<br/>');
|
|
71
|
+
t.res.write('<br>');
|
|
72
|
+
t.output.map((dat, i) => {
|
|
73
|
+
dat_js = JSON.parse(dat)
|
|
74
|
+
colr = "black"
|
|
75
|
+
bc = "#eee"
|
|
76
|
+
switch (dat_js.type) {
|
|
77
|
+
case "error":
|
|
78
|
+
colr = "red"
|
|
79
|
+
bc = "yellow"
|
|
80
|
+
break
|
|
81
|
+
case "debug":
|
|
82
|
+
colr = "blue"
|
|
83
|
+
break
|
|
84
|
+
case "warn":
|
|
85
|
+
colr = "yellow"
|
|
86
|
+
bc = "silver"
|
|
87
|
+
break
|
|
88
|
+
case "success":
|
|
89
|
+
colr = "white"
|
|
90
|
+
bc = "green"
|
|
91
|
+
break
|
|
92
|
+
}
|
|
93
|
+
t.res.write(`<div style="background-color:${bc};color:${colr};">${dat_js.msg}</div>`);
|
|
94
|
+
})
|
|
95
|
+
t.res.end('<br/>End Log Messages</div>');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
t.server.listen(t.port, t.hostname, () => {
|
|
99
|
+
console.log(`Server running at http://${t.hostname}:${t.port}/`);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": {
|
|
3
3
|
"name": "Jim Manton"
|
|
4
4
|
},
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "3.0.0",
|
|
6
6
|
"bundleDependencies": [],
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@types/node": "^18.11.19",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"start": "node app.ts",
|
|
18
18
|
"test": "mocha",
|
|
19
19
|
"ditched": "ditched -a",
|
|
20
|
-
"test_logs": "node ./tests/logs"
|
|
20
|
+
"test_logs": "node ./tests/logs",
|
|
21
|
+
"test_http": "node ./tests/http"
|
|
21
22
|
},
|
|
22
23
|
"keywords": [
|
|
23
24
|
"log",
|
package/test/package.js
CHANGED
|
@@ -6,7 +6,7 @@ const packageMock = {
|
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Jim Manton"
|
|
8
8
|
},
|
|
9
|
-
"version": "
|
|
9
|
+
"version": "3.0.0",
|
|
10
10
|
"bundleDependencies": [],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@types/node": "^18.11.19",
|
|
@@ -21,7 +21,8 @@ const packageMock = {
|
|
|
21
21
|
"start": "node app.ts",
|
|
22
22
|
"test": "mocha",
|
|
23
23
|
"ditched": "ditched -a",
|
|
24
|
-
"test_logs": "node ./tests/logs"
|
|
24
|
+
"test_logs": "node ./tests/logs",
|
|
25
|
+
"test_http": "node ./tests/http"
|
|
25
26
|
},
|
|
26
27
|
"keywords": [
|
|
27
28
|
"log",
|
|
@@ -46,6 +47,7 @@ const packageMock = {
|
|
|
46
47
|
"start": "node app.js"
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
|
|
49
51
|
describe('package.json', function () {
|
|
50
52
|
it('should pass', function () {
|
|
51
53
|
const difference = jsonHasDifferences(packagejson, packageMock)
|
package/tests/http.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var llog = require("../app.js"),
|
|
2
|
+
a = new llog({ parent: null }).init({appender: "http", hostname: "127.0.0.1", port: 3000})
|
|
3
|
+
|
|
4
|
+
a.logMsg({ msg: "this is a debug message".debug, type: "debug" })
|
|
5
|
+
a.logMsg({ msg: "this is some warning message", type: "warn" })
|
|
6
|
+
a.logMsg({ msg: "this is some error message", type: "error" })
|
|
7
|
+
a.logMsg({ msg: "this is a success message", type: "success" })
|
|
8
|
+
a.server()
|
|
9
|
+
|