Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated logging in DM to be compatible with Merb's logger

* Logging methods no longer take a block, they only accept a single
  String argument
  • Loading branch information...
commit 1312cc5ee7eae83b7328a8165043389e665b2650 1 parent a51412a
Dan Kubb authored
View
18 lib/data_mapper/adapters/data_objects_adapter.rb
@@ -72,7 +72,7 @@ def find_by_sql(*args)
properties ||= self.properties
- DataMapper.logger.debug { "FIND_BY_SQL: #{sql} PARAMETERS: #{params.inspect}" }
+ DataMapper.logger.debug("FIND_BY_SQL: #{sql} PARAMETERS: #{params.inspect}")
repository.adapter.read_set_with_sql(repository, self, properties, sql, params, do_reload)
end
@@ -148,7 +148,7 @@ def create(repository, resource)
sql = send(create_with_returning? ? :create_statement_with_returning : :create_statement, resource.class, properties)
values = properties.map { |property| resource.instance_variable_get(property.instance_variable_name) }
- DataMapper.logger.debug { "CREATE: #{sql} PARAMETERS: #{values.inspect}" }
+ DataMapper.logger.debug("CREATE: #{sql} PARAMETERS: #{values.inspect}")
connection = create_connection
command = connection.create_command(sql)
@@ -175,7 +175,7 @@ def read(repository, resource, key)
set = LoadedSet.new(repository, resource, properties_with_indexes)
sql = read_statement(resource, key)
- DataMapper.logger.debug { "READ: #{sql}" }
+ DataMapper.logger.debug("READ: #{sql}")
connection = create_connection
command = connection.create_command(sql)
@@ -200,7 +200,7 @@ def update(repository, resource)
sql = update_statement(resource.class, properties)
values = properties.map { |property| resource.instance_variable_get(property.instance_variable_name) }
parameters = (values + resource.key)
- DataMapper.logger.debug { "UPDATE: #{sql} PARAMETERS: #{parameters.inspect}" }
+ DataMapper.logger.debug("UPDATE: #{sql} PARAMETERS: #{parameters.inspect}")
connection = create_connection
command = connection.create_command(sql)
@@ -244,7 +244,7 @@ def read_set_with_sql(repository, model, properties, sql, parameters, do_reload)
properties_with_indexes = Hash[*properties.zip((0...properties.length).to_a).flatten]
set = LoadedSet.new(repository, model, properties_with_indexes)
- DataMapper.logger.debug { "READ_SET: #{sql} PARAMETERS: #{parameters.inspect}" }
+ DataMapper.logger.debug("READ_SET: #{sql} PARAMETERS: #{parameters.inspect}")
connection = create_connection
begin
@@ -283,20 +283,20 @@ def delete_set(repository, query)
# Database-specific method
def execute(sql, *args)
- DataMapper.logger.debug { "EXECUTE: #{sql} PARAMETERS: #{args.inspect}" }
+ DataMapper.logger.debug("EXECUTE: #{sql} PARAMETERS: #{args.inspect}")
connection = create_connection
command = connection.create_command(sql)
return command.execute_non_query(*args)
rescue => e
- DataMapper.logger.error { e } if DataMapper.logger
+ DataMapper.logger.error(e) if DataMapper.logger
raise e
ensure
connection.close if connection
end
def query(sql, *args)
- DataMapper.logger.debug { "QUERY: #{sql} PARAMETERS: #{args.inspect}" }
+ DataMapper.logger.debug("QUERY: #{sql} PARAMETERS: #{args.inspect}")
connection = create_connection
command = connection.create_command(sql)
@@ -319,7 +319,7 @@ def query(sql, *args)
return results
rescue => e
- DataMapper.logger.error { e } if DataMapper.logger
+ DataMapper.logger.error(e) if DataMapper.logger
raise e
ensure
reader.close if reader
View
4 lib/data_mapper/adapters/sqlite3_adapter.rb
@@ -15,9 +15,7 @@ class Sqlite3Adapter < DataObjectsAdapter
)
def create_connection
- connnection = DataObjects::Sqlite3::Connection.new(@uri)
- # connnection.logger = DataMapper.logger
- return connnection
+ DataObjects::Sqlite3::Connection.new(@uri)
end
protected
View
24 lib/data_mapper/logger.rb
@@ -10,11 +10,11 @@
# DataMapper::Logger::{ Fatal, Error, Warn, Info, Debug }
#
# Logging via:
-# DataMapper.logger.fatal(message<String>,&block)
-# DataMapper.logger.error(message<String>,&block)
-# DataMapper.logger.warn(message<String>,&block)
-# DataMapper.logger.info(message<String>,&block)
-# DataMapper.logger.debug(message<String>,&block)
+# DataMapper.logger.fatal(message<String>)
+# DataMapper.logger.error(message<String>)
+# DataMapper.logger.warn(message<String>)
+# DataMapper.logger.info(message<String>)
+# DataMapper.logger.debug(message<String>)
#
# Flush the buffer to
# DataMapper.logger.flush
@@ -165,16 +165,10 @@ def close
# The logging level as an integer
# string<String>
# The string message to be logged
- # block<&block>
- # An optional block that will be evaluated and added to the logging message after the string message.
- def push(string = nil)
+ def push(string)
message = Time.now.httpdate
message << delimiter
- message << string if string
- if block_given?
- message << delimiter
- message << yield
- end
+ message << string
message << "\n" unless message[-1] == ?\n
@buffer << message
flush # Force a flush for now until we figure out where we want to use the buffering.
@@ -186,8 +180,8 @@ def push(string = nil)
LEVELS.each_pair do |name, number|
class_eval <<-LEVELMETHODS, __FILE__, __LINE__
# DOC
- def #{name}(message = nil, &block)
- self.<<(message, &block) if #{name}?
+ def #{name}(message)
+ self.<<(message) if #{name}?
end
# DOC
Please sign in to comment.
Something went wrong with that request. Please try again.