Skip to content

Commit

Permalink
Fixed up logging, kind of
Browse files Browse the repository at this point in the history
  • Loading branch information
strawmelonjuice committed Jul 30, 2024
1 parent e51c4f6 commit ed79f73
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ src/client.js
/.idea/
/tryout
*.dump
/source/Plugin-runners/node-plugin-api/dist/
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions source/Main/src/externalpluginservers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::sync::Arc;

use actix_web::web::Data;
use interactive_process::InteractiveProcess;
use log::debug;
use log::{debug, error, info, warn};
use serde::{Deserialize, Serialize};
use serde_json::from_str;
use tokio::sync::mpsc::Receiver;
Expand Down Expand Up @@ -93,13 +93,23 @@ pub(crate) async fn main(
}
} else {
if o.replace("\n", "").is_empty() {
// Just wait for the next line lol
// Just wait for the next line
} else {
let mut z = y.lock().unwrap();
z.clear();
config_clone
.clone()
.tell(format!("[JsPluginRuntime]: {}", o));
if o.starts_with("info: ") {
info!("[JsPluginRuntime]: {}", o.split("info: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("debug: ") {
debug!("[JsPluginRuntime]: {}", o.split("debug: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("error: ") {
error!("[JsPluginRuntime]: {}", o.split("error: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("warn: ") {
warn!("[JsPluginRuntime]: {}", o.split("warn: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("log: "){
config_clone
.clone()
.tell(format!("[JsPluginRuntime]: {}", o.split("log: ").collect::<Vec<&str>>()[1]));
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions source/Plugin-runners/node-plugin-api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/


export interface Request {
id: number
body: TestRequestBody | unknown;
Expand Down Expand Up @@ -70,10 +72,30 @@ export interface ErrorResponse {
message?: string;
};
}
export namespace terminalOut {
export function log(str: string) {
console.log(`log: ${str}`);
}
export function error(str: string) {
console.log(`error: ${str}`);
}
export function warn(str: string) {
console.log(`warn: ${str}`);
}
export function info(str: string) {
console.log(`info: ${str}`);
}
export function debug(str: string) {
console.log(`debug: ${str}`);
}
}
;

export const Cynthia = {
send: (res: EmptyOKResponse | OkStringResponseType | OkJSONResponse | ErrorResponse) => {
console.log(`parse: ${JSON.stringify(res)}`);
},
console: console
};
export namespace Incoming {
export interface WebRequest {
Expand Down
7 changes: 5 additions & 2 deletions source/Plugin-runners/node-plugin-api/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "cynthia-plugin-api",
"type": "module",
"version": "1.0.0",
"module": "main.js",
"description": "Contains some classes and functions to help you create CynthiaWeb plugins.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"author": "MLC Bloeiman",
"license": "ISC",
"devDependencies": {
"@types/node": "latest"
"@types/node": "latest",
"typescript": "^5.0.0"
}
}
22 changes: 22 additions & 0 deletions source/Plugin-runners/node-plugin-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES5",
"lib": [
"dom",
"ES2021",
"ES2023"
],
"declaration": true,
"outDir": "./dist/",
"sourceMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"strict": true,
"noImplicitAny": false
},
"exclude": [
"./dist/"
],
"include": ["./"]
}
3 changes: 2 additions & 1 deletion source/Plugin-runners/node-plugin-runner/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import * as CynthiaPluginAPI from "cynthia-plugin-api/main";
import {Cynthia} from "cynthia-plugin-api/main";

import {terminalOut as console} from "../../node-plugin-api/main";
console.info("Node plugin server starting...");
const cynthiabase = {
modifyOutputHTML: [
(htmlin: string, Cynthia: typeof CynthiaPluginAPI.Cynthia) => {
Expand Down

0 comments on commit ed79f73

Please sign in to comment.