Skip to content

Commit

Permalink
add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Nov 27, 2017
1 parent 0cf8ea0 commit f02ff80
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 44 deletions.
38 changes: 19 additions & 19 deletions pluto-models/Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
HISTORY.md
Manifest.txt
README.md
Rakefile
lib/pluto/connecter.rb
lib/pluto/models.rb
lib/pluto/models/feed.rb
lib/pluto/models/forward.rb
lib/pluto/models/item.rb
lib/pluto/models/site.rb
lib/pluto/models/subscription.rb
lib/pluto/models/utils.rb
lib/pluto/schema.rb
lib/pluto/version.rb
test/data/ruby.ini
test/helper.rb
test/test_filter.rb
test/test_helpers.rb
test/test_site.rb
HISTORY.md
Manifest.txt
README.md
Rakefile
lib/pluto/connecter.rb
lib/pluto/models.rb
lib/pluto/models/feed.rb
lib/pluto/models/forward.rb
lib/pluto/models/item.rb
lib/pluto/models/site.rb
lib/pluto/models/subscription.rb
lib/pluto/models/utils.rb
lib/pluto/schema.rb
lib/pluto/version.rb
test/data/ruby.ini
test/helper.rb
test/test_filter.rb
test/test_helpers.rb
test/test_site.rb
16 changes: 9 additions & 7 deletions pluto-models/lib/pluto/connecter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,29 @@ def connect( config={} )
end
end # if config.nil?

puts 'db settings:'
pp config
logger.info 'db settings:'
logger.info config.pretty_inspect

### for dbbrowser and other tools add to ActiveRecord

if ActiveRecord::Base.configurations.nil? # todo/check: can this ever happen? remove?
puts "ActiveRecord configurations nil - set to empty hash"
logger.debug "ActiveRecord configurations nil - set to empty hash"
ActiveRecord::Base.configurations = {} # make it an empty hash
end

## todo/fix: remove debug? option - why? why not?
## (just) use logger level eg. logger.debug
if debug?
puts 'ar configurations (before):'
pp ActiveRecord::Base.configurations
logger.debug 'ar configurations (before):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end

# note: for now always use pluto key for config storage
ActiveRecord::Base.configurations['pluto'] = config

if debug?
puts 'ar configurations (after):'
pp ActiveRecord::Base.configurations
logger.debug 'ar configurations (after):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end


Expand Down
31 changes: 22 additions & 9 deletions pluto-models/lib/pluto/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
module Pluto
module Model


class Feed < ActiveRecord::Base

## logging w/ ActiveRecord
## todo/check: check if logger instance method is present by default?
## only class method present?
## what's the best way to add logging to activerecord (use "builtin" machinery??)

def debug=(value) @debug = value; end
def debug?() @debug || false; end



self.table_name = 'feeds'

has_many :items
Expand Down Expand Up @@ -72,12 +84,11 @@ def published
end


def debug=(value) @debug = value; end
def debug?() @debug || false; end


def deep_update_from_struct!( data )

logger = LogUtils::Logger.root

######
## check for filters (includes/excludes) if present
## for now just check for includes
Expand All @@ -90,18 +101,18 @@ def deep_update_from_struct!( data )

data.items.each do |item|
if includesFilter && includesFilter.match_item?( item ) == false
puts "** SKIPPING | #{item.title}"
puts " no include terms match: #{includes}"
logger.info "** SKIPPING | #{item.title}"
logger.info " no include terms match: #{includes}"
next ## skip to next item
end

item_rec = Item.find_by_guid( item.guid )
if item_rec.nil?
item_rec = Item.new
puts "** NEW | #{item.title}"
logger.info "** NEW | #{item.title}"
else
## todo: check if any attribs changed
puts "UPDATE | #{item.title}"
logger.info "UPDATE | #{item.title}"
end

item_rec.debug = debug? ? true : false # pass along debug flag
Expand Down Expand Up @@ -133,6 +144,8 @@ def deep_update_from_struct!( data )

def update_from_struct!( data )

logger = LogUtils::Logger.root

##
# todo:
## strip all tags from summary (subtitle)
Expand All @@ -158,9 +171,9 @@ def update_from_struct!( data )
if debug?
## puts "*** dump feed_attribs:"
## pp feed_attribs
puts "*** dump feed_attribs w/ class types:"
logger.debug "*** dump feed_attribs w/ class types:"
feed_attribs.each do |key,value|
puts " #{key}: >#{value}< : #{value.class.name}"
logger.debug " #{key}: >#{value}< : #{value.class.name}"
end
end

Expand Down
20 changes: 15 additions & 5 deletions pluto-models/lib/pluto/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ module Pluto
module Model

class Item < ActiveRecord::Base

## logging w/ ActiveRecord
## todo/check: check if logger instance method is present by default?
## only class method present?
## what's the best way to add logging to activerecord (use "builtin" machinery??)

def debug=(value) @debug = value; end
def debug?() @debug || false; end


self.table_name = 'items'

belongs_to :feed
Expand Down Expand Up @@ -46,11 +56,11 @@ def published
end


def debug=(value) @debug = value; end
def debug?() @debug || false; end


def update_from_struct!( data )

logger = LogUtils::Logger.root

## check: new item/record? not saved? add guid
# otherwise do not add guid - why? why not?

Expand All @@ -68,10 +78,10 @@ def update_from_struct!( data )
}

if debug?
puts "*** dump item_attribs w/ class types:"
logger.debug "*** dump item_attribs w/ class types:"
item_attribs.each do |key,value|
next if [:summary,:content].include?( key ) # skip summary n content
puts " #{key}: >#{value}< : #{value.class.name}"
logger.debug " #{key}: >#{value}< : #{value.class.name}"
end
end

Expand Down
8 changes: 6 additions & 2 deletions pluto-models/lib/pluto/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module Pluto
module Model

class Site < ActiveRecord::Base



self.table_name = 'sites'

has_many :subscriptions
Expand Down Expand Up @@ -46,6 +49,8 @@ def self.deep_create_or_update_from_hash!( name, config, opts={} )

def deep_update_from_hash!( config, opts={} )

logger = LogUtils::Logger.root

site_attribs = {
title: config['title'] || config['name'], # support either title or name
url: config['source'] || config['url'], # support source or url for source url for auto-update (optional)
Expand All @@ -59,7 +64,6 @@ def deep_update_from_hash!( config, opts={} )
site_attribs[:key] = site_key if site_key


logger = LogUtils::Logger.root
logger.debug "site_attribs: #{site_attribs.inspect}"

if new_record?
Expand Down Expand Up @@ -169,7 +173,7 @@ def deep_update_from_hash!( config, opts={} )
end


puts "Updating feed subscription >#{feed_key}< - >#{feed_attribs[:feed_url]}<..."
logger.info "Updating feed subscription >#{feed_key}< - >#{feed_attribs[:feed_url]}<..."

feed_rec = Feed.find_by_key( feed_key )
if feed_rec.nil?
Expand Down
4 changes: 2 additions & 2 deletions pluto-models/lib/pluto/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module Pluto

MAJOR = 1
MINOR = 4
PATCH = 1
MINOR = 5
PATCH = 0
VERSION = [MAJOR,MINOR,PATCH].join('.')

def self.version
Expand Down

0 comments on commit f02ff80

Please sign in to comment.