Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 4393c44

Browse files
committed
Merge pull request #93 from GoogleCloudPlatform/rotate_logging
Basing cloud logging handler off a rotating file handler.
2 parents 90a003b + 52b597f commit 4393c44

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

appengine-vmruntime/vmruntime/cloud_logging.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
import json
1818
import logging
19+
import logging.handlers
1920
import math
2021
import os
2122

2223
LOG_PATH_TEMPLATE = '/var/log/app_engine/app.{pid}.json'
24+
MAX_LOG_BYTES = 128 * 1024 * 1024
25+
LOG_FILE_COUNT = 3
2326

2427

25-
class CloudLoggingHandler(logging.FileHandler):
28+
class CloudLoggingHandler(logging.handlers.RotatingFileHandler):
2629
"""A handler that emits logs to Cloud Logging.
2730
2831
Writes to the Cloud Logging directory, wrapped in JSON and with appropriate
@@ -46,7 +49,9 @@ def __init__(self):
4649
# same file simultaneously, so we'll use the worker's PID to pick a log
4750
# filename.
4851
filename = LOG_PATH_TEMPLATE.format(pid=os.getpid())
49-
super(CloudLoggingHandler, self).__init__(filename)
52+
super(CloudLoggingHandler, self).__init__(filename,
53+
maxBytes=MAX_LOG_BYTES,
54+
backupCount=LOG_FILE_COUNT)
5055

5156
def format(self, record):
5257
"""Format the specified record default behavior, plus JSON and

0 commit comments

Comments
 (0)