datalogger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in datalogger.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push "lib"
7
+ t.test_files = FileList["spec/*_spec.rb"]
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
data/Readme.md ADDED
@@ -0,0 +1,34 @@
1
+ # DataLogger (alpha)
2
+ A simple structured data logger. Pass it a hash, and it takes care of storing it to the data sink of your choice (currently stdout, though plugins are on the way).
3
+
4
+ ## Usage
5
+ ```ruby
6
+ require 'datalogger'
7
+
8
+ logger = DataLogger::Logger.new('myapp')
9
+ logger.log a: 1, b: 2, c: 3
10
+ ```
11
+
12
+ This will generate a log message to stdout that looks like so:
13
+
14
+ ```
15
+ myapp a=1 b=2 c=3
16
+ ```
17
+
18
+ Or, perhaps you'd like to log how long it takes to perform a given action:
19
+
20
+ ```ruby
21
+ require 'datalogger'
22
+
23
+ logger = DataLogger::Logger.new('myapp')
24
+ logger.log(event: 'create_user') do
25
+ # code to create a user
26
+ end
27
+ ```
28
+
29
+ This will generate a message that looks something like so:
30
+
31
+ ```
32
+ myapp action=create_user at=start
33
+ myapp action=create_user at=finish elapsed=0.003116
34
+ ```
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/datalogger/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michael Gorsuch"]
6
+ gem.email = ["michael.gorsuch@gmail.com"]
7
+ gem.description = %q{Easy to use structured data logger}
8
+ gem.summary = %q{Structurd data logger}
9
+ gem.homepage = "https://github.com/gorsuch/datalogger"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "datalogger"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DataLogger::VERSION
17
+ end
@@ -0,0 +1,32 @@
1
+ module DataLogger
2
+ class Logger
3
+ attr_accessor :component, :sinks
4
+
5
+ def initialize(component='app')
6
+ self.component = component
7
+ self.sinks = []
8
+ self.sinks << STDOUTSink.new
9
+ end
10
+
11
+ def log_to_sinks(data)
12
+ self.sinks.each do |sink|
13
+ sink.log(self.component, data)
14
+ end
15
+ end
16
+
17
+ def log(data, &blk)
18
+ if data.kind_of?(String)
19
+ data = { message: data }
20
+ end
21
+
22
+ if blk
23
+ start = Time.now
24
+ log_to_sinks(data.merge at: 'start')
25
+ yield
26
+ log_to_sinks(data.merge at: 'finish', elapsed: (Time.now - start))
27
+ else
28
+ log_to_sinks(data)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module DataLogger
2
+ class STDOUTSink
3
+ def initialize(sync=true)
4
+ STDOUT.sync = sync
5
+ end
6
+
7
+ def stringify_data(data)
8
+ data.inject("") { |s, (k,v)| s + "#{k}=#{v} " }.strip
9
+ end
10
+
11
+ def log(component, data)
12
+ puts "#{component} #{stringify_data(data)}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module DataLogger
2
+ VERSION = "0.0.1"
3
+ end
data/lib/datalogger.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "datalogger/version"
2
+ require "datalogger/logger"
3
+ require "datalogger/stdout_sink"
4
+
5
+ module DataLogger
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+
4
+ require 'datalogger'
5
+
6
+ describe DataLogger::Logger do
7
+ it "must have some tests ;-)"
8
+ end
File without changes
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datalogger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Gorsuch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-21 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Easy to use structured data logger
15
+ email:
16
+ - michael.gorsuch@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - Readme.md
25
+ - datalogger.gemspec
26
+ - lib/datalogger.rb
27
+ - lib/datalogger/logger.rb
28
+ - lib/datalogger/stdout_sink.rb
29
+ - lib/datalogger/version.rb
30
+ - spec/logger_spec.rb
31
+ - spec/stdout_sink_spec.rb
32
+ homepage: https://github.com/gorsuch/datalogger
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.10
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Structurd data logger
56
+ test_files:
57
+ - spec/logger_spec.rb
58
+ - spec/stdout_sink_spec.rb