Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable process logging from server #1296

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './extension/store'
export * from './download'
export * from './module'
export * from './api'
export * from './log'
14 changes: 14 additions & 0 deletions core/src/node/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from 'fs'
import util from 'util'
import path from 'path'
import os from 'os'

export const logPath = path.join(os.homedir(), 'jan', 'app.log')

var log_file = fs.createWriteStream(logPath, {
flags: 'a',
})

export const log = function (d: any) {
log_file.write(util.format(d) + '\n')
}
25 changes: 5 additions & 20 deletions server/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import fastify from "fastify";
import dotenv from "dotenv";
import { v1Router } from "@janhq/core/node";
import { log, v1Router } from "@janhq/core/node";
import path from "path";
import fs from "fs";
import util from "util";

import os from "os";

dotenv.config();
Expand All @@ -14,18 +13,6 @@ const serverLogPath = path.join(os.homedir(), "jan", "server.log");

let server: any | undefined = undefined;

var log_file = fs.createWriteStream(serverLogPath, {
flags: "a",
});
var log_stdout = process.stdout;
var log_stderr = process.stderr;

const logServer = function (d: any) {
log_file.write(util.format(d) + "\n");
log_stdout.write(util.format(d) + "\n");
log_stderr.write(util.format(d) + "\n");
};

export const startServer = async (schemaPath?: string, baseDir?: string) => {
try {
server = fastify({
Expand Down Expand Up @@ -75,19 +62,17 @@ export const startServer = async (schemaPath?: string, baseDir?: string) => {
host: JAN_API_HOST,
})
.then(() => {
logServer(
`JAN API listening at: http://${JAN_API_HOST}:${JAN_API_PORT}`
);
log(`JAN API listening at: http://${JAN_API_HOST}:${JAN_API_PORT}`);
});
} catch (e) {
logServer(e);
log(e);
}
};

export const stopServer = async () => {
try {
await server.close();
} catch (e) {
logServer(e);
log(e);
}
};
Loading