logging-flowdock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 474bf9b3b497b8d828768baf72fe6d8610978ceb
4
+ data.tar.gz: ead54931ad1e9cf297a1cd0b87bdd17b381f9b84
5
+ SHA512:
6
+ metadata.gz: 1d606e2115ba6df580e43326091596bfec30c259a21dee3ec86a29bdf070d10980b486f4e8e53d6df924f940a337a5280b8a14d0c8c1d597576be390fc95f0fd
7
+ data.tar.gz: c542d32da8296cb2e1fb962790e4c1aa66dcd37f9c10758e71a31321550756265930a1c4cc80503a73cf3a39c5ef6b7697d9e295c798aac831e976265ee7b86c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ # Most of these are disabling existing cops, primarily
2
+ # due to a smattering of different styles and loose
3
+ # guidlines for contributions.
4
+ #
5
+ # Any of these may be changed.
6
+
7
+ # I personally believe double-quotes is more-idiomatic Ruby
8
+ # StringLiterals:
9
+ # EnforcedStyle: double_quotes
10
+ # Enabled: false
11
+
12
+ Style/PercentLiteralDelimiters:
13
+ PreferredDelimiters:
14
+ '%': '{}'
15
+ '%i': '{}'
16
+ '%q': '{}'
17
+ '%Q': '{}'
18
+ '%r': '{}'
19
+ '%s': '{}'
20
+ '%w': '{}'
21
+ '%W': '{}'
22
+ '%x': '{}'
23
+
24
+ SpaceInsideBlockBraces:
25
+ SpaceBeforeBlockParameters: false
26
+
27
+ LineLength:
28
+ Max: 120
29
+
30
+ # Style/ClassAndModuleChildren:
31
+ # EnforcedStyle: compact
32
+
33
+ Style/FileName:
34
+ Enabled: false
35
+
36
+ # TODO: Disable before release
37
+ # Documentation:
38
+ # Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at wildjim+dev@kiwinet.org. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logging-flowdock.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 mexisme
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Logging::Flowdock
2
+
3
+ This is an "Appender" for the [Logging](https://rubygems.org/gems/logging) gem, to allow you to forward Logs directly to an
4
+ [Flowdock](https://flowdock.com) Service.
5
+
6
+ TODO: Delete this and the text above, and describe your gem
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'logging'
14
+ gem 'logging-flowdock'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install logging-flowdock
24
+
25
+ ## Usage
26
+
27
+
28
+ The Logging gem uses [little-plugger](https://rubygems.org/gems/little-plugger) gem to manage
29
+ [extending Logger](https://github.com/TwP/logging#extending).
30
+ This means it will automatically load and initialise the `logging-flowdock` code as soon as it loads the Logging code.
31
+
32
+ To configure Logging to use Flowdock, you simply have to add the appender to your configuring of Logging.
33
+
34
+ e.g. The following will send the "Wootles" log-output to STDERR and the Flowdock service running on the localhost:
35
+
36
+ ```ruby
37
+ l = Logging.logger["The Wild Wild Test"]
38
+ l.add_appenders(
39
+ Logging.appenders.stderr,
40
+ Logging.appenders.flowdock("Wicky wicky wild", api_token: "AKSDHKSAHDKJAHSDKH-IS-MADE-UP", flow_user: "Bot")
41
+ )
42
+
43
+ l.info "Wootles"
44
+ ```
45
+
46
+ You must provide an `api_token` and a `flow_user`.
47
+
48
+ ### Logging Defaults
49
+
50
+ Sending messages to the Flowdock service can be quite slow, so by default I've set the `flush_period` to 1 second.
51
+ This means a `log.info("MESSAGE")` call should return immediately, and a background thread will flush all logging messages to the Flowdock
52
+ service once every second.
53
+
54
+ If you prefer to *not* do this (e.g. thread-unsafe code) you can disable it:
55
+
56
+ ```
57
+ [...]
58
+
59
+ l.add_appenders(
60
+ Logging.appenders.flowdock(name, ..., flush_period: nil)
61
+ )
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console ${API_TOKEN} ${FLOWDOCK_USER}` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ### To Do's
71
+
72
+ I track major "To Do's" in a [TODO.org](TODO.org) file.
73
+
74
+ I track context-sensitive and minor ones with `TODO` and `FIXME` comments in the source code.
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mexisme/logging-flowdock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
79
+
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/TODO.org ADDED
@@ -0,0 +1,6 @@
1
+ * Tasks
2
+ ** DONE Add docs to the README!
3
+ :LOGBOOK:
4
+ - State "DONE" from "TODO" [2016-02-03 Wed 17:01]
5
+ :END:
6
+ ** TODO Add better doc-comments!
data/bin/console ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "logging"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ name, api_token = ARGV
14
+
15
+ ::Logging.logger.root.add_appenders(::Logging.appenders.stderr)
16
+ ::Logging.logger.root.add_appenders(Logging.appenders.flowdock(name, api_token: api_token, flow_user: "TEST-#{name}"))
17
+ ::Logging.logger.root.level = :debug
18
+
19
+ log = Logging.logger["Console Test"]
20
+
21
+ require "irb"
22
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,74 @@
1
+ require 'flowdock'
2
+
3
+ module Logging
4
+ module Appenders
5
+ # Factory for the Flowdock appender.
6
+ def self.flowdock(*args)
7
+ fail ArgumentError, '::Logging::Appenders::Flowdock needs a name as first argument.' if args.empty?
8
+ ::Logging::Appenders::Flowdock.new(*args)
9
+ end
10
+
11
+ # This class provides an Appender that can write to a Flowdock service over UDP.
12
+ class Flowdock < ::Logging::Appender
13
+ include Buffering
14
+
15
+ # We use a background flusher instead, as the connection to Flowdock can be quite slow:
16
+ DEFAULT_OPTS = {
17
+ flush_period: 1,
18
+ }
19
+ attr_reader :api_token, :flow_user, :flow
20
+
21
+ # Creates a new Flowdock Appender that will use the given host and port
22
+ # as the Flowdock server destination.
23
+ #
24
+ # @param name [String] Stream ID to differentiate in the Flowdock server
25
+ # @param api_token [String]
26
+ # @param flow_user [String]
27
+ def initialize(name, opts = {})
28
+ @api_token = opts[:api_token]
29
+ @flow_user = opts[:flow_user]
30
+
31
+ fail ArgumentError, 'Empty api_token and flow_user is not appropriate' unless api_token && !api_token.empty? && flow_user && !flow_user.empty?
32
+
33
+ # Initialise flow var:
34
+ flow
35
+
36
+ super
37
+ configure_buffering(DEFAULT_OPTS.merge(opts))
38
+ end
39
+
40
+ def flow
41
+ @flow ||= connect(api_token, flow_user)
42
+ end
43
+
44
+ def close(*args)
45
+ super
46
+ @flow = nil
47
+
48
+ self
49
+ end
50
+
51
+ private
52
+
53
+ def connect(host, port)
54
+ ::Flowdock::Flow.new(api_token: api_token, external_user_name: flow_user)
55
+ end
56
+
57
+ def canonical_write(str)
58
+ return self if @flow.nil?
59
+
60
+ str = str.force_encoding(encoding) if encoding && str.encoding != encoding
61
+ timestamp = Time.now.to_s
62
+ message = "#{name} - #{timestamp}:\n#{str}"
63
+ flow.push_to_chat(content: message)
64
+
65
+ self
66
+
67
+ rescue StandardError => err
68
+ self.level = :off
69
+ ::Logging.log_internal { "appender #{name.inspect} has been disabled" }
70
+ ::Logging.log_internal_error(err)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ module Logging
2
+ module Plugins
3
+ # This is plugin-intialisation module used by `little-plugger` to find the code:
4
+ module Flowdock
5
+ extend self
6
+
7
+ VERSION = '0.1.0'.freeze unless defined? VERSION
8
+
9
+ # Initialiser for `little-plugger`:
10
+ def initialize_flowdock
11
+ require File.expand_path('../../appenders/flowdock', __FILE__)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logging/plugins/flowdock'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logging-flowdock"
8
+ spec.version = Logging::Plugins::Flowdock::VERSION
9
+ spec.authors = ["mexisme"]
10
+ spec.email = ["wildjim+dev@kiwinet.org"]
11
+
12
+ spec.summary = 'An appender for the Logging gem that sends messages to a Flowdock channel'
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = 'https://github.com/fairfaxmedia/logging-flowdock'
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.3"
25
+ spec.add_development_dependency 'pry-byebug', '~> 3.2'
26
+
27
+ spec.add_runtime_dependency 'little-plugger', '~> 1.1'
28
+ spec.add_runtime_dependency 'logging', '~> 2.0'
29
+ spec.add_runtime_dependency 'flowdock'
30
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logging-flowdock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mexisme
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: little-plugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: logging
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: flowdock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - wildjim+dev@kiwinet.org
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - TODO.org
128
+ - bin/console
129
+ - bin/setup
130
+ - lib/logging/appenders/flowdock.rb
131
+ - lib/logging/plugins/flowdock.rb
132
+ - logging-flowdock.gemspec
133
+ homepage: https://github.com/fairfaxmedia/logging-flowdock
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.5.1
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: An appender for the Logging gem that sends messages to a Flowdock channel
157
+ test_files: []
158
+ has_rdoc: