LoginSignup
5
5

More than 5 years have passed since last update.

PHPのエラーログをNode.jsで監視して通知してもらう。(Mac専用?)

Posted at

Windowsマシンが手元にないので、ちと検証出来ませんが、
Windowsの場合通知センターって右下のやつになるんですかね。
(前使ってたのXPなんですが、、、)

PHPのログが更新されたら通知が来るスクリプトを組んでみました。
これでPHPのデバッグも少しは楽になるかも?

coffeeScript勉強中なのでおかしいところがあったら教えて下さい。
むしろ俺ならこうするとかあったら言ってください。

必要なもの

  1. coffeeScript
  2. node.js
  3. terminal-notifier
  4. エラーがバンバン通知されても泣かない心
phplog.coffee

# パスはここに書く 相対パスは試してないけどいけるかな?
targetFile = "/PHP/logs/php_error.log"

# ファイルの読み込み
fs = require("fs")
exec = require('child_process').exec


# ファイルを監視
fs.watch( targetFile, (event, filename)->
    console.log "event is: " + event

    # ファイルの変更キャッチ
    if event is "change"
         # コマンドの実行
        exec("terminal-notifier -message 'PHP ERROR!' -title 'm9(^Д^)'", (err, stdout, stderr) ->
            console.log err

            )
     # 本当は末端行だけ取得してexecのメッセージに渡したらもっと幸せになれるかも

)

参考サイト

CoffeeScriptでNode.jsアプリを書いてみる
http://parrot.hatenadiary.jp/entry/20111207/1323245393

Node.jsでshellコマンドを叩く
http://d.hatena.ne.jp/muddydixon/20110708/1310134554

terminal-notifier で通知センターにコマンドラインから通知
http://heartbeatheart.blogspot.jp/2012/08/terminal-notifier.html

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5