Created
May 14, 2020 21:29
-
-
Save daoshengmu/5d2eb23165746b8a2c0345c8cb7ec6a0 to your computer and use it in GitHub Desktop.
Glean test debug logging
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 mozlog.structuredlog import StructuredLogger, set_default_logger | |
from pathlib import Path | |
from glean import Glean, Configuration | |
from glean import (load_metrics, | |
load_pings) | |
import logging | |
def init_python_redirect_logger(logger): | |
"""Create a pipe to the main log, at debug level | |
This is so we can see logs from third party libraries (like Glean) | |
""" | |
class RedirectHandler(logging.StreamHandler): | |
def emit(self, record): | |
logger.debug("{}: {}".format(record.name, str(record.msg) % record.args)) | |
rh = RedirectHandler() | |
rh.setLevel(logging.DEBUG) | |
logging.root.addHandler(rh) | |
logging.root.setLevel(logging.DEBUG) | |
logging.basicConfig(level=logging.DEBUG) | |
logger = StructuredLogger("fxr-pc") | |
init_python_redirect_logger(logger) | |
set_default_logger(logger) | |
data_path = Path.home() | |
Glean.initialize( | |
application_id="fxrpc", | |
application_version="0.1.1", | |
upload_enabled=True, | |
configuration=Configuration( | |
ping_tag="fxrpc-test-tag", | |
log_pings=True | |
), | |
data_dir=data_path / "data" | |
) | |
logging.getLogger("glean").setLevel(logging.DEBUG) | |
Glean.set_upload_enabled(True) | |
metrics = load_metrics("metrics.yaml") | |
metrics.usage.app.set("reality") | |
print("Done...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment