当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Tail.on方法代码示例

本文整理汇总了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);
  });
}
开发者ID:duniter,项目名称:duniter,代码行数:20,代码来源:daemon.ts

示例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");
    }
};
开发者ID:tosono,项目名称:Mirakurun,代码行数:38,代码来源:stream.ts

示例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();
        });
    });
开发者ID:tosono,项目名称:Mirakurun,代码行数:49,代码来源:update.ts

示例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();
    });
};
开发者ID:upsilon,项目名称:Mirakurun,代码行数:42,代码来源:update.ts

示例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());
 });
开发者ID:jonesnc,项目名称:gustav,代码行数:5,代码来源:helpers.ts

示例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'
});
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:26,代码来源:tail-tests.ts


注:本文中的tail.Tail.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。