Package: hg-loggingmod
Mercurial logs through theloggingmoduleThis extension redirects most user feedback meant for terminals to the
Pythonloggingmodule of the standard library.This is intended intended primarily for server-side use cases, and is unlikely
to be useful for client-side operation.Indeed on a server, many messages are useful for the systems administrator
only, and would be unwanted pollution if seen by the client.
A notable exception isui.statuswhich is really used
to report back meaningful information over the wire.Using logging is more robust and flexible than using flags such asui.debugand redirectingstderr. It also provides integration with
Sentry (see below). Many other logs aggregation systems that have alogginghandler could be directly used.At the time of this writing, it has the side effect to disable other extensions
meant for logs, such asblackbox.InstallationInstall withpiporpip3:pip install hgext-loggingmod
   pip3 install "hgext-loggingmod>=0.2.0"Then, in your HGRC, include this:[extensions]loggingmod=ConfigurationAll parameters are to be set within the[logging]hgrc section.Basic configurationThese are applied first, using mostlylogging.basicConfigExample (these are the default values):[logging]level=infoformat=[%(asctime)s] [%(process)d] [%(levelname)s] [%(name)s] %(message)shg_format=[%(asctime)s] [%(process)d] repo:%(repo)s [%(levelname)s] [%(name)s] %(message)sLogging to a file[logging]file=/var/log/mercurial.logFormatTheformatstring is a regular logging format string, seeLogRecord attributesfor a full list of the keys that can be used there.Thehg_formatstring is also a regular logging format string, but it
can additionally make use of therepoparameter: the full path to the
current repository on the file system, if relevant to the given log record.
This format is used in thehglogger and its descendants, such ashg.logging,hg.discoveryetc.The times will include the timezone by default.Advanced configuration through filesJSONThis is the most complete, as it leveragesdictConfig()[logging]
config.json = /etc/hg-logging.jsonThe basic configuration above is done first nevertheless, but it is wiped out
unless one uses theincrementalkeyword.INIThis is forwarded tofileConfig()[logging]
config.ini = /etc/hg-logging.iniUsing with SentryPrerequisitesThesentry_sdkpackage should be importable from the Mercurial process, seeSentry install instructionsIn our experience,pip install sentry-sdkhas not been enough, we had to also
installBrotlias well. Your mileage may
vary.In doubt,test it firstActivationTo forward logs to Sentry, just specify the DSN in the hgrc:[logging]
sentry.dsn = https://<key>@sentry.example.net/<project>Warning : don't use quotes above.Basic configurationThe Sentry default integration catches all logging calls, and is orthogonal
to the regularloggingconfiguration, except for the logger levels.This extension has several knobs to tweak it.
Here's an example[logging]sentry.ignore_loggers=discovery extension# these are the default values:sentry.event_level=errorsentry.breadcrumb_level=infoFine configurationInstead of the flat configuration as above, you can disable the blanket
integration and resort to explicit configuration with theconfig.jsondirective and Sentry's handlers[logging]config.json=/etc/hg-config-with-sentry.confsentry.dsn=https://<key>@sentry.example.net/<project>sentry.default_integration=falseOf course, this also disables thesentry.event_levelandsentry.breadcrumbs_levelconfig items.At the time of this writing, these handlers aresentry_sdk.integrations.logging.EventHandlersentry_sdk.integrations.logging.BreadCrumbHandlerSee also:Handler classesin Sentry documentation