buddy-tunnel
Advanced tools
Comparing version 1.4.5-dev to 1.4.6-dev
{ | ||
"name": "buddy-tunnel", | ||
"preferGlobal": false, | ||
"version": "1.4.5-dev", | ||
"version": "1.4.6-dev", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -78,6 +78,2 @@ const AgentSystem = require('./system'); | ||
getBinaryPath() { | ||
return path.join(this.getConfigDir(), 'buddy-tunnel.exe'); | ||
} | ||
async enable() { | ||
@@ -84,0 +80,0 @@ try { |
const { Command } = require('commander'); | ||
const AgentManager = require('../../agent/manager'); | ||
const logger = require('../../logger'); | ||
const commandAgentRun = new Command('run'); | ||
commandAgentRun.action(async () => { | ||
logger.changeRootPath(AgentManager.system.getConfigDir()); | ||
AgentManager.start(); | ||
@@ -7,0 +9,0 @@ }); |
@@ -8,37 +8,77 @@ const pino = require('pino'); | ||
const rootPath = getHomeDirectory(); | ||
const logPath = resolve(rootPath, 'cli.log'); | ||
const log1Path = resolve(rootPath, 'cli.1.log'); | ||
const logStream = fs.openSync(logPath, 'w'); | ||
const getDestination = () => { | ||
return pino.destination(logStream); | ||
}; | ||
const logger = pino({ | ||
level: process.env.DEBUG === '1' ? 'debug' : 'info', | ||
timestamp: () => `, "time": "${new Date().toISOString()}"`, | ||
formatters: { | ||
bindings: () => ({}), | ||
level: (label) => ({ | ||
level: label.toUpperCase() | ||
}) | ||
class Logger { | ||
rootPath = null; | ||
logPath = null; | ||
log1Path = null; | ||
logStream = null; | ||
p = null; | ||
ts = null; | ||
constructor() { | ||
this.rootPath = getHomeDirectory(); | ||
} | ||
}, getDestination()); | ||
checkLogSize() { | ||
try { | ||
const s = fs.statSync(this.logPath); | ||
if (s.size > 5242880) { | ||
fs.copyFileSync(this.logPath, this.log1Path); | ||
fs.truncateSync(this.logPath); | ||
} | ||
} catch { | ||
// do nothing | ||
} | ||
} | ||
getPino() { | ||
if (!this.p) { | ||
this.logPath = resolve(this.rootPath, 'cli.log'); | ||
this.log1Path = resolve(this.rootPath, 'cli.1.log'); | ||
this.logStream = fs.openSync(this.logPath, 'w'); | ||
this.p = pino({ | ||
level: process.env.DEBUG === '1' ? 'debug' : 'info', | ||
timestamp: () => `, "time": "${new Date().toISOString()}"`, | ||
formatters: { | ||
bindings: () => ({}), | ||
level: (label) => ({ | ||
level: label.toUpperCase() | ||
}) | ||
} | ||
}, pino.destination(this.logStream)); | ||
this.checkLogSize(); | ||
this.ts = setInterval(() => { | ||
this.checkLogSize(); | ||
}, 30000); | ||
} | ||
return this.p; | ||
} | ||
error(...args) { | ||
this.getPino().error(...args); | ||
} | ||
info(...args) { | ||
this.getPino().info(...args); | ||
} | ||
debug(...args){ | ||
this.getPino().debug(...args); | ||
} | ||
fatal(...args){ | ||
this.getPino().fatal(...args); | ||
} | ||
const checkLogSize = () => { | ||
try { | ||
const s = fs.statSync(logPath); | ||
if (s.size > 5242880) { | ||
fs.copyFileSync(logPath, log1Path); | ||
fs.truncateSync(logPath); | ||
changeRootPath(path) { | ||
if (this.ts) { | ||
clearInterval(this.ts); | ||
this.ts = null; | ||
} | ||
} catch (err) { | ||
// do nothing | ||
if (this.logStream) { | ||
try { | ||
this.logStream.close(); | ||
} catch { | ||
// do nothing | ||
} | ||
this.logStream = null; | ||
} | ||
this.p = null; | ||
this.rootPath = path; | ||
} | ||
}; | ||
} | ||
checkLogSize(); | ||
setInterval(checkLogSize, 30000); | ||
module.exports = logger; | ||
module.exports = new Logger(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
320338
7448