quickbase_logger 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +12 -1
- data/lib/quickbase_logger/logger.rb +28 -8
- data/lib/quickbase_logger/version.rb +1 -1
- data/spec/quickbase_logger_spec.rb +22 -5
- metadata +2 -4
- data/spec/log/quickbase_logger_default.log +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: efa3a3cc1ebde57d54f764d842ce953b61c3029b
         | 
| 4 | 
            +
              data.tar.gz: fd3a0fea2568617f71c3e29cf62c431ea8ccbc0c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6a336837b323bb72c668fd99d5e8e31f809dccfee29763468c9017f3a393c23b8808b7330f1dbbdd5775ad881a4c18fab5b90481446297e282051a36ab392ec3
         | 
| 7 | 
            +
              data.tar.gz: 70a958cd4efabf05b31eaedf1cd7cd93e13399a4a80f2ab77baf2c310df14f050208134b94a9df48f05e2b6b32ce7701a8fcff3c414159e161677777ea256f3a
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -70,12 +70,23 @@ QuickbaseLogger is built on top of the wonderful [QuickbaseRecord](https://githu | |
| 70 70 | 
             
            ### Methods and API
         | 
| 71 71 | 
             
            Using QuickbaseLogger is as simple as instantiating an instance of QuickbaseLogger::Logger and wrapping any code you want logged to your Script Logs QuickBase table in the #log_to_quickbase method on that instance.
         | 
| 72 72 |  | 
| 73 | 
            +
            ##### Text Logger File Name
         | 
| 73 74 | 
             
            QuickbaseLogger::Logger.new accepts a :related_script argument that is the [Record ID#] of the parent Script record, and an optional :file_name argument for the name of the text log file. If no :file_name argument is given it will default to "quickbase_logger_default"
         | 
| 74 75 |  | 
| 75 76 | 
             
            ```ruby
         | 
| 76 77 | 
             
              qb_logger = QuickbaseLogger::Logger.new(related_script: 123, file_name: 'my_awesome_log_file')
         | 
| 77 78 | 
             
            ```
         | 
| 78 79 |  | 
| 80 | 
            +
            ##### Purge Old Logs
         | 
| 81 | 
            +
            By default, the Script Log records in QuickBase that are related to the current QuickbaseLogger::Logger instance will be deleted after 180 days. To override this functionality you can add a :purge_frequency argument to the .new method. This should be an integer value representing the number of days after which to delete records (based on the [Date Created] field in QuickBase).
         | 
| 82 | 
            +
             | 
| 83 | 
            +
            ```ruby
         | 
| 84 | 
            +
              # "purge_frequency: 7" means that Script Log records created before 7 days ago will be deleted at the end of the #log_to_quickbase method execution
         | 
| 85 | 
            +
              qb_logger = QuickbaseLogger::Logger.new(related_script: 123, file_name: 'my_awesome_log_file', purge_frequency: 7)
         | 
| 86 | 
            +
            ```
         | 
| 87 | 
            +
             | 
| 88 | 
            +
             | 
| 89 | 
            +
            ##### #log_to_quickbase
         | 
| 79 90 | 
             
            The instance returned from QuickbaseLogger::Logger.new has a method named #log_to_quickbase that accepts a block of code you want to capture in you logs. While inside the scope of the #log_to_quickbase method, you have access to #info(message), #warn(message), and #error(message) methods on the logger instance that simply log the given message to the :log field on the Script Logs table in QuickBase as well as the text logger. Each of these methods will capture the time of the log automatically.
         | 
| 80 91 |  | 
| 81 92 | 
             
            ```ruby
         | 
| @@ -109,7 +120,7 @@ class SomeAwesomeScript | |
| 109 120 | 
             
            end
         | 
| 110 121 | 
             
            ```
         | 
| 111 122 |  | 
| 112 | 
            -
            Here's how the #log_to_quickbase method is structured (for your reference):
         | 
| 123 | 
            +
            Here's how the source code for the #log_to_quickbase method is structured (for your reference):
         | 
| 113 124 |  | 
| 114 125 | 
             
            ```ruby
         | 
| 115 126 | 
             
              def log_to_quickbase
         | 
| @@ -2,18 +2,21 @@ module QuickbaseLogger | |
| 2 2 | 
             
              class Logger
         | 
| 3 3 | 
             
                include QuickbaseRecord::Model
         | 
| 4 4 |  | 
| 5 | 
            -
                attr_accessor :text_logger
         | 
| 5 | 
            +
                attr_accessor :text_logger, :purge_frequency
         | 
| 6 6 |  | 
| 7 7 | 
             
                def initialize(options={})
         | 
| 8 8 | 
             
                  raise ArgumentError.new("QuickbaseLogger::Logger.new must receive a :related_script argument.") unless options[:related_script]
         | 
| 9 9 |  | 
| 10 10 | 
             
                  @log = []
         | 
| 11 11 | 
             
                  @start = "#{formatted_date} #{formatted_time}"
         | 
| 12 | 
            +
                  @purge_frequency = options.fetch(:purge_frequency, 180)
         | 
| 12 13 |  | 
| 13 14 | 
             
                  file_name = options.fetch(:file_name, 'quickbase_logger_default')
         | 
| 14 15 | 
             
                  @text_logger = ::Logger.new("#{formatted_logger_path}#{file_name}.log", "monthly") # standard ruby Logger instance
         | 
| 16 | 
            +
                  @text_logger.info("===== #{Date.today.strftime('%m/%d/%Y')} =====")
         | 
| 15 17 | 
             
                  @text_logger.info("START")
         | 
| 16 | 
            -
             | 
| 18 | 
            +
             | 
| 19 | 
            +
                  super(options)
         | 
| 17 20 | 
             
                end
         | 
| 18 21 |  | 
| 19 22 | 
             
                def log_to_quickbase
         | 
| @@ -28,6 +31,8 @@ module QuickbaseLogger | |
| 28 31 | 
             
                    log_failure_to_quickbase(err)
         | 
| 29 32 | 
             
                    raise err
         | 
| 30 33 | 
             
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  purge_logs
         | 
| 31 36 | 
             
                end
         | 
| 32 37 |  | 
| 33 38 | 
             
                def info(message)
         | 
| @@ -42,17 +47,32 @@ module QuickbaseLogger | |
| 42 47 | 
             
                  log << "Error [#{formatted_time}]: #{message}"
         | 
| 43 48 | 
             
                end
         | 
| 44 49 |  | 
| 50 | 
            +
                def purge_logs
         | 
| 51 | 
            +
                  purge_date = Date.today - purge_frequency.days
         | 
| 52 | 
            +
                  purge_date = purge_date.strftime("%m/%d/%Y")
         | 
| 53 | 
            +
                  related_script_fid = self.class.fields[:related_script].fid
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  begin
         | 
| 56 | 
            +
                    qb_client.purge_records(self.class.dbid, {query: "{#{related_script_fid}.EX.#{related_script}}AND{1.OBF.#{purge_date}}"})
         | 
| 57 | 
            +
                  rescue StandardError => e
         | 
| 58 | 
            +
                    text_logger.error("--- FAILED TO PURGE OLD RECORDS ---")
         | 
| 59 | 
            +
                    text_logger.error(err)
         | 
| 60 | 
            +
                    text_logger.error("BACKTRACE:\n\t#{err.backtrace.slice(0, 10).join("\n\t")}")
         | 
| 61 | 
            +
                    raise err
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 45 65 | 
             
                private
         | 
| 46 66 |  | 
| 47 67 | 
             
                def log_success_to_text_file
         | 
| 48 | 
            -
                  joined_logs = self.log.join("\n")
         | 
| 49 | 
            -
                  text_logger.info("LOGS:\n#{joined_logs}")
         | 
| 68 | 
            +
                  joined_logs = self.log.join("\n\t")
         | 
| 69 | 
            +
                  text_logger.info("LOGS:\n\t#{joined_logs}")
         | 
| 50 70 | 
             
                  text_logger.info("END")
         | 
| 51 71 | 
             
                end
         | 
| 52 72 |  | 
| 53 73 | 
             
                def log_failure_to_text_file(err)
         | 
| 54 | 
            -
                  joined_logs = self.log.join("\n")
         | 
| 55 | 
            -
                  text_logger.info("LOGS:\n#{joined_logs}")
         | 
| 74 | 
            +
                  joined_logs = self.log.join("\n\t")
         | 
| 75 | 
            +
                  text_logger.info("LOGS:\n\t#{joined_logs}")
         | 
| 56 76 |  | 
| 57 77 | 
             
                  text_logger.error("ERROR: #{err}")
         | 
| 58 78 | 
             
                  text_logger.error("BACKTRACE:\n\t#{err.backtrace.slice(0, 10).join("\n\t")}")
         | 
| @@ -67,7 +87,7 @@ module QuickbaseLogger | |
| 67 87 | 
             
                  begin
         | 
| 68 88 | 
             
                    save
         | 
| 69 89 | 
             
                  rescue StandardError => err
         | 
| 70 | 
            -
                    text_logger.error(" | 
| 90 | 
            +
                    text_logger.error("--- COULD NOT WRITE SUCCESS TO QUICKBASE ---")
         | 
| 71 91 | 
             
                    text_logger.error(err)
         | 
| 72 92 | 
             
                    text_logger.error("BACKTRACE:\n\t#{err.backtrace.slice(0, 10).join("\n\t")}")
         | 
| 73 93 | 
             
                    raise err
         | 
| @@ -85,7 +105,7 @@ module QuickbaseLogger | |
| 85 105 | 
             
                  begin
         | 
| 86 106 | 
             
                    save
         | 
| 87 107 | 
             
                  rescue StandardError => err
         | 
| 88 | 
            -
                    text_logger.error(" | 
| 108 | 
            +
                    text_logger.error("--- COULD NOT WRITE FAILURE TO QUICKBASE ---")
         | 
| 89 109 | 
             
                    text_logger.error(err)
         | 
| 90 110 | 
             
                    text_logger.error("BACKTRACE:\n\t#{err.backtrace.slice(0, 10).join("\n\t")}")
         | 
| 91 111 | 
             
                    raise err
         | 
| @@ -19,9 +19,16 @@ end | |
| 19 19 |  | 
| 20 20 | 
             
            RSpec.describe QuickbaseLogger::Logger do
         | 
| 21 21 | 
             
              describe '.initialize' do
         | 
| 22 | 
            +
                before do
         | 
| 23 | 
            +
                  @logger = QuickbaseLogger::Logger.new(related_script: 123)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 22 26 | 
             
                it "defines a parent script that all log records will be related to" do
         | 
| 23 | 
            -
                  logger | 
| 24 | 
            -
             | 
| 27 | 
            +
                  expect(@logger.related_script).to eq(123)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                it "sets a default purge_frequency of 180 days" do
         | 
| 31 | 
            +
                  expect(@logger.purge_frequency).to eq(180)
         | 
| 25 32 | 
             
                end
         | 
| 26 33 | 
             
              end
         | 
| 27 34 |  | 
| @@ -32,9 +39,19 @@ RSpec.describe QuickbaseLogger::Logger do | |
| 32 39 | 
             
                  expect(qb_logger).to receive(:save)
         | 
| 33 40 |  | 
| 34 41 | 
             
                  qb_logger.log_to_quickbase do
         | 
| 35 | 
            -
                    qb_logger.info(' | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 42 | 
            +
                    qb_logger.info('testing that #save is called')
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                it "deletes records older than the purge frequency" do
         | 
| 47 | 
            +
                  qb_logger = QuickbaseLogger::Logger.new(related_script: 1, purge_frequency: 0)
         | 
| 48 | 
            +
                  purge_date = Date.today.strftime("%m/%d/%Y")
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  # the query "{10.EX.1}AND{1.OBF.#{purge_date}}" uses the FID for related_script and date_created, respectively
         | 
| 51 | 
            +
                  expect_any_instance_of(AdvantageQuickbase::API).to receive(:purge_records).with('bkd86zn87', {query: "{10.EX.1}AND{1.OBF.#{purge_date}}"})
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  qb_logger.log_to_quickbase do
         | 
| 54 | 
            +
                    qb_logger.info('testing that #purge_records is called')
         | 
| 38 55 | 
             
                  end
         | 
| 39 56 | 
             
                end
         | 
| 40 57 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: quickbase_logger
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Cullen Jett
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-12-15 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -87,7 +87,6 @@ files: | |
| 87 87 | 
             
            - lib/quickbase_logger/logger.rb
         | 
| 88 88 | 
             
            - lib/quickbase_logger/version.rb
         | 
| 89 89 | 
             
            - quickbase_logger.gemspec
         | 
| 90 | 
            -
            - spec/log/quickbase_logger_default.log
         | 
| 91 90 | 
             
            - spec/quickbase_logger_spec.rb
         | 
| 92 91 | 
             
            - spec/spec_helper.rb
         | 
| 93 92 | 
             
            homepage: https://github.com/cullenjett/quickbase_logger
         | 
| @@ -115,6 +114,5 @@ signing_key: | |
| 115 114 | 
             
            specification_version: 4
         | 
| 116 115 | 
             
            summary: Use Quickbase tables as a logging platform
         | 
| 117 116 | 
             
            test_files:
         | 
| 118 | 
            -
            - spec/log/quickbase_logger_default.log
         | 
| 119 117 | 
             
            - spec/quickbase_logger_spec.rb
         | 
| 120 118 | 
             
            - spec/spec_helper.rb
         | 
| 
            File without changes
         |