Paul: Check-in [ea94e475cb]

Online event coordination and survey application

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a new logger mechanism
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:ea94e475cb9f3a3403bbc178595711ca5a40d8d55a66fd8796212c4b4683af37
User & Date: milouse 2018-11-01 17:19:02
Context
2018-11-15
22:22
Add a shared config object check-in: 76472a19bf user: milouse tags: trunk
2018-11-01
17:19
Add a new logger mechanism check-in: ea94e475cb user: milouse tags: trunk
2018-10-28
18:42
Begin to support answer check-in: 5a83c6619c user: milouse tags: trunk
Changes

Changes to .rubocop.yml.

6
7
8
9
10
11
12



13
14
15
16
17
18
19
  Enabled: false

Metrics/AbcSize:
  Enabled: false

Metrics/BlockLength:
  Max: 30




Metrics/MethodLength:
  Max: 15

Style/ConditionalAssignment:
  EnforcedStyle: assign_inside_condition








>
>
>







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  Enabled: false

Metrics/AbcSize:
  Enabled: false

Metrics/BlockLength:
  Max: 30

Metrics/LineLength:
  Max: 72

Metrics/MethodLength:
  Max: 15

Style/ConditionalAssignment:
  EnforcedStyle: assign_inside_condition

Changes to lib/notification.rb.

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
      body content
    end
    m.from = @from
    m.header['User-agent'] = 'Paul Survey System'
    m.header['X-Mailer'] = 'Ruby Mail'
    begin
      m.deliver!
    rescue Errno::ECONNREFUSED => e
      $stderr.puts e.class.name
    end
  end

  private

  def load_settings
    conf = File.join 'config', 'config.yml'







|
|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
      body content
    end
    m.from = @from
    m.header['User-agent'] = 'Paul Survey System'
    m.header['X-Mailer'] = 'Ruby Mail'
    begin
      m.deliver!
    rescue Errno::ECONNREFUSED
      ::PaulLogger.log.error 'SMTP server refuses to answer'
    end
  end

  private

  def load_settings
    conf = File.join 'config', 'config.yml'

Added lib/paul_logger.rb.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

require 'logger'
require 'english'

# Custom logger to be used everywhere in the app
class PaulLogger
  class << self
    def log
      return @logger unless @logger.nil?
      @logger = Logger.new 'tmp/logs/application.log'
      @logger.datetime_format = '%Y-%m-%d %H:%M:%S'
      @logger.progname = 'Paul'
      @logger.formatter = proc do |severity, datetime, _, msg|
        "[#{datetime} #{$PID}] #{severity} #{msg}\n"
      end
      @logger
    end
  end
end

Changes to paul.rb.

1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

require 'logger'
require 'sinatra/base'
require 'slim/smart'

require './lib/survey'
require './lib/notification'

# To be included:
# Digest https://ruby-doc.org/stdlib-2.4.4/libdoc/digest/rdoc/Digest.html
# SecureRandom https://ruby-doc.org/stdlib-2.4.4/libdoc/securerandom/rdoc/SecureRandom.html

# Main Sinatra application
class Paul < Sinatra::Base
  configure :production, :development do
    enable :logging
    app_logger = Logger.new("#{root}/tmp/logs/application.log")
    app_logger.datetime_format = '%Y-%m-%d %H:%M:%S'
    set :logger, app_logger
    disable :method_override, :sessions
  end

  configure :production do
    set :main_script_path, '/paul.js'
  end



<


>











<
<
|







1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
# frozen_string_literal: true


require 'sinatra/base'
require 'slim/smart'
require './lib/paul_logger'
require './lib/survey'
require './lib/notification'

# To be included:
# Digest https://ruby-doc.org/stdlib-2.4.4/libdoc/digest/rdoc/Digest.html
# SecureRandom https://ruby-doc.org/stdlib-2.4.4/libdoc/securerandom/rdoc/SecureRandom.html

# Main Sinatra application
class Paul < Sinatra::Base
  configure :production, :development do
    enable :logging


    set :logger, ::PaulLogger.log
    disable :method_override, :sessions
  end

  configure :production do
    set :main_script_path, '/paul.js'
  end