Skip to content

Commit 36bc568

Browse files
committed
Import cdplogger-client into logger/ subdirectory
Merge JavascriptCDPLoggerClient repository into logger/ with full commit history preserved. All files imported unchanged. Source: https://github.com/CDPTechnologies/JavascriptCDPLoggerClient
2 parents c813745 + bd73418 commit 36bc568

16 files changed

Lines changed: 14304 additions & 0 deletions

File tree

logger/.github/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# CDPLogger Client for JavaScript
2+
3+
A simple JavaScript interface for communicating with CDP applications that include a CDPLogger component to retrieve historic data.
4+
- For documentation on the JS logger client see [DOCUMENTATION.md](../DOCUMENTATION.md).
5+
- For a quickstart guide on how to set-up the npm project for either Node or Web see [QUICKSTART.md](../QUICKSTART.md)
6+
- For more information about CDP Studio see https://cdpstudio.com/.
7+
8+
## Installation
9+
10+
### NPM Package (Recommended)
11+
12+
```bash
13+
npm install cdplogger-client
14+
```
15+
16+
### Development Setup
17+
18+
Clone the repository and install dependencies:
19+
20+
```bash
21+
git clone https://github.com/CDPTechnologies/JavascriptCDPLoggerClient.git
22+
cd JavascriptCDPLoggerClient
23+
npm install
24+
```
25+
26+
27+
## Running Tests
28+
29+
To run the automatic tests with fake data, execute:
30+
31+
```bash
32+
npm test
33+
```
34+
35+
Note: these jest tests execute on every push and pull of the repo as well.
36+
37+
To test the time sync functionality using simulated response:
38+
39+
```bash
40+
node test/testTimeSync.js
41+
```
42+
43+
44+
## Usage
45+
46+
The value.js file contains a simple logger built for the CDP Studio example case.
47+
48+
1. Set up and run the Logger in CDP Studio.
49+
(Refer to Help → Framework - Data Logging → How to Setup Logging in Automation System)
50+
https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-configuration-example.html
51+
52+
2. Run the value.js file from the command line:
53+
54+
```bash
55+
node examples/value.js
56+
```
57+
58+
For usage related to events run:
59+
60+
```bash
61+
node examples/event.js
62+
```
63+
64+
65+
## Contact
66+
67+
Email: support@cdptech.com

logger/.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Run Jest Tests
2+
3+
on:
4+
push:
5+
branches: [ '**' ] # Run on all branches
6+
pull_request:
7+
branches: [ '**' ] # Run on PRs targeting any branch
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '18'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run tests
26+
run: npm test
27+
28+
- name: Cleanup
29+
if: always()
30+
run: |
31+
echo "Cleaning up..."
32+
rm -rf node_modules
33+
rm -rf .npm

logger/.gitignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
11+
# Runtime data
12+
pids
13+
*.pid
14+
*.seed
15+
*.pid.lock
16+
17+
# Directory for instrumented libs generated by jscoverage/JSCover
18+
lib-cov
19+
20+
# Coverage directory used by tools like istanbul
21+
coverage
22+
23+
# nyc test coverage
24+
.nyc_output
25+
26+
# Grunt intermediate storage
27+
.grunt
28+
29+
# Bower dependency directory
30+
bower_components
31+
32+
# node-waf configuration
33+
.lock-wscript
34+
35+
# Compiled binary addons
36+
build/Release
37+
38+
# Dependency directories
39+
jspm_packages/
40+
41+
# TypeScript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# dotenv environment variables file
60+
.env
61+
62+
# next.js build output
63+
.next
64+
65+
# npm config file
66+
.npmrc
67+
68+
protos/

logger/DOCUMENTATION.md

Lines changed: 301 additions & 0 deletions
Large diffs are not rendered by default.

logger/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 CDP Technologies
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

logger/QUICKSTART.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Quick Start Guide – CDPLogger Client
2+
3+
This guide demonstrates how to get started with the CDPLogger Client in both **Node.js** and **Browser** environments. The client automatically detects the environment and works seamlessly in both.
4+
5+
## Documentation
6+
7+
For documentation on the JS logger client see [DOCUMENTATION.md](DOCUMENTATION.md)
8+
9+
## Overview
10+
11+
The CDPLogger Client uses **automatic environment detection** to work in both Node.js and browser environments from a single source file:
12+
13+
- **Node.js:**
14+
- Automatically loads protobuf definitions using `require('./generated/containerPb.js')`
15+
- Uses the `ws` package for WebSocket functionality (installed as a dependency)
16+
- No manual setup required
17+
18+
- **Browser:**
19+
- Uses the browser's native WebSocket API
20+
- Expects protobuf definitions to be available at `window.root`
21+
- Requires including the containerPb.js script before the client
22+
23+
## Installation
24+
25+
### For Node.js
26+
27+
```bash
28+
npm install cdplogger-client
29+
```
30+
31+
### For Browser
32+
33+
Include the following scripts in your HTML:
34+
- `protobuf.min.js` – for the ProtoBuf runtime.
35+
- `containerPb.js` – which sets up `window.root` with your protobuf definitions
36+
- `client.js` – the same file works in both Node.js and browser environments
37+
- Instead of importing protobuf definitions via CommonJS, obtain them from the global scope:
38+
```js
39+
const root = window.root;
40+
const Container = root.DBMessaging.Protobuf.Container;
41+
const CDPValueType = root.ICD.Protobuf.CDPValueType;
42+
const EventQuery = root.DBMessaging.Protobuf.EventQuery;
43+
```
44+
45+
## Usage
46+
47+
### Node.js Example
48+
49+
```js
50+
// Import the client
51+
const cdplogger = require('cdplogger-client');
52+
53+
// Create a client instance (endpoint can be "127.0.0.1:17000" or "ws://127.0.0.1:17000")
54+
const client = new cdplogger.Client('127.0.0.1:17000');
55+
56+
// List logged nodes (displaying name and routing information)
57+
client.requestLoggedNodes().then(nodes => {
58+
nodes.forEach(node => {
59+
console.log(`Name: ${node.name}, Routing: ${node.routing}`);
60+
});
61+
62+
// If we have nodes, request data points for the first one
63+
if (nodes.length > 0) {
64+
const nodeName = nodes[0].name;
65+
console.log(`\nRequesting data points for node: ${nodeName}`);
66+
67+
// Get log limits and request data points
68+
client.requestLogLimits().then(limits => {
69+
return client.requestDataPoints([nodeName], limits.startS, limits.endS, 10, 0);
70+
}).then(dataPoints => {
71+
console.log(`\nReceived ${dataPoints.length} data points:`);
72+
dataPoints.forEach(point => {
73+
console.log(`Timestamp: ${new Date(point.timestamp * 1000).toISOString()}`);
74+
if (point.value && point.value[nodeName]) {
75+
const val = point.value[nodeName];
76+
console.log(` Min: ${val.min}, Max: ${val.max}, Last: ${val.last}`);
77+
}
78+
});
79+
}).catch(err => {
80+
console.error("Error retrieving data points:", err);
81+
});
82+
}
83+
});
84+
85+
// Disconnect after a short delay (for demonstration purposes)
86+
setTimeout(() => {
87+
client.disconnect();
88+
process.exit(0);
89+
}, 5000);
90+
```
91+
92+
*The client automatically detects the Node.js environment and uses the `ws` package for WebSocket functionality.*
93+
94+
### Browser Example
95+
96+
Create an HTML file that includes the necessary scripts. For example:
97+
98+
```html
99+
<!DOCTYPE html>
100+
<html>
101+
<head>
102+
<meta charset="UTF-8">
103+
<title>CDPLogger Client Quick Start</title>
104+
<!-- Include the protobuf runtime -->
105+
<script src="protobuf.min.js"></script>
106+
<!-- Include containerPb.js to set up global "root" -->
107+
<script src="containerPb.js"></script>
108+
<!-- Include client.js -->
109+
<script src="client.js"></script>
110+
</head>
111+
<body>
112+
<script>
113+
// Access protobuf definitions from global scope
114+
const root = window.root;
115+
const Container = root.DBMessaging.Protobuf.Container;
116+
const CDPValueType = root.ICD.Protobuf.CDPValueType;
117+
const EventQuery = root.DBMessaging.Protobuf.EventQuery;
118+
119+
// The client is now available globally as "cdplogger" (attached to window)
120+
// Use window.location.hostname to connect to the same host as the web page
121+
const client = new cdplogger.Client(window.location.hostname + ":17000");
122+
123+
// List logged nodes and output their names and routings
124+
client.requestLoggedNodes().then(nodes => {
125+
nodes.forEach(node => {
126+
console.log(`Name: ${node.name}, Routing: ${node.routing}`);
127+
});
128+
129+
// If we have nodes, request data points for the first one
130+
if (nodes.length > 0) {
131+
const nodeName = nodes[0].name;
132+
console.log(`\nRequesting data points for node: ${nodeName}`);
133+
134+
// Get log limits and request data points
135+
client.requestLogLimits().then(limits => {
136+
return client.requestDataPoints([nodeName], limits.startS, limits.endS, 10, 0);
137+
}).then(dataPoints => {
138+
console.log(`\nReceived ${dataPoints.length} data points:`);
139+
dataPoints.forEach(point => {
140+
console.log(`Timestamp: ${new Date(point.timestamp * 1000).toISOString()}`);
141+
if (point.value && point.value[nodeName]) {
142+
const val = point.value[nodeName];
143+
console.log(` Min: ${val.min}, Max: ${val.max}, Last: ${val.last}`);
144+
}
145+
});
146+
}).catch(err => {
147+
console.error("Error retrieving data points:", err);
148+
});
149+
}
150+
});
151+
</script>
152+
</body>
153+
</html>
154+
```
155+
156+
*In the browser version, we use `window.location.hostname` to connect to the same host as the web page, with the default logger port 17000.*
157+
158+
## Prerequisites
159+
160+
- **CDP Studio:** Ensure a CDP Studio application is running with an active **CDPLogger** (or LogServer) on a known WebSocket port (e.g., 17000).
161+
- **For Node.js:** No additional setup required - WebSocket support is automatically configured.
162+
- **For Browser:** Ensure `containerPb.js` is available and sets up `window.root` with protobuf definitions.
163+
164+
## Learn More
165+
166+
- [Full README](https://github.com/CDPTechnologies/JavascriptCDPLoggerClient)
167+
- [CDP Logger Documentation](https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-configuration-manual.html)

0 commit comments

Comments
 (0)