log-queue 2.1.0 → 3.0.1

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 CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  [![NPM](https://nodei.co/npm/log-queue.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/log-queue/)
8
8
 
9
- Logging mainly to console and log4js-tagline, but can certainly be used for generic 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,107 @@
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
+ t.exclude_logMsg = props.exclude_logMsg
41
+
42
+ t.logMsg = t.logMsg.bind(t)
43
+ t.server = t.server.bind(t)
44
+
45
+ return t
46
+ } catch (e) {
47
+ e.message = `${fname} error: ${e.message}`
48
+ throw (e)
49
+ }
50
+ }
51
+
52
+ logMsg(props = {}) {
53
+ let t = this, fname = "http.logMsg"
54
+ try {
55
+ if (typeof t.exclude_logMsg != "undefined")
56
+ if (t.exclude_logMsg.indexOf(props.type) > -1)
57
+ return
58
+ t.output.push(`${JSON.stringify(props)}`)
59
+ } catch (e) {
60
+ e.message = `${fname} error: ${e.message}`
61
+ console.log(e.message)
62
+ throw e
63
+ }
64
+ }
65
+
66
+ server() {
67
+ let t = this, fname = "http.server", colr, dat_js, bc
68
+
69
+ t.server = http.createServer((req, res) => {
70
+ t.res = res
71
+ t.req = req
72
+ t.res.statusCode = 200;
73
+ t.res.setHeader('Content-Type', 'text/html');
74
+ t.res.write('<div align=center style="width:30%;">Log Messages<br/>');
75
+ t.res.write('<br>');
76
+ t.output.map((dat, i) => {
77
+ dat_js = JSON.parse(dat)
78
+ colr = "black"
79
+ bc = "#eee"
80
+ switch (dat_js.type) {
81
+ case "error":
82
+ colr = "red"
83
+ bc = "yellow"
84
+ break
85
+ case "debug":
86
+ colr = "blue"
87
+ break
88
+ case "warn":
89
+ colr = "yellow"
90
+ bc = "silver"
91
+ break
92
+ case "success":
93
+ colr = "white"
94
+ bc = "green"
95
+ break
96
+ }
97
+ t.res.write(`<div style="background-color:${bc};color:${colr};">${dat_js.msg}</div>`);
98
+ })
99
+ t.res.end('<br/>End Log Messages</div>');
100
+ });
101
+
102
+ t.server.listen(t.port, t.hostname, () => {
103
+ console.log(`Server running at http://${t.hostname}:${t.port}/`);
104
+ });
105
+
106
+ }
107
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": {
3
3
  "name": "Jim Manton"
4
4
  },
5
- "version": "2.1.0",
5
+ "version": "3.0.1",
6
6
  "bundleDependencies": [],
7
7
  "dependencies": {
8
8
  "@types/node": "^18.11.19",
@@ -17,13 +17,15 @@
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",
25
+ "console",
24
26
  "log4js-tagline",
27
+ "http",
25
28
  "base-queue",
26
- "console",
27
29
  "appenders",
28
30
  "javascript",
29
31
  "mocha"
package/test/package.js CHANGED
@@ -6,7 +6,7 @@ const packageMock = {
6
6
  "author": {
7
7
  "name": "Jim Manton"
8
8
  },
9
- "version": "2.1.0",
9
+ "version": "3.0.1",
10
10
  "bundleDependencies": [],
11
11
  "dependencies": {
12
12
  "@types/node": "^18.11.19",
@@ -21,13 +21,15 @@ 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",
29
+ "console",
28
30
  "log4js-tagline",
31
+ "http",
29
32
  "base-queue",
30
- "console",
31
33
  "appenders",
32
34
  "javascript",
33
35
  "mocha"
package/tests/http.js ADDED
@@ -0,0 +1,10 @@
1
+ var llog = require("../app.js"),
2
+ a = new llog({ parent: null,
3
+ exclude_logMsg: ["warn"]}).init({appender: "http", hostname: "127.0.0.1", port: 3000})
4
+
5
+ a.logMsg({ msg: "this is a debug message".debug, type: "debug" })
6
+ a.logMsg({ msg: "this is some warning message", type: "warn" })
7
+ a.logMsg({ msg: "this is some error message", type: "error" })
8
+ a.logMsg({ msg: "this is a success message", type: "success" })
9
+ a.server()
10
+