fix: disable process logging from server (#1296)

This commit is contained in:
Louis 2024-01-02 23:26:36 +07:00 committed by GitHub
parent e083d7a30e
commit b5c72f65cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 20 deletions

View File

@ -5,3 +5,4 @@ export * from './extension/store'
export * from './download'
export * from './module'
export * from './api'
export * from './log'

14
core/src/node/log.ts Normal file
View File

@ -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')
}

View File

@ -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();
@ -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({
@ -75,12 +62,10 @@ 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);
}
};
@ -88,6 +73,6 @@ export const stopServer = async () => {
try {
await server.close();
} catch (e) {
logServer(e);
log(e);
}
};