logutils-activerecord 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 637f7d2a4d2688dd640b9b93a4be76e1c89cf078
4
- data.tar.gz: 01a2e677deb140556a402337ca06913cb19d941a
3
+ metadata.gz: 4eaba1108c6e07023fbb10cd0d8b12a489812920
4
+ data.tar.gz: dc5038396877005a0d9e48d275f3fe45ab50292b
5
5
  SHA512:
6
- metadata.gz: fb563c7c27808faf717c7ca96d4f9979339840c22600d24f9fb0147ead123a70de4b049433719c3aff466c3afc3257c5a819e7dbb23b1b6a981e7565e13c5f7b
7
- data.tar.gz: 600eb38f7a649ad2e147148921ecf89e0e3cc04bbd0c5b12b2de5b3da520981f946429d5d2c52b18eeb9470fecd9f07971a83c489a11c32f5b283edfd35761e1
6
+ metadata.gz: 9b2739e3295457a0e4071efd696008ef9fedfe148beb4fdedbb40cf799714d3286d1378cf0938f53165c0ba7e5d98fc6d9c0710875c0b8c8cb58257d1258d084
7
+ data.tar.gz: f4ae69a8b77dbb27d7a5431f33b519506edfe5bfe9ed939c0b4a25879e9271e9113faf27c3ae1b1f6ab814ec073fb0e46311937fcd7e80f8e3a6809137d532d3
data/Manifest.txt CHANGED
@@ -3,4 +3,12 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/logutils/activerecord.rb
6
+ lib/logutils/activerecord/deleter.rb
7
+ lib/logutils/activerecord/models.rb
8
+ lib/logutils/activerecord/schema.rb
6
9
  lib/logutils/activerecord/version.rb
10
+ lib/logutils/server.rb
11
+ lib/logutils/server/public/style.css
12
+ lib/logutils/server/views/_version.erb
13
+ lib/logutils/server/views/index.erb
14
+ lib/logutils/server/views/layout.erb
@@ -0,0 +1,15 @@
1
+
2
+ module LogDb
3
+
4
+ class Deleter
5
+ include Models
6
+
7
+ def run
8
+ # for now delete all tables
9
+
10
+ Log.delete_all
11
+ end
12
+
13
+ end # class Deleter
14
+
15
+ end # module LogDb
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ module LogDb
4
+ module Model
5
+
6
+ class Log < ActiveRecord::Base
7
+
8
+ end # class Log
9
+
10
+ end # module Model
11
+
12
+ ##### add convenience module alias in plural e.g. lets you use include LogDb::Models
13
+ Models = Model
14
+
15
+ end # module LogDb
16
+
@@ -0,0 +1,44 @@
1
+
2
+ module LogDb
3
+
4
+ class CreateDb ## fix/todo: change to ActiveRecord::Migration why? why not?
5
+
6
+ def self.up
7
+
8
+ ActiveRecord::Schema.define do
9
+
10
+ create_table :logs do |t|
11
+ t.string :msg, :null => false
12
+ t.string :level, :null => false # e.g. fatal, error, warn, info, debug
13
+ t.string :app
14
+ t.string :tag # e.g. class name w/ namespace e.g. SportDB.Reader etc. # NB: change to name?
15
+ t.integer :pid
16
+ t.integer :tid
17
+ t.string :ts # timestamp - change to datetime?
18
+ # add filename, line, method ??
19
+ t.timestamps
20
+ end
21
+
22
+ #####################################
23
+ # todo: add more fields ?? e.g.
24
+ #
25
+ # %m : The message to be logged
26
+ # %d : The ISO8601 Timestamp
27
+ # %L : The log level, e.g INFO, WARN
28
+ # %l : The log level (short), e.g. I, W
29
+ # %p : The PID of the process from where the log event occured
30
+ # %t : The Thread ID from where the log event occured
31
+ # %h : The hostname of the machine from where the log event occured
32
+ # %f : The filename from where the log event occured
33
+ # %n : The line number of the file from where the log event occured
34
+ # %F : The filename with path from where the log event occured
35
+ # %M : The method where the log event occured
36
+
37
+
38
+ end # block Schema.define
39
+
40
+ end # method up
41
+
42
+ end # class CreateDb
43
+
44
+ end # module LogDb
@@ -3,8 +3,8 @@
3
3
  module LogDb
4
4
 
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 0
7
- PATCH = 1
6
+ MINOR = 1
7
+ PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -1,4 +1,61 @@
1
1
  # encoding: utf-8
2
2
 
3
+ ##
4
+ # NOTE: logutils addon (logutils assumed/required) will NOT work stand-alone
3
5
 
6
+ # rubygems / 3rd party libs
4
7
 
8
+ require 'active_record' ## todo: add sqlite3? etc.
9
+
10
+
11
+ # our own code
12
+
13
+ require 'logutils/activerecord/version' # NOTE: let version always go first
14
+ require 'logutils/activerecord/models'
15
+ require 'logutils/activerecord/schema'
16
+ require 'logutils/activerecord/deleter'
17
+
18
+
19
+
20
+
21
+ module LogDb
22
+
23
+ class DbHandler
24
+ include Models
25
+
26
+ def write( ev )
27
+ if( ev.fatal? || ev.error? || ev.warn? || ev.unknown? )
28
+ ## create log entry in db table (logs)
29
+ Log.create!( level: ev.level, msg: ev.msg, pid: ev.pid, tid: ev.tid, ts: ev.ts )
30
+ end
31
+ end # method write
32
+ end # class DbHandler
33
+
34
+ def self.create
35
+ CreateDb.up
36
+ end
37
+
38
+ # delete ALL records (use with care!)
39
+ def self.delete!
40
+ puts '*** deleting log table records/data...'
41
+ Deleter.new.run
42
+ end # method delete!
43
+
44
+
45
+ def self.stats
46
+ # to be done
47
+ end
48
+
49
+
50
+ STDDBHANDLER = DbHandler.new # default/standard db handler
51
+
52
+ def self.setup # check: use different name? e.g. configure or connect ?? why or why not?
53
+ # turn on logging to db - assumes active connection
54
+ STDLOGGER.handlers << STDDBHANDLER
55
+ end
56
+
57
+ end # module LogDb
58
+
59
+
60
+ # say hello
61
+ puts LogDb.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
@@ -0,0 +1,49 @@
1
+
2
+
3
+ body { font-family: arial,verdana,helvetica; }
4
+
5
+ .log-id,
6
+ .log-pid,
7
+ .log-created-at { font-size: 60%; color: grey; }
8
+
9
+ .log-id { text-align: right; }
10
+
11
+ .log-level,
12
+ .log-msg { font-size: 80%; }
13
+
14
+ .log-created-at,
15
+ .log-pid,
16
+ .log-msg { white-space: nowrap; }
17
+
18
+ .log-level { font-weight: bold; }
19
+
20
+ .log-msg.warn { font-weight: bold; }
21
+
22
+
23
+ /****
24
+ * links
25
+ */
26
+
27
+ a {
28
+ color: black;
29
+ text-decoration: none; }
30
+ a:hover {
31
+ color: black;
32
+ background-color: aqua;
33
+ text-decoration: underline; }
34
+ a:visited {
35
+ color: black; }
36
+
37
+
38
+
39
+ /**********
40
+ * version / powered by
41
+ */
42
+
43
+ .version {
44
+ text-align: center;
45
+ margin-top: 10px;
46
+ color: grey; }
47
+ .version a, .version span {
48
+ font-size: 12px;
49
+ color: grey; }
@@ -0,0 +1,5 @@
1
+ <div class='version'>
2
+ <a href="https://github.com/rubylibs/logutils">log.db/<%= LogDb::VERSION %></a> -
3
+ <span>Ruby/<%= "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}/#{RUBY_PLATFORM})" %> on</span>
4
+ <span>Sinatra/<%= Sinatra::VERSION %> (<%= ENV['RACK_ENV'] %>)</span>
5
+ </div>
@@ -0,0 +1,26 @@
1
+
2
+ <h3><%= Log.count %> Logs</h3>
3
+
4
+ <!-- todo:
5
+ add filter for FATAL,ERROR,WARN,etc.
6
+ add log count per kind? (e.g. 20 errors, 5 warns, etc.)
7
+
8
+ css: use colors
9
+
10
+ - error/fatal - red?
11
+ - warn - // bold or organge?
12
+ - info - normal
13
+ - debug - light grey??
14
+ -->
15
+
16
+ <table>
17
+ <% Log.all.each do |log| %>
18
+ <tr>
19
+ <td class='log-id'><%= log.id %>.</td>
20
+ <td class='log-level <%= log.level %>'>[<%= log.level %>]</td>
21
+ <td class='log-msg <%= log.level %>'><%= log.msg %></td>
22
+ <td class='log-pid'><%= "#{log.pid}.#{log.tid}" %></td>
23
+ <td class='log-created-at' <%= log.level %>'><%= log.created_at %></td>
24
+ </tr>
25
+ <% end %>
26
+ </table>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='UTF-8'>
5
+ <title>Logs</title>
6
+ <link href="<%= url('/style.css') %>" rel='stylesheet'>
7
+ </head>
8
+ <body>
9
+
10
+ <%= yield %>
11
+
12
+ <%= erb :'_version' %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,58 @@
1
+ ######
2
+ # NB: use rackup to startup Sinatra service (see config.ru)
3
+ #
4
+ # e.g. config.ru:
5
+ # require './boot'
6
+ # run LogDb::Server
7
+
8
+
9
+ # 3rd party libs/gems - include/require in ./boot
10
+ ### require 'sinatra/base'
11
+
12
+
13
+ # NOTE: it's an addon for logutils
14
+ # assume logutils and logutils/activerecord already required
15
+ # require 'logutils'
16
+ # require 'logutils/db'
17
+
18
+
19
+ # our own code
20
+
21
+ module LogDb
22
+
23
+ class Server < Sinatra::Base
24
+
25
+ def self.banner
26
+ "logdb-service/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] on Sinatra/#{Sinatra::VERSION} (#{ENV['RACK_ENV']})"
27
+ end
28
+
29
+ PUBLIC_FOLDER = "#{LogDb.root}/lib/logutils/server/public"
30
+ VIEWS_FOLDER = "#{LogDb.root}/lib/logutils/server/views"
31
+
32
+ puts "[boot] logdb-service - setting public folder to: #{PUBLIC_FOLDER}"
33
+ puts "[boot] logdb-service - setting views folder to: #{VIEWS_FOLDER}"
34
+
35
+ set :public_folder, PUBLIC_FOLDER # set up the static dir (with images/js/css inside)
36
+ set :views, VIEWS_FOLDER # set up the views dir
37
+
38
+ set :static, true # set up static file routing
39
+
40
+ #####################
41
+ # Models
42
+
43
+ include Models
44
+
45
+ ##############################################
46
+ # Controllers / Routing / Request Handlers
47
+
48
+ get '/' do
49
+ erb :index
50
+ end
51
+
52
+ end # class Server
53
+ end # module LogDb
54
+
55
+
56
+ # say hello
57
+ puts LogDb::Server.banner
58
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logutils-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logutils
@@ -80,7 +80,15 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - lib/logutils/activerecord.rb
83
+ - lib/logutils/activerecord/deleter.rb
84
+ - lib/logutils/activerecord/models.rb
85
+ - lib/logutils/activerecord/schema.rb
83
86
  - lib/logutils/activerecord/version.rb
87
+ - lib/logutils/server.rb
88
+ - lib/logutils/server/public/style.css
89
+ - lib/logutils/server/views/_version.erb
90
+ - lib/logutils/server/views/index.erb
91
+ - lib/logutils/server/views/layout.erb
84
92
  homepage: https://github.com/rubylibs/logutils-activerecord
85
93
  licenses:
86
94
  - Public Domain