logging-google-cloud 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26369695b04328a67b08f2174fe93dfabc72f247
4
+ data.tar.gz: f4d36dea91547ca7a964aaf133ddb502a3feb30b
5
+ SHA512:
6
+ metadata.gz: 66024433cbb1d9f7db99f0d2b504db15a63ab572823905b084cd883018ac222188e7e2fcea293ba0744266260cab957541e7382673d8f64cfe7d8c10a1bc1fe6
7
+ data.tar.gz: 94f5783931d1287399d31b51d6130a6c0bfbe2971917b8086ddbfac71b4a39a70ea26d49e9111b543c063994879985216102c5e959d6e94f282443a542723fd9
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "gcloud", github: "GoogleCloudPlatform/gcloud-ruby", branch: "master"
@@ -0,0 +1,92 @@
1
+ GIT
2
+ remote: git://github.com/GoogleCloudPlatform/gcloud-ruby.git
3
+ revision: bde4915fe7baffae8326ed93b4ffcf3dc2de7c54
4
+ branch: master
5
+ specs:
6
+ gcloud (0.6.1)
7
+ beefcake (~> 1.0)
8
+ digest-crc (~> 0.4)
9
+ google-api-client (~> 0.8.3)
10
+ mime-types (~> 2.4)
11
+ zonefile (~> 1.04)
12
+
13
+ PATH
14
+ remote: .
15
+ specs:
16
+ logging-google-cloud (1.0.2)
17
+ gcloud (~> 0.6)
18
+ logging (~> 2.0)
19
+
20
+ GEM
21
+ remote: http://rubygems.org/
22
+ specs:
23
+ activesupport (4.2.5.1)
24
+ i18n (~> 0.7)
25
+ json (~> 1.7, >= 1.7.7)
26
+ minitest (~> 5.1)
27
+ thread_safe (~> 0.3, >= 0.3.4)
28
+ tzinfo (~> 1.1)
29
+ addressable (2.4.0)
30
+ autoparse (0.3.3)
31
+ addressable (>= 2.3.1)
32
+ extlib (>= 0.9.15)
33
+ multi_json (>= 1.0.0)
34
+ beefcake (1.1.0)
35
+ digest-crc (0.4.1)
36
+ extlib (0.9.16)
37
+ faraday (0.9.2)
38
+ multipart-post (>= 1.2, < 3)
39
+ google-api-client (0.8.6)
40
+ activesupport (>= 3.2)
41
+ addressable (~> 2.3)
42
+ autoparse (~> 0.3)
43
+ extlib (~> 0.9)
44
+ faraday (~> 0.9)
45
+ googleauth (~> 0.3)
46
+ launchy (~> 2.4)
47
+ multi_json (~> 1.10)
48
+ retriable (~> 1.4)
49
+ signet (~> 0.6)
50
+ googleauth (0.5.1)
51
+ faraday (~> 0.9)
52
+ jwt (~> 1.4)
53
+ logging (~> 2.0)
54
+ memoist (~> 0.12)
55
+ multi_json (~> 1.11)
56
+ os (~> 0.9)
57
+ signet (~> 0.7)
58
+ i18n (0.7.0)
59
+ json (1.8.3)
60
+ jwt (1.5.2)
61
+ launchy (2.4.3)
62
+ addressable (~> 2.3)
63
+ little-plugger (1.1.4)
64
+ logging (2.0.0)
65
+ little-plugger (~> 1.1)
66
+ multi_json (~> 1.10)
67
+ memoist (0.14.0)
68
+ mime-types (2.99)
69
+ minitest (5.8.4)
70
+ multi_json (1.11.2)
71
+ multipart-post (2.0.0)
72
+ os (0.9.6)
73
+ retriable (1.4.1)
74
+ signet (0.7.2)
75
+ addressable (~> 2.3)
76
+ faraday (~> 0.9)
77
+ jwt (~> 1.5)
78
+ multi_json (~> 1.10)
79
+ thread_safe (0.3.5)
80
+ tzinfo (1.2.2)
81
+ thread_safe (~> 0.1)
82
+ zonefile (1.04)
83
+
84
+ PLATFORMS
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ gcloud!
89
+ logging-google-cloud!
90
+
91
+ BUNDLED WITH
92
+ 1.11.2
@@ -0,0 +1,71 @@
1
+ ## Logging Google Cloud Appender
2
+ * [Homepage](http://rubygems.org/gems/logging-google-cloud)
3
+ * [Github Project](https://github.com/tobiasstrebitzer/logging-google.cloud)
4
+
5
+ ### Description
6
+
7
+ The Logging Google Cloud Appender provides a way to send log messages from your
8
+ Ruby application to Google Cloud Logging.
9
+
10
+ ### Installation
11
+
12
+ ```
13
+ gem install logging-google-cloud
14
+ ```
15
+
16
+ The Logging module is not yet available in the latest gcloud release on rubygems.
17
+ You need to manually install the [latest gcloud-ruby version from here](https://github.com/GoogleCloudPlatform/gcloud-ruby)
18
+
19
+ ### Examples
20
+
21
+ This example creates and configures a google cloud logging appender and sends verious log messages.
22
+
23
+ ```ruby
24
+ require "logging"
25
+ require "logging/appenders/gcl"
26
+
27
+ Logging.init(Logging::Appenders::GoogleCloudLogging::SEVERITY_NAMES)
28
+ logger = Logging::Logger.new("Dronejob")
29
+ logger.add_appenders(Logging.appenders.gcl('Google Cloud Logging',
30
+ project_id: "project-id",
31
+ log_name: "log-name",
32
+ resource_type: "gce_instance",
33
+ resource_labels: {"instance_id" => "instance-id", "zone" => "us-central1-b"},
34
+ buffer_size: '3',
35
+ immediate_at: 'error, fatal'
36
+ ))
37
+
38
+ logger.debug("debug message")
39
+ logger.info("info message")
40
+ logger.notice("notice message")
41
+ logger.warning("warning message")
42
+ logger.error("error message")
43
+ logger.critical("critical message")
44
+ logger.alert("alert message")
45
+ logger.emergency("emergency message")
46
+ ```
47
+
48
+ ### License
49
+
50
+ The MIT License
51
+
52
+ Copyright (c) 2016 Tobias Strebitzer
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ 'Software'), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
68
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
69
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
70
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
71
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ module LoggingGoogleCloud
2
+ VERSION = "1.0.2"
3
+ end
@@ -0,0 +1,95 @@
1
+ require "gcloud"
2
+
3
+ module Logging
4
+ module Appenders
5
+
6
+ def self.gcl( *args )
7
+ if !Gcloud.instance_methods.include?(:logging)
8
+ puts "-- Gcloud Logging module not available. Please use the latest gcloud version from github master."
9
+ return false
10
+ end
11
+ return ::Logging::Appenders::GoogleCloudLogging if args.empty?
12
+ ::Logging::Appenders::GoogleCloudLogging.new(*args)
13
+ end
14
+
15
+ class GoogleCloudLogging < ::Logging::Appender
16
+ SEVERITY_NAMES = %w(DEBUG INFO NOTICE WARNING ERROR CRITICAL ALERT EMERGENCY)
17
+
18
+ include Buffering
19
+ attr_reader :project_id, :log_name, :resource_type, :resource_labels, :keyfile
20
+
21
+ def initialize(name, options={})
22
+ super(name, options)
23
+ auto_flushing = options.fetch(:buffsize, options.fetch(:buffer_size, 100))
24
+ configure_buffering({:auto_flushing => auto_flushing}.merge(options))
25
+
26
+ @project_id = options.fetch(:project_id, nil)
27
+ raise ArgumentError, 'Must specify project id' if @project_id.nil?
28
+
29
+ @log_name = options.fetch(:log_name, nil)
30
+ raise ArgumentError, 'Must specify log name' if @log_name.nil?
31
+
32
+ @resource_type = options.fetch(:resource_type, nil)
33
+ raise ArgumentError, 'Must specify resource type' if @resource_type.empty?
34
+
35
+ @resource_labels = options.fetch(:resource_labels, nil)
36
+ @keyfile = options.fetch(:keyfile, nil)
37
+ end
38
+
39
+ def gcloud_logging
40
+ @gcloud_logging ||= Gcloud.new(@project_id, @keyfile).logging
41
+ end
42
+
43
+ def resource
44
+ gcloud_logging.resource(@resource_type, @resource_labels)
45
+ end
46
+
47
+ def close( *args )
48
+ super(false)
49
+ end
50
+
51
+ def flush
52
+ return self if @buffer.empty?
53
+ entries = nil
54
+ sync do
55
+ entries = @buffer.dup
56
+ @buffer.clear
57
+ end
58
+
59
+ send_entries(entries)
60
+
61
+ self
62
+ end
63
+
64
+ private
65
+
66
+ def write(event)
67
+ entry = gcloud_logging.entry.tap do |entry|
68
+ entry.timestamp = Time.now
69
+ entry.severity = ::Logging::LNAMES[event.level]
70
+ entry.payload = event.data
71
+ entry.labels[:file] = event.file if !event.file.empty?
72
+ entry.labels[:line] = event.line if !event.line.empty?
73
+ entry.labels[:method] = event.method if !event.method.empty?
74
+ end
75
+
76
+ if @auto_flushing == 1
77
+ send_entries([entry])
78
+ else
79
+ sync {
80
+ @buffer << entry
81
+ }
82
+ @periodic_flusher.signal if @periodic_flusher
83
+ flush if @buffer.length >= @auto_flushing || immediate?(event)
84
+ end
85
+
86
+ self
87
+ end
88
+
89
+ def send_entries(entries)
90
+ gcloud_logging.write_entries(entries, log_name: @log_name, resource: resource)
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'logging-google-cloud/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "logging-google-cloud"
7
+ s.version = LoggingGoogleCloud::VERSION
8
+ s.licenses = ["BSD-3-Clause"]
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Tobias Strebitzer"]
11
+ s.email = ["*@magloft.com"]
12
+ s.homepage = "https://github.com/tobiasstrebitzer/logging-google-cloud"
13
+ s.summary = "Google Cloud Logging appender"
14
+ s.description = "Google Cloud Logging appender for the logging gem"
15
+ s.required_ruby_version = '~> 2.0'
16
+ s.required_rubygems_version = '~> 2.5'
17
+ s.add_runtime_dependency "logging", "~> 2.0"
18
+ s.add_runtime_dependency "gcloud", "~> 0.6"
19
+ s.files = `git ls-files`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ s.require_path = 'lib'
22
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logging-google-cloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Strebitzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logging
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gcloud
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ description: Google Cloud Logging appender for the logging gem
42
+ email:
43
+ - '*@magloft.com'
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - README.md
51
+ - lib/logging-google-cloud/version.rb
52
+ - lib/logging/appenders/gcl.rb
53
+ - logging-google-cloud.gemspec
54
+ homepage: https://github.com/tobiasstrebitzer/logging-google-cloud
55
+ licenses:
56
+ - BSD-3-Clause
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: '2.5'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.5.1
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Google Cloud Logging appender
78
+ test_files: []
79
+ has_rdoc: