A tool to enable remote logging for AnaLogger
npm install remote-loggingRemote-Logging is a remote log viewer.
!Preview
shell
Install modules globally
npm install remote-logging -g
`
or
`shell
Run module with no installation step from a temporary directory
npx --yes remote-logging@latest
`
On Linux, you will need to open the port for the devices on your network can access the console.
Centos:
`shell
sudo firewall-cmd --add-port=12000/tcp --permanent
sudo firewall-cmd reload
`
Other distributions:
`shell
sudo iptables -A INPUT -p tcp --dport 12000 -j ACCEPT
sudo systemctl restart iptables
`
Refer to your distro for a more precise set-up.
On windows, it may ask to allow access to the port (12000 by default)
!Browser to Remote Logging view
---
Usage
With Remote Logging, you can automatically console.log your data to the viewer.
$3
`shell
$> remote-logging [--port 12000]
`
---
Demo
$3
To send logs from a logging system to remote-logging, you must send a POST request with the following format:
`shell
[
[{"lid": 123888, "color": "blue"}, "My message 1"],
[{"lid": 123939, "color": "blue"}, "My message 2"],
[{"lid": 123959, "color": "blue"}, "My message 3"],
]
`
The lid is a random number
`shell
$> curl --request POST 'http://your-server-ip:12000/analogger' --data-raw '[{"lid": 123888}, "My message"]'
`
#### Example with Postman
!Postman to Remote Logging view
---
$3
To send logs from the browser, you can use `fetch` and adapt the formatting above
`javascript
fetch("http://localhost:12000/analogger", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(/ Your formatted data /),
redirect: 'follow'
})
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
`
!Browser to Remote Logging view
---
$3
You can send log from AnaLogger by passing true to the logToRemote option.
`javascript
const {anaLogger} = require("analogger");
anaLogger.setOptions({logToRemote: true});
`
Go to the AnaLogger page for more options:
https://www.npmjs.com/package/analogger
---
Tests
$3
Mocha is a JavaScript test framework: https://www.npmjs.com/package/mocha
##### Description of how to have Remote-Logging working as an automated test viewer
* Install Remote-Logging
`shell
$> npm install remote-logging
`
* Launch Remote-Logging
`shell
Port by default
$> remote-logging --port 8221
`
* Pass the path of the reporter to Mocha
`shell
mocha --reporter=./node_modules/remote-logging/reporter.cjs
`
!Preview
$3
To pass options to the reporter, use environment variables:
| Name | Description | Default |
|-------------------------------------------|---------------------------------------------------|---------------------------------|
| ANALOGGER_TEST_PORT | Port you wish to set the remote-logging server to | 8221 |
| ANALOGGER_LOG_FILE | To add log into a file | |
| ANALOGGER_LOG_TO_REMOTE_URL ** | To change the remote url for logging | http://localhost:8221/analogger |
| ANALOGGER_LOG_TO_REMOTE_BINARY_URL ** | To change the address for screenshots | http://localhost:8221/uploaded |
> ##### ** Set these if you have updated your AnaLogger configuration to point to custom URLs
#### Example
##### Linux:
`shell
export ANALOGGER_TEST_PORT=12000
export ANALOGGER_LOG_FILE=reporter.log
mocha --reporter=./node_modules/remote-logging/reporter.cjs
`
##### Windows (Powershell)
`shell
$env:ANALOGGER_TEST_PORT = 12000
$env:ANALOGGER_LOG_FILE = "reporter.log"
mocha --reporter=./node_modules/remote-logging/reporter.cjs
`
---
$3
`shell
$> npm remove remote-logging -g
``