google-cloud-logging 1.4.0 → 1.5.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 +4 -4
- data/README.md +19 -19
- data/lib/google-cloud-logging.rb +41 -0
- data/lib/google/cloud/logging.rb +65 -16
- data/lib/google/cloud/logging/async_writer.rb +11 -11
- data/lib/google/cloud/logging/credentials.rb +6 -6
- data/lib/google/cloud/logging/entry/http_request.rb +1 -2
- data/lib/google/cloud/logging/entry/list.rb +1 -1
- data/lib/google/cloud/logging/entry/operation.rb +1 -2
- data/lib/google/cloud/logging/entry/source_location.rb +1 -2
- data/lib/google/cloud/logging/log/list.rb +1 -1
- data/lib/google/cloud/logging/logger.rb +12 -11
- data/lib/google/cloud/logging/metric.rb +2 -2
- data/lib/google/cloud/logging/metric/list.rb +1 -1
- data/lib/google/cloud/logging/middleware.rb +23 -16
- data/lib/google/cloud/logging/project.rb +58 -67
- data/lib/google/cloud/logging/rails.rb +16 -13
- data/lib/google/cloud/logging/resource_descriptor/list.rb +3 -2
- data/lib/google/cloud/logging/service.rb +22 -22
- data/lib/google/cloud/logging/sink.rb +63 -49
- data/lib/google/cloud/logging/sink/list.rb +1 -1
- data/lib/google/cloud/logging/version.rb +1 -1
- metadata +11 -11
@@ -167,7 +167,7 @@ module Google
|
|
167
167
|
# @private Raise an error unless an active connection to the service
|
168
168
|
# is available.
|
169
169
|
def ensure_service!
|
170
|
-
|
170
|
+
raise "Must have active connection to service" unless @service
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
@@ -146,7 +146,7 @@ module Google
|
|
146
146
|
# @private Raise an error unless an active connection to the service
|
147
147
|
# is available.
|
148
148
|
def ensure_service!
|
149
|
-
|
149
|
+
raise "Must have active connection to service" unless @service
|
150
150
|
end
|
151
151
|
end
|
152
152
|
end
|
@@ -71,7 +71,7 @@ module Google
|
|
71
71
|
##
|
72
72
|
# The Google Cloud log_name to write the log entry with.
|
73
73
|
attr_reader :log_name
|
74
|
-
|
74
|
+
alias progname log_name
|
75
75
|
|
76
76
|
##
|
77
77
|
# The Google Cloud resource to write the log entry with.
|
@@ -84,8 +84,8 @@ module Google
|
|
84
84
|
##
|
85
85
|
# The logging severity threshold (e.g. `Logger::INFO`)
|
86
86
|
attr_reader :level
|
87
|
-
|
88
|
-
|
87
|
+
alias sev_threshold level
|
88
|
+
alias local_level level
|
89
89
|
|
90
90
|
##
|
91
91
|
# Boolean flag that indicates whether this logger can be silenced or
|
@@ -317,7 +317,7 @@ module Google
|
|
317
317
|
write_entry severity, message unless @closed
|
318
318
|
true
|
319
319
|
end
|
320
|
-
|
320
|
+
alias log add
|
321
321
|
|
322
322
|
##
|
323
323
|
# Logs the given message at UNKNOWN severity.
|
@@ -393,11 +393,13 @@ module Google
|
|
393
393
|
#
|
394
394
|
def level= severity
|
395
395
|
new_level = derive_severity severity
|
396
|
-
|
396
|
+
if new_level.nil?
|
397
|
+
raise ArgumentError, "invalid log level: #{severity}"
|
398
|
+
end
|
397
399
|
@level = new_level
|
398
400
|
end
|
399
|
-
|
400
|
-
|
401
|
+
alias sev_threshold= level=
|
402
|
+
alias local_level= level=
|
401
403
|
|
402
404
|
##
|
403
405
|
# Close the logging "device". This effectively disables logging from
|
@@ -482,7 +484,7 @@ module Google
|
|
482
484
|
|
483
485
|
##
|
484
486
|
# @deprecated Use delete_request_info
|
485
|
-
|
487
|
+
alias delete_trace_id delete_request_info
|
486
488
|
|
487
489
|
##
|
488
490
|
# No-op method. Created to match the spec of ActiveSupport::Logger#flush
|
@@ -584,15 +586,14 @@ module Google
|
|
584
586
|
when "error".freeze then ::Logger::ERROR
|
585
587
|
when "fatal".freeze then ::Logger::FATAL
|
586
588
|
when "unknown".freeze then ::Logger::UNKNOWN
|
587
|
-
else nil
|
588
589
|
end
|
589
590
|
end
|
590
591
|
|
591
592
|
##
|
592
593
|
# @private Get Google Cloud deverity from logger level number.
|
593
594
|
def gcloud_severity severity_int
|
594
|
-
%i
|
595
|
-
rescue
|
595
|
+
%i[DEBUG INFO WARNING ERROR CRITICAL DEFAULT][severity_int]
|
596
|
+
rescue StandardError
|
596
597
|
:DEFAULT
|
597
598
|
end
|
598
599
|
|
@@ -125,7 +125,7 @@ module Google
|
|
125
125
|
@grpc = service.get_metric name
|
126
126
|
true
|
127
127
|
end
|
128
|
-
|
128
|
+
alias refresh! reload!
|
129
129
|
|
130
130
|
##
|
131
131
|
# Permanently deletes the logs-based metric.
|
@@ -160,7 +160,7 @@ module Google
|
|
160
160
|
# @private Raise an error unless an active connection to the service is
|
161
161
|
# available.
|
162
162
|
def ensure_service!
|
163
|
-
|
163
|
+
raise "Must have active connection to service" unless service
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
@@ -161,7 +161,7 @@ module Google
|
|
161
161
|
# @private Raise an error unless an active connection to the service
|
162
162
|
# is available.
|
163
163
|
def ensure_service!
|
164
|
-
|
164
|
+
raise "Must have active connection to service" unless @service
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
@@ -22,12 +22,13 @@ module Google
|
|
22
22
|
##
|
23
23
|
# The default log name used to instantiate the default logger if one
|
24
24
|
# isn't provided.
|
25
|
-
DEFAULT_LOG_NAME = "ruby_app_log"
|
25
|
+
DEFAULT_LOG_NAME = "ruby_app_log".freeze
|
26
26
|
|
27
27
|
##
|
28
28
|
# A default value for the log_name_map argument. Directs health check
|
29
29
|
# logs to a separate log name so they don't spam the main log.
|
30
|
-
DEFAULT_LOG_NAME_MAP =
|
30
|
+
DEFAULT_LOG_NAME_MAP =
|
31
|
+
{ "/_ah/health" => "ruby_health_check_log" }.freeze
|
31
32
|
|
32
33
|
##
|
33
34
|
# The Google::Cloud::Logging::Logger instance
|
@@ -59,11 +60,12 @@ module Google
|
|
59
60
|
@logger = logger
|
60
61
|
else
|
61
62
|
log_name = configuration.log_name
|
62
|
-
logging = Logging.new
|
63
|
-
|
63
|
+
logging = Logging.new project_id: configuration.project_id,
|
64
|
+
credentials: configuration.credentials
|
64
65
|
resource = Middleware.build_monitored_resource(
|
65
66
|
configuration.monitored_resource.type,
|
66
|
-
configuration.monitored_resource.labels
|
67
|
+
configuration.monitored_resource.labels
|
68
|
+
)
|
67
69
|
@logger = logging.logger log_name, resource
|
68
70
|
end
|
69
71
|
end
|
@@ -225,7 +227,8 @@ module Google
|
|
225
227
|
if Google::Cloud.env.app_engine?
|
226
228
|
["gae_app", {
|
227
229
|
module_id: Google::Cloud.env.app_engine_service_id,
|
228
|
-
version_id: Google::Cloud.env.app_engine_service_version
|
230
|
+
version_id: Google::Cloud.env.app_engine_service_version
|
231
|
+
}]
|
229
232
|
elsif Google::Cloud.env.container_engine?
|
230
233
|
["container", {
|
231
234
|
cluster_name: Google::Cloud.env.container_engine_cluster_name,
|
@@ -235,7 +238,8 @@ module Google
|
|
235
238
|
elsif Google::Cloud.env.compute_engine?
|
236
239
|
["gce_instance", {
|
237
240
|
instance_id: Google::Cloud.env.instance_name,
|
238
|
-
zone: Google::Cloud.env.instance_zone
|
241
|
+
zone: Google::Cloud.env.instance_zone
|
242
|
+
}]
|
239
243
|
else
|
240
244
|
["global", {}]
|
241
245
|
end
|
@@ -256,12 +260,14 @@ module Google
|
|
256
260
|
# already.
|
257
261
|
#
|
258
262
|
def load_config **kwargs
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
configuration.
|
264
|
-
|
263
|
+
project_id = kwargs[:project] || kwargs[:project_id]
|
264
|
+
configuration.project_id = project_id unless project_id.nil?
|
265
|
+
|
266
|
+
creds = kwargs[:credentials] || kwargs[:keyfile]
|
267
|
+
configuration.credentials = creds unless creds.nil?
|
268
|
+
|
269
|
+
log_name_map = kwargs[:log_name_map]
|
270
|
+
configuration.log_name_map = log_name_map unless log_name_map.nil?
|
265
271
|
|
266
272
|
init_default_config
|
267
273
|
end
|
@@ -269,9 +275,10 @@ module Google
|
|
269
275
|
##
|
270
276
|
# Fallback to default configuration values if not defined already
|
271
277
|
def init_default_config
|
272
|
-
configuration.project_id ||=
|
273
|
-
|
274
|
-
|
278
|
+
configuration.project_id ||= begin
|
279
|
+
(Cloud.configure.project_id || Logging.default_project_id)
|
280
|
+
end
|
281
|
+
configuration.credentials ||= Cloud.configure.credentials
|
275
282
|
configuration.log_name ||= DEFAULT_LOG_NAME
|
276
283
|
configuration.log_name_map ||= DEFAULT_LOG_NAME_MAP
|
277
284
|
end
|
@@ -14,7 +14,6 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "google/cloud/errors"
|
17
|
-
require "google/cloud/env"
|
18
17
|
require "google/cloud/logging/service"
|
19
18
|
require "google/cloud/logging/credentials"
|
20
19
|
require "google/cloud/logging/log/list"
|
@@ -75,16 +74,7 @@ module Google
|
|
75
74
|
def project_id
|
76
75
|
service.project
|
77
76
|
end
|
78
|
-
|
79
|
-
|
80
|
-
##
|
81
|
-
# @private Default project.
|
82
|
-
def self.default_project_id
|
83
|
-
ENV["LOGGING_PROJECT"] ||
|
84
|
-
ENV["GOOGLE_CLOUD_PROJECT"] ||
|
85
|
-
ENV["GCLOUD_PROJECT"] ||
|
86
|
-
Google::Cloud.env.project_id
|
87
|
-
end
|
77
|
+
alias project project_id
|
88
78
|
|
89
79
|
##
|
90
80
|
# Lists log entries. Use this method to retrieve log entries from Cloud
|
@@ -164,7 +154,7 @@ module Google
|
|
164
154
|
filter: filter, order: order,
|
165
155
|
projects: projects
|
166
156
|
end
|
167
|
-
|
157
|
+
alias find_entries entries
|
168
158
|
|
169
159
|
##
|
170
160
|
# Creates an new Entry instance that may be populated and written to the
|
@@ -226,7 +216,7 @@ module Google
|
|
226
216
|
e.payload = payload if payload
|
227
217
|
e
|
228
218
|
end
|
229
|
-
|
219
|
+
alias new_entry entry
|
230
220
|
|
231
221
|
##
|
232
222
|
# Writes log entries to the Stackdriver Logging service.
|
@@ -469,9 +459,9 @@ module Google
|
|
469
459
|
max: max
|
470
460
|
Log::List.from_grpc list_grpc, service, resource: resource, max: max
|
471
461
|
end
|
472
|
-
|
473
|
-
|
474
|
-
|
462
|
+
alias find_logs logs
|
463
|
+
alias log_names logs
|
464
|
+
alias find_log_names logs
|
475
465
|
|
476
466
|
##
|
477
467
|
# Deletes a log and all its log entries. The log will reappear if it
|
@@ -537,7 +527,7 @@ module Google
|
|
537
527
|
list_grpc = service.list_resource_descriptors token: token, max: max
|
538
528
|
ResourceDescriptor::List.from_grpc list_grpc, service, max
|
539
529
|
end
|
540
|
-
|
530
|
+
alias find_resource_descriptors resource_descriptors
|
541
531
|
|
542
532
|
##
|
543
533
|
# Creates a new monitored resource instance.
|
@@ -564,7 +554,7 @@ module Google
|
|
564
554
|
r.labels = labels
|
565
555
|
end
|
566
556
|
end
|
567
|
-
|
557
|
+
alias new_resource resource
|
568
558
|
|
569
559
|
##
|
570
560
|
# Retrieves the list of sinks belonging to the project.
|
@@ -600,7 +590,10 @@ module Google
|
|
600
590
|
list_grpc = service.list_sinks token: token, max: max
|
601
591
|
Sink::List.from_grpc list_grpc, service, max
|
602
592
|
end
|
603
|
-
|
593
|
+
alias find_sinks sinks
|
594
|
+
|
595
|
+
# rubocop:disable Metrics/LineLength
|
596
|
+
# overload is too long...
|
604
597
|
|
605
598
|
##
|
606
599
|
# Creates a new project sink. When you create a sink, only new log
|
@@ -621,40 +614,27 @@ module Google
|
|
621
614
|
# @see https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs
|
622
615
|
# Permissions for writing exported logs
|
623
616
|
#
|
624
|
-
# @
|
625
|
-
#
|
626
|
-
#
|
627
|
-
#
|
628
|
-
#
|
629
|
-
# destination
|
630
|
-
#
|
631
|
-
#
|
632
|
-
#
|
633
|
-
#
|
634
|
-
#
|
635
|
-
#
|
636
|
-
#
|
637
|
-
#
|
638
|
-
#
|
639
|
-
#
|
640
|
-
#
|
641
|
-
#
|
642
|
-
#
|
643
|
-
#
|
644
|
-
#
|
645
|
-
# @param [Symbol] version The log entry version used when exporting log
|
646
|
-
# entries from this sink. This version does not have to correspond to
|
647
|
-
# the version of the log entry when it was written to Stackdriver
|
648
|
-
# Logging. Accepted values are `:unspecified`, `:v2`, and `:v1`.
|
649
|
-
# Version 2 is currently the preferred format. An unspecified version
|
650
|
-
# format currently defaults to V2 in the service. The default value is
|
651
|
-
# `:unspecified`.
|
652
|
-
# @param [Boolean] unique_writer_identity Whether the sink will have a
|
653
|
-
# dedicated service account returned in the sink's `writer_identity`.
|
654
|
-
# Set this field to be true to export logs from one project to a
|
655
|
-
# different project. This field is ignored for non-project sinks
|
656
|
-
# (e.g. organization sinks) because those sinks are required to have
|
657
|
-
# dedicated service accounts. Optional.
|
617
|
+
# @overload create_sink(name, destination, filter: nil, unique_writer_identity: nil)
|
618
|
+
# @param [String] name The client-assigned sink identifier. Sink
|
619
|
+
# identifiers are limited to 1000 characters and can include only
|
620
|
+
# the following characters: `A-Z`, `a-z`, `0-9`, and the special
|
621
|
+
# characters `_-.`.
|
622
|
+
# @param [String] destination The resource name of the export
|
623
|
+
# destination. See [About
|
624
|
+
# sinks](https://cloud.google.com/logging/docs/api/tasks/exporting-logs#about_sinks)
|
625
|
+
# for examples.
|
626
|
+
# @param [String, nil] filter An [advanced logs
|
627
|
+
# filter](https://cloud.google.com/logging/docs/view/advanced_filters)
|
628
|
+
# that defines the log entries to be exported. The filter must be
|
629
|
+
# consistent with the log entry format designed by the `version`
|
630
|
+
# parameter, regardless of the format of the log entry that was
|
631
|
+
# originally written to Stackdriver Logging.
|
632
|
+
# @param [Boolean] unique_writer_identity Whether the sink will have a
|
633
|
+
# dedicated service account returned in the sink's
|
634
|
+
# `writer_identity`. Set this field to be true to export logs from
|
635
|
+
# one project to a different project. This field is ignored for
|
636
|
+
# non-project sinks (e.g. organization sinks) because those sinks
|
637
|
+
# are required to have dedicated service accounts. Optional.
|
658
638
|
#
|
659
639
|
# @return [Google::Cloud::Logging::Sink] a project sink
|
660
640
|
#
|
@@ -676,18 +656,29 @@ module Google
|
|
676
656
|
# sink = logging.create_sink "my-sink",
|
677
657
|
# "storage.googleapis.com/#{bucket.id}"
|
678
658
|
#
|
679
|
-
def create_sink name, destination, filter: nil,
|
680
|
-
|
681
|
-
|
682
|
-
version = Sink.resolve_version version
|
659
|
+
def create_sink name, destination, filter: nil,
|
660
|
+
unique_writer_identity: nil,
|
661
|
+
start_at: nil, end_at: nil, version: nil
|
683
662
|
ensure_service!
|
663
|
+
|
664
|
+
if start_at
|
665
|
+
warn "[DEPRECATION] start_at is deprecated and will be ignored."
|
666
|
+
end
|
667
|
+
if end_at
|
668
|
+
warn "[DEPRECATION] end_at is deprecated and will be ignored."
|
669
|
+
end
|
670
|
+
if version
|
671
|
+
warn "[DEPRECATION] version is deprecated and will be ignored."
|
672
|
+
end
|
673
|
+
|
684
674
|
grpc = service.create_sink \
|
685
|
-
name, destination, filter,
|
686
|
-
start_time: start_at, end_time: end_at,
|
675
|
+
name, destination, filter,
|
687
676
|
unique_writer_identity: unique_writer_identity
|
688
677
|
Sink.from_grpc grpc, service
|
689
678
|
end
|
690
|
-
|
679
|
+
alias new_sink create_sink
|
680
|
+
|
681
|
+
# rubocop:enable Metrics/LineLength
|
691
682
|
|
692
683
|
##
|
693
684
|
# Retrieves a sink by name.
|
@@ -716,8 +707,8 @@ module Google
|
|
716
707
|
rescue Google::Cloud::NotFoundError
|
717
708
|
nil
|
718
709
|
end
|
719
|
-
|
720
|
-
|
710
|
+
alias get_sink sink
|
711
|
+
alias find_sink sink
|
721
712
|
|
722
713
|
##
|
723
714
|
# Retrieves the list of metrics belonging to the project.
|
@@ -753,7 +744,7 @@ module Google
|
|
753
744
|
grpc = service.list_metrics token: token, max: max
|
754
745
|
Metric::List.from_grpc grpc, service, max
|
755
746
|
end
|
756
|
-
|
747
|
+
alias find_metrics metrics
|
757
748
|
|
758
749
|
##
|
759
750
|
# Creates a new logs-based metric for Google Cloud Monitoring.
|
@@ -786,7 +777,7 @@ module Google
|
|
786
777
|
grpc = service.create_metric name, filter, description
|
787
778
|
Metric.from_grpc grpc, service
|
788
779
|
end
|
789
|
-
|
780
|
+
alias new_metric create_metric
|
790
781
|
|
791
782
|
##
|
792
783
|
# Retrieves metric by name.
|
@@ -815,8 +806,8 @@ module Google
|
|
815
806
|
rescue Google::Cloud::NotFoundError
|
816
807
|
nil
|
817
808
|
end
|
818
|
-
|
819
|
-
|
809
|
+
alias get_metric metric
|
810
|
+
alias find_metric metric
|
820
811
|
|
821
812
|
protected
|
822
813
|
|
@@ -824,7 +815,7 @@ module Google
|
|
824
815
|
# @private Raise an error unless an active connection to the service is
|
825
816
|
# available.
|
826
817
|
def ensure_service!
|
827
|
-
|
818
|
+
raise "Must have active connection to service" unless service
|
828
819
|
end
|
829
820
|
end
|
830
821
|
end
|