Moved to framework logger object.
This commit is contained in:
parent
0225ba1cdf
commit
d9938f59c6
6 changed files with 35 additions and 40 deletions
|
@ -182,7 +182,7 @@ returns
|
||||||
if self.class.column_names.include? 'updated_by_id'
|
if self.class.column_names.include? 'updated_by_id'
|
||||||
if UserInfo.current_user_id
|
if UserInfo.current_user_id
|
||||||
if self.updated_by_id && self.updated_by_id != UserInfo.current_user_id
|
if self.updated_by_id && self.updated_by_id != UserInfo.current_user_id
|
||||||
puts "NOTICE create - self.updated_by_id is different: #{self.updated_by_id.to_s}/#{UserInfo.current_user_id.to_s}"
|
logger.info "NOTICE create - self.updated_by_id is different: #{self.updated_by_id.to_s}/#{UserInfo.current_user_id.to_s}"
|
||||||
end
|
end
|
||||||
self.updated_by_id = UserInfo.current_user_id
|
self.updated_by_id = UserInfo.current_user_id
|
||||||
end
|
end
|
||||||
|
@ -190,7 +190,7 @@ returns
|
||||||
if self.class.column_names.include? 'created_by_id'
|
if self.class.column_names.include? 'created_by_id'
|
||||||
if UserInfo.current_user_id
|
if UserInfo.current_user_id
|
||||||
if self.created_by_id && self.created_by_id != UserInfo.current_user_id
|
if self.created_by_id && self.created_by_id != UserInfo.current_user_id
|
||||||
puts "NOTICE create - self.created_by_id is different: #{self.created_by_id.to_s}/#{UserInfo.current_user_id.to_s}"
|
logger.info "NOTICE create - self.created_by_id is different: #{self.created_by_id.to_s}/#{UserInfo.current_user_id.to_s}"
|
||||||
end
|
end
|
||||||
self.created_by_id = UserInfo.current_user_id
|
self.created_by_id = UserInfo.current_user_id
|
||||||
end
|
end
|
||||||
|
@ -426,7 +426,7 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
puts "#{ self.class.name }.find(#{ self.id }) notify created " + self.created_at.to_s
|
logger.debug "#{ self.class.name }.find(#{ self.id }) notify created " + self.created_at.to_s
|
||||||
class_name = self.class.name
|
class_name = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Sessions.broadcast(
|
Sessions.broadcast(
|
||||||
|
@ -454,7 +454,7 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
puts "#{ self.class.name }.find(#{ self.id }) notify UPDATED " + self.updated_at.to_s
|
logger.debug "#{ self.class.name }.find(#{ self.id }) notify UPDATED " + self.updated_at.to_s
|
||||||
class_name = self.class.name
|
class_name = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Sessions.broadcast(
|
Sessions.broadcast(
|
||||||
|
@ -481,7 +481,7 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
puts "#{ self.class.name }.find(#{ self.id }) notify DESTOY " + self.updated_at.to_s
|
logger.debug "#{ self.class.name }.find(#{ self.id }) notify DESTOY " + self.updated_at.to_s
|
||||||
class_name = self.class.name
|
class_name = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Sessions.broadcast(
|
Sessions.broadcast(
|
||||||
|
@ -934,7 +934,7 @@ check string/varchar size and cut them if needed
|
||||||
if column && limit
|
if column && limit
|
||||||
current_length = attribute[1].to_s.length
|
current_length = attribute[1].to_s.length
|
||||||
if limit < current_length
|
if limit < current_length
|
||||||
puts "WARNING: cut string because of database length #{self.class.to_s}.#{attribute[0]}(#{limit} but is #{current_length}:#{attribute[1].to_s})"
|
logger.info "WARNING: cut string because of database length #{self.class.to_s}.#{attribute[0]}(#{limit} but is #{current_length}:#{attribute[1].to_s})"
|
||||||
self[ attribute[0] ] = attribute[1][ 0, limit ]
|
self[ attribute[0] ] = attribute[1][ 0, limit ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Package < ApplicationModel
|
||||||
end
|
end
|
||||||
if data[:output]
|
if data[:output]
|
||||||
location = data[:output] + '/' + package.elements["zpm/name"].text + '-' + package.elements["zpm/version"].text + '.zpm'
|
location = data[:output] + '/' + package.elements["zpm/name"].text + '-' + package.elements["zpm/version"].text + '.zpm'
|
||||||
puts "NOTICE: writting package to '#{location}'"
|
logger.info "NOTICE: writting package to '#{location}'"
|
||||||
file = File.new( location, 'wb' )
|
file = File.new( location, 'wb' )
|
||||||
file.write( package.to_s )
|
file.write( package.to_s )
|
||||||
file.close
|
file.close
|
||||||
|
@ -67,12 +67,12 @@ class Package < ApplicationModel
|
||||||
# link files
|
# link files
|
||||||
Dir.glob( @@root + '/**/*' ) do |entry|
|
Dir.glob( @@root + '/**/*' ) do |entry|
|
||||||
if File.symlink?( entry)
|
if File.symlink?( entry)
|
||||||
puts "unlink: #{entry}"
|
logger.info "unlink: #{entry}"
|
||||||
File.delete( entry )
|
File.delete( entry )
|
||||||
end
|
end
|
||||||
backup_file = entry + '.link_backup'
|
backup_file = entry + '.link_backup'
|
||||||
if File.exists?( backup_file )
|
if File.exists?( backup_file )
|
||||||
puts "Restore backup file of #{backup_file} -> #{entry}."
|
logger.info "Restore backup file of #{backup_file} -> #{entry}."
|
||||||
File.rename( backup_file, entry )
|
File.rename( backup_file, entry )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -87,7 +87,7 @@ class Package < ApplicationModel
|
||||||
if package == false
|
if package == false
|
||||||
raise "Can't link package, '#{package_base_dir}' is no package source directory!"
|
raise "Can't link package, '#{package_base_dir}' is no package source directory!"
|
||||||
end
|
end
|
||||||
puts package.inspect
|
logger.debug package.inspect
|
||||||
return package
|
return package
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -109,13 +109,13 @@ class Package < ApplicationModel
|
||||||
dest = @@root + '/' + file
|
dest = @@root + '/' + file
|
||||||
|
|
||||||
if File.symlink?( dest.to_s )
|
if File.symlink?( dest.to_s )
|
||||||
puts "Unlink file: #{dest.to_s}"
|
logger.info "Unlink file: #{dest.to_s}"
|
||||||
File.delete( dest.to_s )
|
File.delete( dest.to_s )
|
||||||
end
|
end
|
||||||
|
|
||||||
backup_file = dest.to_s + '.link_backup'
|
backup_file = dest.to_s + '.link_backup'
|
||||||
if File.exists?( backup_file )
|
if File.exists?( backup_file )
|
||||||
puts "Restore backup file of #{backup_file} -> #{dest.to_s}."
|
logger.info "Restore backup file of #{backup_file} -> #{dest.to_s}."
|
||||||
File.rename( backup_file, dest.to_s )
|
File.rename( backup_file, dest.to_s )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -137,7 +137,7 @@ class Package < ApplicationModel
|
||||||
|
|
||||||
# ignore files
|
# ignore files
|
||||||
if file =~ /^README/
|
if file =~ /^README/
|
||||||
puts "NOTICE: Ignore #{file}"
|
logger.info "NOTICE: Ignore #{file}"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class Package < ApplicationModel
|
||||||
|
|
||||||
if File.directory?( entry.to_s )
|
if File.directory?( entry.to_s )
|
||||||
if !File.exists?( dest.to_s )
|
if !File.exists?( dest.to_s )
|
||||||
puts "Create dir: #{dest.to_s}"
|
logger.info "Create dir: #{dest.to_s}"
|
||||||
FileUtils.mkdir_p( dest.to_s )
|
FileUtils.mkdir_p( dest.to_s )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -156,7 +156,7 @@ class Package < ApplicationModel
|
||||||
if File.exists?( backup_file )
|
if File.exists?( backup_file )
|
||||||
raise "Can't link #{entry.to_s} -> #{dest.to_s}, destination and .link_backup already exists!"
|
raise "Can't link #{entry.to_s} -> #{dest.to_s}, destination and .link_backup already exists!"
|
||||||
else
|
else
|
||||||
puts "Create backup file of #{dest.to_s} -> #{backup_file}."
|
logger.info "Create backup file of #{dest.to_s} -> #{backup_file}."
|
||||||
File.rename( dest.to_s, backup_file )
|
File.rename( dest.to_s, backup_file )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -165,7 +165,7 @@ class Package < ApplicationModel
|
||||||
if File.symlink?( dest.to_s )
|
if File.symlink?( dest.to_s )
|
||||||
File.delete( dest.to_s )
|
File.delete( dest.to_s )
|
||||||
end
|
end
|
||||||
puts "Link file: #{entry.to_s} -> #{dest.to_s}"
|
logger.info "Link file: #{entry.to_s} -> #{dest.to_s}"
|
||||||
File.symlink( entry.to_s, dest.to_s )
|
File.symlink( entry.to_s, dest.to_s )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -325,14 +325,14 @@ class Package < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._parse(xml)
|
def self._parse(xml)
|
||||||
# puts xml.inspect
|
logger.debug xml.inspect
|
||||||
begin
|
begin
|
||||||
package = REXML::Document.new( xml )
|
package = REXML::Document.new( xml )
|
||||||
rescue => e
|
rescue => e
|
||||||
puts 'ERROR: ' + e.inspect
|
puts 'ERROR: ' + e.inspect
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
# puts package.inspect
|
logger.debug package.inspect
|
||||||
return package
|
return package
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ class Package < ApplicationModel
|
||||||
# rename existing file
|
# rename existing file
|
||||||
if File.exist?( location )
|
if File.exist?( location )
|
||||||
backup_location = location + '.save'
|
backup_location = location + '.save'
|
||||||
puts "NOTICE: backup old file '#{location}' to #{backup_location}"
|
logger.info "NOTICE: backup old file '#{location}' to #{backup_location}"
|
||||||
File.rename( location, backup_location )
|
File.rename( location, backup_location )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ class Package < ApplicationModel
|
||||||
|
|
||||||
# install file
|
# install file
|
||||||
begin
|
begin
|
||||||
puts "NOTICE: install '#{location}' (#{permission})"
|
logger.info "NOTICE: install '#{location}' (#{permission})"
|
||||||
file = File.new( location, 'wb' )
|
file = File.new( location, 'wb' )
|
||||||
file.write( data )
|
file.write( data )
|
||||||
file.close
|
file.close
|
||||||
|
@ -418,7 +418,7 @@ class Package < ApplicationModel
|
||||||
location = @@root + '/' + file
|
location = @@root + '/' + file
|
||||||
|
|
||||||
# install file
|
# install file
|
||||||
puts "NOTICE: uninstall '#{location}'"
|
logger.info "NOTICE: uninstall '#{location}'"
|
||||||
if File.exist?( location )
|
if File.exist?( location )
|
||||||
File.delete( location )
|
File.delete( location )
|
||||||
end
|
end
|
||||||
|
@ -426,7 +426,7 @@ class Package < ApplicationModel
|
||||||
# rename existing file
|
# rename existing file
|
||||||
backup_location = location + '.save'
|
backup_location = location + '.save'
|
||||||
if File.exist?( backup_location )
|
if File.exist?( backup_location )
|
||||||
puts "NOTICE: restore old file '#{backup_location}' to #{location}"
|
logger.info "NOTICE: restore old file '#{backup_location}' to #{location}"
|
||||||
File.rename( backup_location, location )
|
File.rename( backup_location, location )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ class Package < ApplicationModel
|
||||||
if direction == 'reverse'
|
if direction == 'reverse'
|
||||||
done = Package::Migration.where( :name => package.underscore, :version => version ).first
|
done = Package::Migration.where( :name => package.underscore, :version => version ).first
|
||||||
next if !done
|
next if !done
|
||||||
puts "NOTICE: down package migration '#{migration}'"
|
logger.info "NOTICE: down package migration '#{migration}'"
|
||||||
load "#{location}/#{migration}"
|
load "#{location}/#{migration}"
|
||||||
classname = name.camelcase
|
classname = name.camelcase
|
||||||
Kernel.const_get(classname).down
|
Kernel.const_get(classname).down
|
||||||
|
@ -487,7 +487,7 @@ class Package < ApplicationModel
|
||||||
else
|
else
|
||||||
done = Package::Migration.where( :name => package.underscore, :version => version ).first
|
done = Package::Migration.where( :name => package.underscore, :version => version ).first
|
||||||
next if done
|
next if done
|
||||||
puts "NOTICE: up package migration '#{migration}'"
|
logger.info "NOTICE: up package migration '#{migration}'"
|
||||||
load "#{location}/#{migration}"
|
load "#{location}/#{migration}"
|
||||||
classname = name.camelcase
|
classname = name.camelcase
|
||||||
Kernel.const_get(classname).up
|
Kernel.const_get(classname).up
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Scheduler < ApplicationModel
|
||||||
|
|
||||||
jobs_started = {}
|
jobs_started = {}
|
||||||
while true
|
while true
|
||||||
puts "Scheduler running (runner #{runner} of #{runner_count})..."
|
logger.info "Scheduler running (runner #{runner} of #{runner_count})..."
|
||||||
|
|
||||||
# reconnect in case db connection is lost
|
# reconnect in case db connection is lost
|
||||||
begin
|
begin
|
||||||
|
@ -29,7 +29,7 @@ class Scheduler < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start_job( job, runner, runner_count )
|
def self.start_job( job, runner, runner_count )
|
||||||
puts "started job thread for '#{job.name}' (#{job.method})..."
|
logger.info "started job thread for '#{job.name}' (#{job.method})..."
|
||||||
sleep 4
|
sleep 4
|
||||||
|
|
||||||
Thread.new {
|
Thread.new {
|
||||||
|
@ -56,7 +56,7 @@ class Scheduler < ApplicationModel
|
||||||
# raise "Exception from thread"
|
# raise "Exception from thread"
|
||||||
job.pid = ''
|
job.pid = ''
|
||||||
job.save
|
job.save
|
||||||
puts " ...stopped thread for '#{job.method}'"
|
logger.info " ...stopped thread for '#{job.method}'"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class Scheduler < ApplicationModel
|
||||||
job.last_run = Time.now
|
job.last_run = Time.now
|
||||||
job.pid = Thread.current.object_id
|
job.pid = Thread.current.object_id
|
||||||
job.save
|
job.save
|
||||||
puts "execute #{job.method} (runner #{runner} of #{runner_count}, try_count #{try_count})..."
|
logger.info "execute #{job.method} (runner #{runner} of #{runner_count}, try_count #{try_count})..."
|
||||||
eval job.method()
|
eval job.method()
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "execute #{job.method} (runner #{runner} of #{runner_count}, try_count #{try_count}) exited with error #{ e.inspect }"
|
puts "execute #{job.method} (runner #{runner} of #{runner_count}, try_count #{try_count}) exited with error #{ e.inspect }"
|
||||||
|
@ -84,7 +84,7 @@ class Scheduler < ApplicationModel
|
||||||
# reset error counter if to old
|
# reset error counter if to old
|
||||||
if try_run_time + ( 60 * 5 ) < Time.now
|
if try_run_time + ( 60 * 5 ) < Time.now
|
||||||
try_count = 0
|
try_count = 0
|
||||||
end
|
end
|
||||||
try_run_time = Time.now
|
try_run_time = Time.now
|
||||||
|
|
||||||
# restart job again
|
# restart job again
|
||||||
|
@ -98,7 +98,7 @@ class Scheduler < ApplicationModel
|
||||||
|
|
||||||
def self.worker
|
def self.worker
|
||||||
wait = 10
|
wait = 10
|
||||||
puts "*** Starting worker #{Delayed::Job.to_s}"
|
logger.info "*** Starting worker #{Delayed::Job.to_s}"
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
result = nil
|
result = nil
|
||||||
|
@ -113,7 +113,7 @@ class Scheduler < ApplicationModel
|
||||||
|
|
||||||
if count.zero?
|
if count.zero?
|
||||||
sleep(wait)
|
sleep(wait)
|
||||||
puts "*** worker loop"
|
logger.info "*** worker loop"
|
||||||
else
|
else
|
||||||
printf "*** #{count} jobs processed at %.4f j/s, %d failed ...\n" % [count / realtime, result.last]
|
printf "*** #{count} jobs processed at %.4f j/s, %d failed ...\n" % [count / realtime, result.last]
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,6 +42,7 @@ class Setting < ApplicationModel
|
||||||
end
|
end
|
||||||
setting.state = { :value => value }
|
setting.state = { :value => value }
|
||||||
setting.save
|
setting.save
|
||||||
|
logger.info "Setting.set() name:#{name}, value:#{value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get(name)
|
def self.get(name)
|
||||||
|
|
|
@ -403,7 +403,7 @@ returns
|
||||||
|
|
||||||
# find file
|
# find file
|
||||||
list = Store.list( :object => 'User::Image', :o_id => self.id )
|
list = Store.list( :object => 'User::Image', :o_id => self.id )
|
||||||
puts list.inspect
|
logger.debug list.inspect
|
||||||
if list && list[0]
|
if list && list[0]
|
||||||
file = Store.find( list[0] )
|
file = Store.find( list[0] )
|
||||||
result = {
|
result = {
|
||||||
|
@ -492,7 +492,7 @@ returns
|
||||||
if self.email
|
if self.email
|
||||||
hash = Digest::MD5.hexdigest(self.email)
|
hash = Digest::MD5.hexdigest(self.email)
|
||||||
self.image_source = "http://www.gravatar.com/avatar/#{hash}?s=48&d=404"
|
self.image_source = "http://www.gravatar.com/avatar/#{hash}?s=48&d=404"
|
||||||
#puts "#{self.email}: http://www.gravatar.com/avatar/#{hash}?s=48&d=404"
|
logger.debug "#{self.email}: #{self.image_source}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,14 +59,8 @@ module NotificationFactory
|
||||||
|
|
||||||
def self.send(data)
|
def self.send(data)
|
||||||
sender = Setting.get('notification_sender')
|
sender = Setting.get('notification_sender')
|
||||||
<<<<<<< HEAD
|
Rails.logger.info "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]} (from #{sender})"
|
||||||
Rails.logger.info "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]}"
|
|
||||||
Channel::EmailSend.new.send(
|
Channel::EmailSend.new.send(
|
||||||
=======
|
|
||||||
imap = Channel::IMAP.new
|
|
||||||
Rails.logger.info "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]}"
|
|
||||||
message = imap.send(
|
|
||||||
>>>>>>> 5e22499e44225c831661087b68de154deafef5c6
|
|
||||||
{
|
{
|
||||||
# :in_reply_to => self.in_reply_to,
|
# :in_reply_to => self.in_reply_to,
|
||||||
:from => sender,
|
:from => sender,
|
||||||
|
|
Loading…
Reference in a new issue