LoginSignup
1
1

More than 3 years have passed since last update.

StackDriver loggingでログを追加する方法

Posted at

はじめに

StackDriver loggingでログを追加してみたいと思います。
マニュアルはこちらです。
https://cloud.google.com/logging/docs/agent/configuration

前提

debian-9-drawfork-v20191004でGCE起動して試してました。

Fluentd設定

Stackdriver loggingは、Fluentedを使用しています。そのため、ログを追加するためにFluentedの設定をします。今回は試しにscriptコマンドで出力したコンソールログをStackdriver loggingに転送したいと思います。
設定ファイルは、「/etc/google-fluentd/config.d」配下に作成します。

$ vi /etc/google-fluentd/config.d/script.conf 
<source>
  @type tail
  #フォーマット未設定
  format none

  #転送するファイルパス
  path /home/matsushi/console.log
  pos_file /var/lib/google-fluentd/pos/script.pos
  read_from_head true
  #TagとしてScriptを指定
  tag script
</source>

fluentdを再起動して設定を読み込みます

sudo service google-fluentd restart

スクリプトコマンドを実行し、ログを出力します。

$ script /home/matsushi/console.log 
Script started, file is /home/matsushi/console.log
$ ls
console.log  typescript
$ hostname
instance-1
$ exit
Script done, file is /home/matsushi/console.log

Google Cloud ConsoleのStackderiver loggingの画面でログが出力されていること確認します。

image.png

投稿内容は私個人の意見であり、所属企業・部門見解を代表するものではありません。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1