Class: OnlyofficeMysqlHelper::MySQLLogger
- Inherits:
-
Object
- Object
- OnlyofficeMysqlHelper::MySQLLogger
- Defined in:
- lib/onlyoffice_mysql_helper/mysql_logger.rb
Overview
Log action in mysql
Instance Attribute Summary collapse
-
#hash ⇒ Hash
Hash to add to DB.
-
#mysql ⇒ MySQLHelper
Instance of helper.
-
#table ⇒ String
Table name.
Instance Method Summary collapse
-
#create_log_table(table_name, column) ⇒ Void
Create table for logging purposes.
-
#initialize(mysql = MySQLHelper.new, table = nil, hash = {}) ⇒ MySQLLogger
constructor
A new instance of MySQLLogger.
-
#log_actions(action, hash) ⇒ nil
Log ant actions in DB.
Constructor Details
#initialize(mysql = MySQLHelper.new, table = nil, hash = {}) ⇒ MySQLLogger
Returns a new instance of MySQLLogger.
13 14 15 16 17 |
# 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 |
Instance Attribute Details
#hash ⇒ Hash
Returns hash to add to DB.
11 12 13 |
# File 'lib/onlyoffice_mysql_helper/mysql_logger.rb', line 11 def hash @hash end |
#mysql ⇒ MySQLHelper
Returns instance of helper.
7 8 9 |
# File 'lib/onlyoffice_mysql_helper/mysql_logger.rb', line 7 def mysql @mysql end |
#table ⇒ String
Returns table name.
9 10 11 |
# File 'lib/onlyoffice_mysql_helper/mysql_logger.rb', line 9 def table @table end |
Instance Method Details
#create_log_table(table_name, column) ⇒ Void
Create table for logging purposes
22 23 24 25 26 27 28 |
# 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) ⇒ nil
Log ant actions in DB
34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |