我想在安装了 google-cloud-logging gem 的 ruby 脚本中创建一个特定的日志。
当我在我的 Windows 客户端上运行它时它可以工作,但是当我在我的 linux 服务器上运行它时出现以下错误:
/usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/service.rb:327:in `rescue in execute': 14:Connect Failed (Google::Cloud::UnavailableError)
from /usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/service.rb:324:in `execute'
from /usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/service.rb:124:in `write_entries'
from /usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/project.rb:277:in `write_entries'
from ./test.rb:26:in `<main>'
我已经在两台机器上安装了 Google Cloud SDK,并且我通过 ginit 获得了授权。我还添加了密钥文件,它是一个日志管理服务帐户,但没有任何作用。我可以通过同一台机器上的 googl-cloud-storage 将文件上传到存储桶
这是我的 Ruby 脚本示例:
require "google/cloud/logging"
puts "in script"
logging = Google::Cloud::Logging.new(project: "projectname",
keyfile: ###path###)
puts "after logging"
filename = "test from server"
entry = logging.entry
entry.payload = filename
entry.log_name = "1"
entry.resource.type = "gae_app"
entry.resource.labels[:module_id] = "upload"
entry.resource.labels[:version_id] = "1.0.0.0"
puts "after setup"
logging.write_entries entry
puts "after writing"