Remote-Logging is a remote log viewer.

![Preview](https://github.com/thimpat/demos/blob/main/remote-logging/images/preview-1.png
"Remote Logs")


## Installation

```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
```

<br/>

**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](https://github.com/thimpat/demos/blob/main/remote-logging/images/firewall-windows-example.png)

<br/>

---


## Usage

With Remote Logging, you can automatically `console.log` your data to the viewer.

### From a Shell

```shell
$> remote-logging [--port 12000]
```

---

## Demo

### Send logs from a logger

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"]'
```
<br/>

#### Example with Postman

![Postman to Remote Logging view](https://github.com/thimpat/demos/blob/main/remote-logging/images/rl-analogger-2.gif
"Remote Logs")

<br/>

---

### Send logs from a browser to Remote Logging

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](https://github.com/thimpat/demos/blob/main/remote-logging/images/rl-analogger.gif
"Remote Logs")

<br/>

---

### Send logs from AnaLogger

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

<br/>

---

## Tests


### Use Remote-Logging as a Mocha Test reporter


Mocha is a JavaScript test framework: https://www.npmjs.com/package/mocha

<br/>

##### Description of how to have Remote-Logging working as an automated test viewer


* Install Remote-Logging

```shell
$> npm install remote-logging
```

<br/>

* Launch Remote-Logging

```shell
# Port by default
$> remote-logging --port 8221
```

<br/>

* Pass the path of the reporter to Mocha

```shell
mocha --reporter=./node_modules/remote-logging/reporter.cjs
```

<br/>

![Preview](https://github.com/thimpat/demos/blob/main/remote-logging/images/rl-report.gif "Mocha Reporter")


<br/>


### Reporter Options

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

<br/>

#### Example

##### Linux:

```shell
export ANALOGGER_TEST_PORT=12000
export ANALOGGER_LOG_FILE=reporter.log 
mocha --reporter=./node_modules/remote-logging/reporter.cjs
```

<br/>

##### Windows (Powershell)

```shell
$env:ANALOGGER_TEST_PORT = 12000
$env:ANALOGGER_LOG_FILE = "reporter.log" 
mocha --reporter=./node_modules/remote-logging/reporter.cjs
```

<br/>

---


### Uninstall Remote-logging

```shell
$> npm remove remote-logging -g
```
<br/>


---


### Changelog

##### current:
*  Fix Js error in reporter


##### 1.4.2:
*  Display Remote-Logging version in the console


##### 1.4.0:
*  Set up Remote Logging as a Mocha reporter
*  Open a new window with the application icon
*  Review screenshot viewer for takeScreenshot plugin


##### 1.3.1:
*  Fix updater


##### 1.2.0:
*  Release standard input in CLI after launching Remote-Logging


##### 1.1.2:
*  Remove close button from splash screen progress bar
*  Display port in the notification
*  Show tray notification when the application starts
*  Review the exit button from the tray icon
*  Fix missing screenshots
*  Fix messages not being logged
*  Fix bug with failing ips
*  Select listening port with --port option
*  Review layout
*  Fix application launcher



---


