Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: infra_libs/logs/logs.py

Issue 1527843002: infra_libs/logs: Check if log directory exists. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Utilities for logging. 5 """Utilities for logging.
6 6
7 Example usage: 7 Example usage:
8 8
9 .. code-block:: python 9 .. code-block:: python
10 10
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 _add_file_handlers(options, logger) 251 _add_file_handlers(options, logger)
252 252
253 253
254 def _add_file_handlers(options, logger): # pragma: no cover 254 def _add_file_handlers(options, logger): # pragma: no cover
255 # Test whether we can write to the log directory. If not, write to a 255 # Test whether we can write to the log directory. If not, write to a
256 # temporary directory instead. One of the DEFAULT_LOG_DIRECTORIES are created 256 # temporary directory instead. One of the DEFAULT_LOG_DIRECTORIES are created
257 # on the real production machines by puppet, so /tmp should only be used when 257 # on the real production machines by puppet, so /tmp should only be used when
258 # running locally on developers' workstations. 258 # running locally on developers' workstations.
259 logs_directory = tempfile.gettempdir() 259 logs_directory = tempfile.gettempdir()
260 for directory in options.logs_directory.split(os.pathsep): 260 for directory in options.logs_directory.split(os.pathsep):
261 if not os.path.isdir(directory):
262 continue
263
261 try: 264 try:
262 with tempfile.TemporaryFile(dir=directory): 265 with tempfile.TemporaryFile(dir=directory):
263 pass 266 pass
264 except OSError: 267 except OSError:
265 pass 268 pass
266 else: 269 else:
267 logs_directory = directory 270 logs_directory = directory
268 break 271 break
269 272
270 # Log files are named with this pattern: 273 # Log files are named with this pattern:
(...skipping 12 matching lines...) Expand all
283 for level in file_levels: 286 for level in file_levels:
284 add_handler( 287 add_handler(
285 logger, 288 logger,
286 handler=logging.handlers.RotatingFileHandler( 289 handler=logging.handlers.RotatingFileHandler(
287 filename=os.path.join( 290 filename=os.path.join(
288 logs_directory, pattern % logging.getLevelName(level)), 291 logs_directory, pattern % logging.getLevelName(level)),
289 maxBytes=10 * 1024 * 1024, 292 maxBytes=10 * 1024 * 1024,
290 backupCount=10, 293 backupCount=10,
291 delay=True), 294 delay=True),
292 level=level) 295 level=level)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698