class OnlyofficeMysqlHelper::MySQLLogger
Log action in mysql
Attributes
hash[RW]
@return [Hash] hash to add to DB
mysql[RW]
@return [MySQLHelper] instance of helper
table[RW]
@return [String] table name
Public Class Methods
new(mysql = MySQLHelper.new, table = nil, hash = {})
click to toggle source
# File lib/onlyoffice_mysql_helper/mysql_logger.rb, line 13 def initialize(mysql = MySQLHelper.new, table = nil, hash = {}) @mysql = mysql @table = table @hash = hash end
Public Instance Methods
create_log_table(table_name, column)
click to toggle source
Create table for logging purposes @param table_name [String] name of table to create @return [Void]
# File lib/onlyoffice_mysql_helper/mysql_logger.rb, line 22 def create_log_table(table_name, column) table_command = 'id INT PRIMARY KEY AUTO_INCREMENT, '\ "#{column} VARCHAR(25) NOT NULL, "\ 'time VARCHAR(255) NOT NULL, '\ 'operation VARCHAR(255) NOT NULL' @mysql.create_table(table_name, table_command) end
log_actions(action, hash) { || ... }
click to toggle source
Log ant actions in DB @param [String] action name for log @param [Hash] hash with additional options @return [nil]
# File lib/onlyoffice_mysql_helper/mysql_logger.rb, line 34 def log_actions(action, hash) mysql_hash = hash.merge(@hash) mysql_hash[:time] = Time.now mysql_hash[:operation] = "Start: #{action}" @mysql.add_record(@table, mysql_hash) yield mysql_hash[:time] = Time.now mysql_hash[:operation] = "Finished: #{action}" @mysql.add_record(@table, mysql_hash) end