本文整理汇总了TypeScript中tail.Tail.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Tail.on方法的具体用法?TypeScript Tail.on怎么用?TypeScript Tail.on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tail.Tail
的用法示例。
在下文中一共展示了Tail.on方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: watchFile
function watchFile(file:any) {
const tail = new Tail(file);
// Specific errors handling
process.on('uncaughtException', (err:any) => {
if (err.code === "ENOENT") {
console.error('EXCEPTION: ', err.message);
setTimeout(() => watchFile(file), 1000) // Wait a second
}
});
// On new line
tail.on("line", function(data:any) {
console.log(data);
});
tail.on("error", function(error:any) {
console.error('ERROR: ', error);
});
}
示例2: Tail
export const get: Operation = (req, res) => {
if (!process.env.LOG_STDOUT || !process.env.LOG_STDERR) {
res.writeHead(500, "Unknown Logfile Path", {
"Content-Type": "text/plain"
});
res.end("Unknown Logfile Path");
return;
}
if (!fs.existsSync(process.env.LOG_STDOUT) || !fs.existsSync(process.env.LOG_STDERR)) {
res.writeHead(500, "Logfile Unavailable", {
"Content-Type": "text/plain"
});
res.end("Logfile Unavailable");
return;
}
res.setHeader("Content-Type", "text/plain; charset=utf-8");
res.status(200);
const stdout = new Tail(process.env.LOG_STDOUT);
const stderr = new Tail(process.env.LOG_STDERR);
req.setTimeout(1000 * 60 * 60, () => { });
req.once("close", () => {
stdout.removeListener("line", _listener);
stdout.unwatch();
stderr.removeListener("line", _listener);
stderr.unwatch();
});
stdout.on("line", _listener);
stderr.on("line", _listener);
function _listener(data: string) {
res.write(data + "\n");
}
};
示例3: latestVersion
latestVersion("mirakurun").then(latest => {
if (!req.query.force && current === latest) {
api.responseError(res, 409, "Update Nothing");
return;
}
let command;
const args = [
"install",
"mirakurun@latest",
"-g",
"--production"
];
if (process.platform === "win32") {
command = "npm.cmd";
} else {
command = "npm";
args.push("--unsafe");
}
res.setHeader("Content-Type", "text/plain; charset=utf-8");
res.status(202);
res.write("Updating...\n");
const path = join(tmpdir(), "Mirakurun_Updating.log");
if (existsSync(path) === true) {
unlinkSync(path);
}
const out = openSync(path, "a");
const err = openSync(path, "a");
res.write(`> ${command} ${args.join(" ")}\n\n`);
const npm = spawn(command, args, {
detached: true,
stdio: ["ignore", out, err]
});
npm.unref();
const tail = new Tail(path);
tail.on("line", data => res.write(data + "\n"));
req.once("close", () => {
tail.removeAllListener("line");
tail.unwatch();
});
});
示例4: async
export const put: Operation = async (req, res) => {
if (!req.query.force && !process.env.pm_uptime && !process.env.USING_WINSER) {
api.responseError(res, 500);
return;
}
const latest = await latestVersion("mirakurun");
if (!req.query.force && current === latest) {
api.responseError(res, 409, "Update Nothing");
return;
}
res.setHeader("Content-Type", "text/plain; charset=utf-8");
res.status(202);
res.write("Updating...\n");
const path = join(tmpdir(), "Mirakurun_Updating.log");
if (existsSync(path) === true) {
unlinkSync(path);
}
const out = openSync(path, "a");
const err = openSync(path, "a");
res.write(`> node lib/updater\n\n`);
const npm = spawn("node", ["lib/updater"], {
detached: true,
stdio: ["ignore", out, err]
});
npm.unref();
const tail = new Tail(path);
tail.on("line", data => res.write(data + "\n"));
req.once("close", () => {
tail.removeAllListeners("line");
tail.unwatch();
});
};
示例5: Observable
return new Observable(o => {
logTail.on('line', (line) => o.next(line));
logTail.on('err', (err) => o.error(err));
logTail.on('end', () => o.complete());
});
示例6: Tail
import { Tail } from 'tail';
const tail = new Tail("test.txt");
tail.on("line", data => {
console.log(data);
});
tail.on("error", error => {
console.log('ERROR: ', error);
});
tail.unwatch();
tail.watch();
// With options object
const tail2 = new Tail("test2.txt", {
separator: /[\r]{0,1}\n/,
fromBeginning: false,
fsWatchOptions: {},
follow: true,
logger: console,
useWatchFile: false,
encoding: 'utf-8'
});