Project

lognotify

0.0
No commit activity in last 3 years
No release in over 3 years
Actively monitors a log file for new entries which can trigger an event using a regular expression
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.4.0, ~> 0.4
 Project Readme

Introducing the lognotify gem

In an effort to pay more attention to log files I wrote the lognotify gem to make it convenient to monitor a log file's recent entries.

require 'lognotify'


ln = LogNotify.new('/tmp/mail.info')

def ln.on_update(entry)

  puts 'entry: ' + entry.inspect

  if entry =~ /citserver\[1988\]: Context: <james> logged in/ then
    puts 'James logged into the mail server'
  end
  
end

ln.start

In the above example the lognotify gem monitors the updates to the file /tmp/mail.info and prints out the most recent log entry. It checks if James has logged into the mail server and if he has it prints out the following message:

James logged into the mail server

Show below is the code used to create a sample log file while lognotify was running:

require 'logger'

log = Logger.new '/tmp/mail.info'
log.info 'testing'
sleep 2
log.info 'box1 citserver[1988]: Context: <james> logged in'
sleep 1
log.info 'new mail arrived'
log.close

Output:

entry: "I, [2015-10-04T10:26:38.444514 #5675]  INFO -- : testing\n"
entry: "I, [2015-10-04T10:26:40.446443 #5675]  INFO -- : box1 citserver[1988]: Context:  logged in\n"
James logged into the mail server
entry: "I, [2015-10-04T10:26:41.447813 #5675]  INFO -- : new mail arrived\n"

Resources

lognotify gem log monitor