Martin Blanchard pushed to branch mablanch/23-new-logging at BuildGrid / buildgrid
Commits:
-
90a514e8
by Raoul Hidalgo Charman at 2018-11-06T15:41:48Z
-
f94cc6ca
by Raoul Hidalgo Charman at 2018-11-06T16:17:23Z
-
96b54a52
by Martin Blanchard at 2018-11-06T17:11:22Z
6 changed files:
- − buildgrid/_app/_logging.py
- buildgrid/_app/cli.py
- buildgrid/server/actioncache/service.py
- buildgrid/server/bots/service.py
- buildgrid/server/execution/service.py
- buildgrid/server/operations/service.py
Changes:
1 |
-# Copyright (C) 2018 Bloomberg LP
|
|
2 |
-#
|
|
3 |
-# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
-# you may not use this file except in compliance with the License.
|
|
5 |
-# You may obtain a copy of the License at
|
|
6 |
-#
|
|
7 |
-# <http://www.apache.org/licenses/LICENSE-2.0>
|
|
8 |
-#
|
|
9 |
-# Unless required by applicable law or agreed to in writing, software
|
|
10 |
-# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
-# See the License for the specific language governing permissions and
|
|
13 |
-# limitations under the License.
|
|
14 |
- |
|
15 |
- |
|
16 |
-import logging
|
|
17 |
- |
|
18 |
- |
|
19 |
-def bgd_logger():
|
|
20 |
- formatter = logging.Formatter(
|
|
21 |
- fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
22 |
- )
|
|
23 |
- |
|
24 |
- logger = logging.getLogger()
|
|
25 |
- logger.setLevel(logging.INFO)
|
|
26 |
- |
|
27 |
- handler = logging.StreamHandler()
|
|
28 |
- handler.setFormatter(formatter)
|
|
29 |
- |
|
30 |
- logger.addHandler(handler)
|
|
31 |
- |
|
32 |
- return logger
|
... | ... | @@ -21,16 +21,14 @@ Any files in the commands/ folder with the name cmd_*.py |
21 | 21 |
will be attempted to be imported.
|
22 | 22 |
"""
|
23 | 23 |
|
24 |
-import os
|
|
25 | 24 |
import logging
|
25 |
+import os
|
|
26 | 26 |
|
27 | 27 |
import click
|
28 | 28 |
import grpc
|
29 | 29 |
|
30 | 30 |
from buildgrid.utils import read_file
|
31 | 31 |
|
32 |
-from . import _logging
|
|
33 |
- |
|
34 | 32 |
CONTEXT_SETTINGS = dict(auto_envvar_prefix='BUILDGRID')
|
35 | 33 |
|
36 | 34 |
|
... | ... | @@ -141,12 +139,27 @@ class BuildGridCLI(click.MultiCommand): |
141 | 139 |
|
142 | 140 |
|
143 | 141 |
@click.command(cls=BuildGridCLI, context_settings=CONTEXT_SETTINGS)
|
144 |
-@click.option('-v', '--verbose', is_flag=True,
|
|
145 |
- help='Enables verbose mode.')
|
|
142 |
+@click.option('-v', '--verbose', count=True,
|
|
143 |
+ help='Increase log verbosity level.')
|
|
146 | 144 |
@pass_context
|
147 | 145 |
def cli(context, verbose):
|
148 | 146 |
"""BuildGrid App"""
|
149 |
- logger = _logging.bgd_logger()
|
|
150 |
- context.verbose = verbose
|
|
151 |
- if verbose:
|
|
147 |
+ logger = logging.getLogger()
|
|
148 |
+ |
|
149 |
+ # Clean-up root logger for any pre-configuration:
|
|
150 |
+ for log_handler in logger.handlers[:]:
|
|
151 |
+ logger.removeHandler(log_handler)
|
|
152 |
+ for log_filter in logger.filters[:]:
|
|
153 |
+ logger.removeFilter(log_filter)
|
|
154 |
+ |
|
155 |
+ logging.basicConfig(
|
|
156 |
+ format='%(asctime)s:%(name)32.32s][%(levelname)5.5s]: %(message)s')
|
|
157 |
+ |
|
158 |
+ if verbose == 1:
|
|
159 |
+ logger.setLevel(logging.WARNING)
|
|
160 |
+ elif verbose == 2:
|
|
161 |
+ logger.setLevel(logging.INFO)
|
|
162 |
+ elif verbose >= 3:
|
|
152 | 163 |
logger.setLevel(logging.DEBUG)
|
164 |
+ else:
|
|
165 |
+ logger.setLevel(logging.ERROR)
|
... | ... | @@ -43,6 +43,8 @@ class ActionCacheService(remote_execution_pb2_grpc.ActionCacheServicer): |
43 | 43 |
|
44 | 44 |
def GetActionResult(self, request, context):
|
45 | 45 |
try:
|
46 |
+ self.logger.debug("GetActionResult request from [{}]"
|
|
47 |
+ .format(context.peer()))
|
|
46 | 48 |
instance = self._get_instance(request.instance_name)
|
47 | 49 |
return instance.get_action_result(request.action_digest)
|
48 | 50 |
|
... | ... | @@ -59,6 +61,8 @@ class ActionCacheService(remote_execution_pb2_grpc.ActionCacheServicer): |
59 | 61 |
|
60 | 62 |
def UpdateActionResult(self, request, context):
|
61 | 63 |
try:
|
64 |
+ self.logger.debug("UpdateActionResult request from [{}]"
|
|
65 |
+ .format(context.peer()))
|
|
62 | 66 |
instance = self._get_instance(request.instance_name)
|
63 | 67 |
instance.update_action_result(request.action_digest, request.action_result)
|
64 | 68 |
return request.action_result
|
... | ... | @@ -44,6 +44,8 @@ class BotsService(bots_pb2_grpc.BotsServicer): |
44 | 44 |
|
45 | 45 |
def CreateBotSession(self, request, context):
|
46 | 46 |
try:
|
47 |
+ self.logger.debug("CreateBotSession request from [{}]"
|
|
48 |
+ .format(context.peer()))
|
|
47 | 49 |
parent = request.parent
|
48 | 50 |
instance = self._get_instance(request.parent)
|
49 | 51 |
return instance.create_bot_session(parent,
|
... | ... | @@ -58,6 +60,8 @@ class BotsService(bots_pb2_grpc.BotsServicer): |
58 | 60 |
|
59 | 61 |
def UpdateBotSession(self, request, context):
|
60 | 62 |
try:
|
63 |
+ self.logger.debug("UpdateBotSession request from [{}]"
|
|
64 |
+ .format(context.peer()))
|
|
61 | 65 |
names = request.name.split("/")
|
62 | 66 |
# Operation name should be in format:
|
63 | 67 |
# {instance/name}/{uuid}
|
... | ... | @@ -85,6 +89,8 @@ class BotsService(bots_pb2_grpc.BotsServicer): |
85 | 89 |
return bots_pb2.BotSession()
|
86 | 90 |
|
87 | 91 |
def PostBotEventTemp(self, request, context):
|
92 |
+ self.logger.debug("PostBotEventTemp request from [{}]"
|
|
93 |
+ .format(context.peer()))
|
|
88 | 94 |
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
89 | 95 |
return Empty()
|
90 | 96 |
|
... | ... | @@ -43,6 +43,8 @@ class ExecutionService(remote_execution_pb2_grpc.ExecutionServicer): |
43 | 43 |
|
44 | 44 |
def Execute(self, request, context):
|
45 | 45 |
try:
|
46 |
+ self.logger.debug("Execute request from [{}]"
|
|
47 |
+ .format(context.peer()))
|
|
46 | 48 |
message_queue = queue.Queue()
|
47 | 49 |
instance = self._get_instance(request.instance_name)
|
48 | 50 |
operation = instance.execute(request.action_digest,
|
... | ... | @@ -78,6 +80,8 @@ class ExecutionService(remote_execution_pb2_grpc.ExecutionServicer): |
78 | 80 |
|
79 | 81 |
def WaitExecution(self, request, context):
|
80 | 82 |
try:
|
83 |
+ self.logger.debug("WaitExecution request from [{}]"
|
|
84 |
+ .format(context.peer()))
|
|
81 | 85 |
names = request.name.split("/")
|
82 | 86 |
|
83 | 87 |
# Operation name should be in format:
|
... | ... | @@ -43,6 +43,8 @@ class OperationsService(operations_pb2_grpc.OperationsServicer): |
43 | 43 |
|
44 | 44 |
def GetOperation(self, request, context):
|
45 | 45 |
try:
|
46 |
+ self.logger.debug("GetOperation request from [{}"
|
|
47 |
+ .format(context.peer()))
|
|
46 | 48 |
name = request.name
|
47 | 49 |
|
48 | 50 |
instance_name = self._parse_instance_name(name)
|
... | ... | @@ -64,6 +66,8 @@ class OperationsService(operations_pb2_grpc.OperationsServicer): |
64 | 66 |
|
65 | 67 |
def ListOperations(self, request, context):
|
66 | 68 |
try:
|
69 |
+ self.logger.debug("ListOperations request from [{}]"
|
|
70 |
+ .format(context.peer()))
|
|
67 | 71 |
# The request name should be the collection name
|
68 | 72 |
# In our case, this is just the instance_name
|
69 | 73 |
instance_name = request.name
|
... | ... | @@ -87,6 +91,8 @@ class OperationsService(operations_pb2_grpc.OperationsServicer): |
87 | 91 |
|
88 | 92 |
def DeleteOperation(self, request, context):
|
89 | 93 |
try:
|
94 |
+ self.logger.debug("DeleteOperation request from [{}]"
|
|
95 |
+ .format(context.peer()))
|
|
90 | 96 |
name = request.name
|
91 | 97 |
|
92 | 98 |
instance_name = self._parse_instance_name(name)
|
... | ... | @@ -104,6 +110,8 @@ class OperationsService(operations_pb2_grpc.OperationsServicer): |
104 | 110 |
|
105 | 111 |
def CancelOperation(self, request, context):
|
106 | 112 |
try:
|
113 |
+ self.logger.debug("CancelOperation request from [{}]"
|
|
114 |
+ .format(context.peer()))
|
|
107 | 115 |
name = request.name
|
108 | 116 |
|
109 | 117 |
instance_name = self._parse_instance_name(name)
|