Skip to content

Commit e488895

Browse files
waprinJon Wayne Parrott
authored andcommitted
Use Stackdriver Logging Handlers (GoogleCloudPlatform#91)
1 parent f1f1c42 commit e488895

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

5-logging/bookshelf/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import logging
1717

1818
from flask import current_app, Flask, redirect, request, session, url_for
19+
import google.cloud.logging
20+
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging
1921
import httplib2
2022
from oauth2client.contrib.flask_util import UserOAuth2
2123

@@ -34,9 +36,12 @@ def create_app(config, debug=False, testing=False, config_overrides=None):
3436
app.config.update(config_overrides)
3537

3638
# [START setup_logging]
37-
# Configure logging
3839
if not app.testing:
39-
logging.basicConfig(level=logging.INFO)
40+
client = google.cloud.logging.Client(app.config['PROJECT_ID'])
41+
handler = CloudLoggingHandler(client)
42+
# Attaches the handler to the root logger
43+
setup_logging(handler)
44+
logging.getLogger().setLevel(logging.INFO)
4045
# [END setup_logging]
4146

4247
# Setup the data model.

6-pubsub/bookshelf/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import logging
1717

1818
from flask import current_app, Flask, redirect, request, session, url_for
19+
import google.cloud.logging
20+
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging
1921
import httplib2
2022
from oauth2client.contrib.flask_util import UserOAuth2
2123

@@ -35,7 +37,11 @@ def create_app(config, debug=False, testing=False, config_overrides=None):
3537

3638
# Configure logging
3739
if not app.testing:
38-
logging.basicConfig(level=logging.INFO)
40+
client = google.cloud.logging.Client(app.config['PROJECT_ID'])
41+
handler = CloudLoggingHandler(client)
42+
# Attaches the handler to the root logger
43+
setup_logging(handler)
44+
logging.getLogger().setLevel(logging.INFO)
3945

4046
# Setup the data model.
4147
with app.app_context():

7-gce/bookshelf/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import logging
1717

1818
from flask import current_app, Flask, redirect, request, session, url_for
19+
import google.cloud.logging
20+
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging
1921
import httplib2
2022
from oauth2client.contrib.flask_util import UserOAuth2
2123

@@ -35,7 +37,11 @@ def create_app(config, debug=False, testing=False, config_overrides=None):
3537

3638
# Configure logging
3739
if not app.testing:
38-
logging.basicConfig(level=logging.INFO)
40+
client = google.cloud.logging.Client(app.config['PROJECT_ID'])
41+
handler = CloudLoggingHandler(client)
42+
# Attaches the handler to the root logger
43+
setup_logging(handler)
44+
logging.getLogger().setLevel(logging.INFO)
3945

4046
# Setup the data model.
4147
with app.app_context():

0 commit comments

Comments
 (0)