Last active
October 19, 2016 16:44
-
-
Save Fkawala/654093301c47241386b5cd4e02791e56 to your computer and use it in GitHub Desktop.
google cloud logging protobuff RequestLog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import logging | |
from google.protobuf.struct_pb2 import Struct, Value, ListValue | |
client = logging.Client() | |
logger = client.logger('test') | |
line = Struct(fields={'time': Value(string_value='2016-09-04T13:00:08.139759Z'), | |
'severity': Value(string_value='INFO'), | |
'logMessage': Value(string_value='Simply testing')}) | |
lines = ListValue() | |
lines.values.add(struct_value=line) | |
pb_fields = {'@type': Value(string_value='type.googleapis.com/google.appengine.logging.v1.RequestLog'), | |
'startTime':Value(string_value='2016-09-04T13:00:08.117102Z'), | |
'endTime':Value(string_value='2016-09-04T13:00:08.117102Z'), | |
'latency':Value(string_value='0s'), | |
'responseSize':Value(string_value='349'), | |
'userAgent': Value(string_value='agent'), | |
'resource': Value(string_value='test resource'), | |
'line': Value(list_value=lines)} | |
labels = {'serviceName': 'custom.googleapis.com', | |
'custom.googleapis.com/primary_key': 'fake_module', | |
'custom.googleapis.com/secondary_key': 'fake_version', | |
'zone': 'us6'} | |
logger.log_proto(Struct(fields=pb_fields), labels=labels) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile extending the generic Python image with application files for a | |
# single application. | |
FROM ubuntu:latest | |
# And add a bunch of packages. | |
RUN apt-get update | |
RUN apt-get install -y \ | |
python-pip \ | |
python-crypto \ | |
python-openssl | |
ADD requirements /tmp/requirements | |
RUN pip install -r /tmp/requirements | |
ENV GCLOUD_PROJECT project | |
ENV GOOGLE_APPLICATION_CREDENTIALS credentials.json | |
ADD . /app | |
WORKDIR /app | |
CMD python do_log.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google-cloud==0.20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment