Skip to content

Commit

Permalink
fix: disable process logging from server (janhq#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Jan 2, 2024
1 parent e083d7a commit b5c72f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
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);
}
};

0 comments on commit b5c72f6

Please sign in to comment.