2023-06-06 14:25:31 +00:00
|
|
|
import pino from "pino";
|
2023-07-13 08:31:20 +00:00
|
|
|
import { isBrowser, isTest, testLogDebug } from "./env";
|
2023-06-15 15:53:21 +00:00
|
|
|
|
2023-06-06 14:25:31 +00:00
|
|
|
/**
|
|
|
|
|
* Stream not available in browser, will use default console output.
|
|
|
|
|
*/
|
2023-07-13 08:31:20 +00:00
|
|
|
const stream =
|
|
|
|
|
isBrowser || isTest
|
|
|
|
|
? null
|
|
|
|
|
: /**
|
2023-09-10 02:25:23 +00:00
|
|
|
* Default rotating file locate at `~/.tabby-client/agent/logs/`.
|
2023-07-13 08:31:20 +00:00
|
|
|
*/
|
|
|
|
|
require("rotating-file-stream").createStream("tabby-agent.log", {
|
2023-09-10 02:25:23 +00:00
|
|
|
path: require("path").join(require("os").homedir(), ".tabby-client", "agent", "logs"),
|
2023-07-13 08:31:20 +00:00
|
|
|
size: "10M",
|
|
|
|
|
interval: "1d",
|
|
|
|
|
});
|
2023-06-06 14:25:31 +00:00
|
|
|
|
|
|
|
|
export const rootLogger = !!stream ? pino(stream) : pino();
|
2023-07-13 08:31:20 +00:00
|
|
|
if (isTest && testLogDebug) {
|
|
|
|
|
rootLogger.level = "debug";
|
|
|
|
|
}
|
2023-06-06 14:25:31 +00:00
|
|
|
|
|
|
|
|
export const allLoggers = [rootLogger];
|
|
|
|
|
rootLogger.onChild = (child) => {
|
|
|
|
|
allLoggers.push(child);
|
|
|
|
|
};
|