Saravanan666/pypi-org huggingface dataset:
Package: log-to-json
Logging to JSONYet another log to JSON library for Python.
I needed a library that integrated well with applications that mixed logging using built-in logging outputs and JSON output.
I was also unable to find a library that worked withlogging.QueueHandlerThus this library was born.Installpip install log-to-jsonorconda install log-to-json -c conda-forgeExampleBasic Usagefromlog_to_jsonimportJsonFormatterimportlogginglogger=logging.getLogger()handler=logging.StreamHandler()json_formatter=JsonFormatter(keys=("name",))handler.setFormatter(json_formatter)logger.critical({"app-name":"my-app","app_version":"1.0"})# produces the log{"app-name":"my-app","app_version":"1.0","name":"root"}Slightly more advanced Usagefromlog_to_jsonimportJsonFormatterimportlogginglogger=logging.getLogger()handler=logging.StreamHandler()deffinalizer(message_dict):"""rename name to logger_name"""message_dict["logger_name"]=message_dict.pop("name")returnmessage_dictjson_formatter=JsonFormatter(keys=("message","name","user"),formatters={"user":str.upper},finalizer=finalizer)handler.setFormatter(json_formatter)logger.critical("critical failure",extra={"user":"guest"})# produces the message{"message":"critical failure","user":"GUEST","logger_name":"root"}Notable FeaturesIndividual Key FormattersFinalizerPer Message PrefixIntegrates with non-JSON LoggingPluggable Serializer
Package: log-to-kafka
log_to_kafka============DESCRIPTION------------ 将日志发送到kafka中，做日志分布式管理INSTALL-------ubuntu & windows>>>>>>>>>>>>>>>>::git clone https://github.com/ShichaoMa/log_to_kafka.gitsudo python setup.py  installorsudo pip install log_to_kafkaHELLOWORLD----------demo1>>>>>::from log_to_kafka import Loggerclass MyClass(Logger):name = "log_name"def __init__(self, settings_file):super(MyClass, self).__init__(settings_file)MC = MyClass("default_settings.py")MC.set_logger()MC.logger.debug("....")demo2>>>>>::import osfrom log_to_kafka import LogFactoryfrom cloghandler import ConcurrentRotatingFileHandlermy_dir = "logs"try:os.makedirs(my_dir)except OSError as exception:if exception.errno != errno.EEXIST:raiselogger = LogFactory.get_instance(name="test_name")logger.set_handler(ConcurrentRotatingFileHandler(os.path.join(my_dir, "test.log"),backupCount=5,maxBytes=10240))logger.info("this is a log. ")demo3>>>>>::from log_to_kafka import LogFactory, KafkaHandlersettings = {"KAFKA_HOSTS":"192.168.200.90:9092", "TOPIC":"jay-cluster-logs"}logger = LogFactory.get_instance(name="test_name", json=True)kafka_handler = KafkaHandler(settings)logger.set_handler(kafka_handler)logger.info("this is a log. ")demo4>>>>>::import sysimport loggingfrom log_to_kafka import LogFactorylogger = LogFactory.get_instance(name="test_name")logger.set_handler(logging.StreamHandler(sys.stdout))logger.info("this is a log. ")demo5>>>>>- 编写自定义handler- 请参见KafkaHandler的实现方式
Package: logtools
A log files analysis / filtering framework.logtools encompasses of a few easy-to-use, easy to configure command-line
tools, typically used in conjunction with Apache logs.The idea is to standardize log parsing and filtering using a coherent
configuration methodology and UNIX command-line interface (STDIN input streaming, command-line piping etc.)
so as to create a consistent environment for creating reports, charts and other such
log mining artifacts that are typically employed in a Website context.This software is distributed under the Apache 2.0 license.
Package: log-to-slack
Python log handler that posts to a Slack channel. Posts to the Slack API
usinghttps://github.com/slackapi/python-slack-sdkOriginal work by Mathias Osehttps://github.com/mathiasose/slacker_log_handlerInstallationpipinstalllog-to-slackOptionsapi_key (required)Generate a key athttps://api.slack.com/channel (required)Set which channel id you want to post to, e.g. “C0XXXXXXXXX”.usernameThe username that will post to Slack. Defaults to “Python logger”.icon_urlURL to an image to use as the icon for the logger usericon_emojiemoji to use as the icon. Overrides icon_url. If neither icon_url nor
icon_emoji is set, :heavy_exclamation_mark: will be used.fail_silentDefaults to False.
If your API key is invalid or for some other reason the API call returns an error,
this option will silently ignore the API error.
If you enable this setting,make sure you have another log handlerthat will also handle the same log events,
or they may be lost entirely.Example Python logging handlerThis is how you useslacker_log_handleras a regular Python logging handler.
This example will send a error message to a slack channel.importloggingimportsysfromdatetimeimportdatetimefromlog_to_slackimportSlackLogHandler,NoStacktraceFormatterlogger=logging.getLogger("Daily Report")logger.setLevel(logging.DEBUG)""" Adding slack handler """slack_handler=SlackerLogHandler("xoxb-XXXXX-XXX",# slack api token"C0XXXXXXXXX",# channel id not channel namestack_trace=True,fail_silent=True,)formatter=NoStacktraceFormatter("%(asctime)s-%(name)s-%(levelname)s-%(message)s")slack_handler.setFormatter(formatter)slack_handler.setLevel(logging.ERROR)logger.addHandler(slack_handler)if__name__=="__main__":logger.debug("Debug message to slack!")logger.info("Info message to slack!")logger.warning("Warning message to slack!")try:x=5/0except:logger.exception("Exception message to slack!")# # you can also use the below statement to log error with trace info# logger.error("Error message to slack!", exc_info=True)Slack message formattingThis example use a subclass that will send a formatted message to a slack channel.
Reference:https://api.slack.com/reference/surfaces/formattingclassCustomLogHandler(SlackLogHandler):defbuild_msg(self,record):message="> New message :\n"+record.getMessage()returnmessageLicenseApache 2.0Slacker is also under Apache 2.0.See also:https://api.slack.com/terms-of-service
Package: logToTopo
# README #This idea was born because of a need for a simple tool to generate a network topology out of the information obtained from the output ofshow router interfacecommand.—
## Setup ##### System Libraries
These libraries have been tested under Ubuntu 20.04 and Windows10 with Python3.8.###### Ubuntu`bash pip3 install logToTopo `###### Windows
For Windows users, make sure you have Python and [PIP](https://pip.pypa.io/en/stable/installing/) installed.`bash py-mpip install logToTopo `—
## Usage ##1) Getting data
To obatain the data, use [taskAutom](https://pypi.org/project/taskAutom/) where the plugin uses only theshow router intefacecommand.Example:taskAutom -d data -py plugin -j 2Generate the topology. [logChecker](https://pypi.org/project/logChecker/) will be ran withinlogToTop. This will generate an Excel file with the parsed content. Use that as input.Example:logToTopo -xs sheet_name -folder folder_at_step_1
Package: logtrail
A tool to display bar-chart anywhere.installationuse pip.   $ pip install logtrailusage.   >>> import logtrail
.   >>> logtrail.Logger.info("calling 'logtrail.logger.info'")
.   >>> logtrail.Logger.debug("calling 'logtrail.logger.debug'")
.   >>> logtrail.Logger.warn("calling 'logtrail.logger.warn'")
.   >>> logtrail.Logger.error("calling 'logtrail.logger.error'")
.   >>> logtrail.Logger.i("calling 'logtrail.logger.i'")
.   >>> logtrail.Logger.d("calling 'logtrail.logger.d'")
.   >>> logtrail.Logger.w("calling 'logtrail.logger.w'")
.   >>> logtrail.Logger.e("calling 'logtrail.logger.e'")
Package: logtron
LogtronLogtronis a simple logging library with JSON log formatting.>>>importlogtron>>>logger=logtron.autodiscover()>>>logger.info("hello world"){"timestamp":1598900664859,"message":"hello world","name":"root","level":20,"context":{},"extra":{}}>>>logger.info("extra args",extra={"foo":"bar","count":7}){"timestamp":1598900667704,"message":"extra args","name":"root","level":20,"context":{},"extra":{"foo":"bar","count":7}}>>>Or>>>importlogtron>>>logtron.autodiscover()# Only needs to run once somewhere to configure the root logger<RootLoggerroot(INFO)>>>>>>>importlogging>>>logger=logging.getLogger()>>>logger.info("hello world"){"timestamp":1598900735699,"message":"hello world","name":"root","level":20,"context":{},"extra":{}}>>>logger.info("extra args",extra={"foo":"bar","count":7}){"timestamp":1598900757238,"message":"extra args","name":"root","level":20,"context":{},"extra":{"foo":"bar","count":7}}>>>Logtron allows you to skip all the usual boilerplate when configuring python logging.Logtron will default to a console JSON log formatter that is compatible with popular log aggregators such asLogstash,Fluent Bit, orAWS CloudWatch Logs.Installing Logtron and Supported VersionsLogtron is available on PyPI:$python-mpipinstalllogtronLogtron officially supports Python 2.7 & 3.5+.
Package: logtron-aws
Logtron-AWSLogtron-AWSis a set of AWS-targeted extensions for theLogtronlibrary.importlogtron_awslogger=logtron_aws.autodiscover()logger.info("hello world")Orimportlogtron_awslogtron_aws.autodiscover()# Only needs to run once somewhere to configure the root loggerimportlogginglogger=logging.getLogger()logger.info("hello world")Logtron-AWS provides a set of extensions for theLogtronlibrary to enable features such as:Automated log context discovery using AWS STSLog handler for logging directly to CloudWatch LogsAutomatic log group creationConvention-based log group naming derived from IAM role nameConfigurable log retention periodAutomated background log batch submission to support high frequency loggingConfigureable batch submission time intervalHighly configurable if needed, but has sane defaults out-of-the-boxInstalling Logtron-AWS and Supported VersionsLogtron-AWS is available on PyPI:$python-mpipinstalllogtron-awsLogtron-AWS officially supports Python 2.7 & 3.5+.For more info, check out thedocumentation.
Package: logtube
logtube-pythonlogtube python sdk设置fromsrcimportlogtubelogtube.setup({# 项目名，唯一标识一个项目"project":"eshop-id-service",# 环境名，用以区分不同环境"env":"dev",# 命令行输出"console":{"topics":["*","-debug"]# 输出除了 debug 之外的所有主题},# 文件输出"file":{"topics":["*","-debug"],# 输出除了 debug 之外的所有主题"dir":"logs",# 设置日志输出的根目录"subdirs":{# 设置子目录"xlog":["*","-debug"]# 非调试日志输出到 `xlog` 子目录，其他日志进入 `others` 子目录}}})一般日志输出第一个参数为关键字，可以用于为日志输出打一个关键字，鉴于日志量过大，info 日志必须通过关键字检索fromsrcimportlogtubelogtube.debug("关键字","文本")logtube.info("关键字","文本")logtube.warn("关键字","文本")logtube.error("关键字","文本")logtube.fatal("关键字","文本")Job 工具针对任务类型的日志，Logtube 提供了工具类fromsrcimportlogtubej=logtube.job()j.set_job_name("sleep-job-1m")# 设置任务名，用于区分一类任务j.set_job_id("xxxxx-xxxxx-xxxxx-xxxxx")# 设置任务编号，用于追踪同一个任务j.add_keyword("hello")# 可以增加关键字j.add_extra("key","val")# 可以增加附属键值对j.mark_start()# 标记任务开始# ... 此处为耗时很久的业务代码j.mark_end(True,"任务成功")# 标记任务结束和任务结果，True 为成功，可以额外添加任意纯文本# committer.mark_end(False, "任务失败，因为 xxx.xxxx")许可证Guo Y.K., MIT License
Package: logtweet
LogTweetCreate a tweet based on a #100DaysOfCode log message.UsageThe log url can be configured. The log has to have a format like my log, which you can find athttps://log100days.lpld.io/log.md.My log is based on theoriginal #100DaysOfCode log repo.
This is a markdown log.
Have created a little Flask app that converts my log to an HTML site using themarkdown2package. But other Markdown converters should work similar.Once you have an HTML document withh2day headers andh3sections for "Today's Progress" and "Link(s)", you can point the tool at that URL and generate a Tweet from it.To actually enable the tweeting, you need to create a Twitter developer account and get an API key, API secret, Access Token and Access Token Secret.The tweet will also contain the first link that you define in the "Link(s)" section under today's log.
To save some space the link is shortened.
By default, I use my own link shortener.If you want to, you can also use the Bit.ly service.
Their links might be a bit shorter and provide some engagement/tracking info.
To use the Bitly service, you need to generate an API key through them and add it to the config (see below).OptionsIf you want to create a tweet for a different day than today, you can do so with the--offsetcommand line flag.
The offset is defined in integer days relative to today.
So to generate a tweet for yesterday use-o -1.If you want to suppress the actual tweeting and only see the message in the console, use the--testmodecommand line flag.InstallationI recommendpipxto install python scripts and other tools in isolated virtual environments. This keeps the you platform python clean and you don't have to worry about activating a particular virtual environment to use a tool/script.pipxinstalllogtweetThis way you will have a clean environment and the tool still available on the command line.But if you want to, you should be able to install it withpip install logtweet.ConfigurationYou need a configuration file for the script to work.
Theconfig.inican either be in the current working directory or in~/.config/logtweet/.Because I can not figure out how to define a "post-install hook" that is run bypipI can not generate an example config at the defined location.
You can find an example config onGitHub.In that config file you define the URL where your log can be found and the API keys and access tokens that are needed for Twitter and Bit.ly.DevelopmentInstall withpython-mpipinstall-e".[develop]"This installs the app dependencies as well as tools to develop and distribute the package.
Package: loguetools
loguetoolsloguetoolsmanipulates Korg 'logue'-series synthesizer patch libraries (what Korg calls program collections).It perform a few tasks:Translation of patches from the (original) minilogue to the minilogue xd. See thetranslationsection for a description and limitations.(Forminilogue xd)Bulk extraction of all patches in collections to separate patch files.(Forminilogue,minilogue xdandprologue)Readable display of patch contents.(Forminilogueandminilogue xd)There are two versions:A gui-based version (Windows and MacOS)A set of commandline tools written in Python (3.7 or later)InstallingGUIJust download and run the latest version fromReleases.The files are single-click executables; no need to install. There are Windows (.exe) and macOS (.app.zip) versions.Commandline toolsThese require Python 3.7 or later.
Install with pippipinstallloguetoolsUsingGUISee the wiki.Commandline toolspip will install the script entry points. All tools contain documention for parameters, e.g.translate --helpdump(Forminilogueandminilogue xd)Display the contents of a program or preset pack. -m generates md5 checksums for patches.explode(Forminilogue,minilogue xdandprologue)Bulk extraction of individual patches from libraries.translate(Forminilogue xd)Translate (original) minilogue patches to the minilogue xd.LimitationsThe hardware and routing possibilities for the OG and xd differ in significant ways. The translate tool tries to make sensible choices about setting the xd's EG and LFO hardware to match the original patch but the options are limited.I don't own an original minilogue so I have limited ability to test the translation accuracy. I foundJeff Kistler's minilogue editorvery helpful for checking some of the parameter translations. Korg's documentation has some errors and omissions and I haven't worked out how to translate everything correctly yet; if you notice a problem, let me know or create an issue!These are on my radarNo prologue patch translation yetSmarter use of the xd multi-engine to switch between noise and sub oscillatorKnown problemsI haven't created minilogue patch packs that can be distributed. Thus most unit tests will fail. This may improve in future.LicensesSee LICENSE.txtCode released under the 3-clause BSD license.Application icon "tools by i cons from the Noun Project"Development notesSuggestions and bug reports are welcome. Pull requests will probably be welcome; feel free to create a feature suggestion first to discuss.
Package: logupdate
logupdate.pyLog by overwriting the previous output in the terminal.
Useful for rendering progress bars, animations, etc.
(Port ofsindresorhus/log-updatefrom js to python)InstallJust pip install it, and you're good to go.pipinstalllogupdateUsagefromlogupdateimportlogupdatefromtimeimportsleeplogupdate("Hello, a secret is about to be said to you")sleep(1)logupdate("You can pimp your interactive commands with logupdate")sleep(1)logupdate("Don't forget the secret ;)")sleep(1)logupdate.clear().done()ExamplesYou can find some example in the dedicatedexamplesfolder.APIlogupdate(text, ...): log to stdout (overwriting previous input)logupdate.clear([restore_cursor=None]): Clear previous logged output. This can also restore the cursor if asked.logupdate.done([restore_cursor=None]): Persist the logged output. This enable to start a new "log session" below.
This restores the cursor unless you ask not to.logupdate.stderr(text, ...): log to stderrlogupdate.stderr.clear([restore_cursor=None]): clear stderr.logupdate.stderr.done([restore_cursor=None]):  persist stderr.logupdate.create(stream, [show_cursor=False]): return alogupdatemethod dedicated to log to givenstream.LicenseMIT ©AdrieanKhisbe
Package: loguricorn
loguricornA small package for reroutinggunicornlogs tologuruThis package provides a compatible interface for automatically routinggunicornlogs to the popularlogurulibrary.UsageInstall the package:pipinstallloguricornThen pass the custom interface to gunicorn at runtime:gunicorn--logger-classloguricorn.Loggertests.app:appAll log records will now be routed through the defaultloguru.logger.ConfigurationIt's possible to customize theloguru.loggerinstance beforegunicorninitializes itself. Simply add your changes in a configuration file and pass it
to gunicorn at runtime:importsysfromloguruimportloggerlogger.remove()logger.add(sys.stderr,colorize=True,format="<green>{time}</green> <level>{message}</level>",)gunicorn-cconf.py--logger-classloguricorn.Loggertests.app:appIt's recommended to import any customizations from your main application and
use them in the configuration in order to obtain a consistent log record format
across the entire execution.TestingTesting is done by startinggunicornin a subprocess with the custom logger
enabled and validating that the emitted logs match the expected format.Install dev dependencies:poetryinstallRun test:poetryruntox.ContributingCheck out theissuesfor items needing attention or submit your own and
then:Fork the repoCreate your feature branch (git checkout -b feature/fooBar)Commit your changes (git commit -am 'Add some fooBar')Push to the branch (git push origin feature/fooBar)Create a new Pull Request
Package: loguru-caplog
loguru-caplogСaptures loguru logging output.Source:Making things work with Pytest and caplogUsagefromloguru_caplogimportloguru_caplogascaplog# `some_func` adds two numbers, and logs a warning if the first is < 1deftest_some_func_logs_warning(caplog):assertsome_func(-1,3)==2assert"Oh no!"incaplog.text
Package: loguru-discord
Loguru-DiscordLightweight, easy-to-useDiscordsink forLoguru.UsageConstruct a handler with your preferred options, then add a new sink to Loguru.InstallationSupport is guaranteed only for Python 3.11 or greater.Once this requirement is met, simply install via your package manager of choice.pip install loguru-discordExampleThe following code is a complete example which demonstrates:Constructing a handlerAdding the handler as a Loguru sinkCatching an exception and firing a logfromloguruimportloggerfromloguru_discordimportDiscordSinklogger.add(DiscordSink("https://discord.com/api/webhooks/00000000/XXXXXXXX"))try:value:float=1/0exceptExceptionase:logger.opt(exception=e).error("Lorem ipsum dolor sit amet")CustomizationUpon constructing your handler, the following optional customizations are available via keyword arguments.Username: Username to use for the Discord Webhook message.Avatar: Image URL to use for the Discord Webhook message.Embed: Toggle whether to use plain codeblock formatting or rich embeds.Suppress: Prevent specific Exception types from being sent to Discord.ReleasesLoguru-Discord followsSemantic Versioningfor tagging releases of the project.ContributingBug fixes and optimizations are always welcome. SeeCONTRIBUTING.mdfor details.
Package: loguru-logger-lite
loguru_logger_liteThis simple logger is built on top ofloguruto make a quick setup for basic
logging.The logger has four transports (called "sinks" here, same as in loguru):stdoutstderrfilekafkaThe standard sinks (stdout, stderr and file) are configured with the same arguments as in loguru (see "add" method
inloguru documentation).Installationpip install loguru-logger-liteUsageget_default_logger() methodThe basic logger can be created usingget_default_loggermethod. Theget_default_loggermethod returns
preconfigured loguru logger withstdoutandstderrsinks. All messages whoselevelis less thanERRORare sent tostdoutwhile messages whoselevelisERRORor above are sent tostderr.fromloguru_logger_liteimportLoggerlogger=Logger.get_default_logger()logger.info('Test log message')The output will be like this:MODULE: example | COMPONENT: __main__ | PID: 230552 | INFO | 2022-04-08T19:59:36.290220-0400 | Test log messageNOTE:The above log message format will also be a default format if theformatoption is not provided in sink configuration.get_logger(sinks) methodTheget_loggermethod is used to create a logger with a custom set of sinks. This method expects a list ofSinkobjects and returns a loguru logger with the configured sinks.fromloguru_logger_liteimportLogger,LogLevels,Sink,Sinks,\KafkaSinkOptions,FileSinkOptionslogger=Logger.get_logger([Sink(name=Sinks.FILE,opts=FileSinkOptions(path='test.log',level=LogLevels.DEBUG)),Sink(name=Sinks.KAFKA,opts=KafkaSinkOptions(level=LogLevels.TRACE,bootstrap_servers=['localhost:9092'],sink_topic='log_topic'))])logger.info('Test log message')NOTE:When usingfileandkafkasinks, the output will be a json withtextandrecordroot items.
Thetextitem is formatted log message andrecordis loguru Record dictionary (seeloguru documentation).Kafka sinkThe kafka sink, along with the basic loguru options, has additional parameters for kafka producer:bootstrap_servers - a list of strings of kafka brokers addresses.producer_config - kafka producer configuration (seekafka-python documentation).sink_topic - a kafka topic name where to send log messages.get_kafka_sink(options) methodThekafkasink can be used standalone with existing loguru logger:fromloguruimportloggerfromloguru_logger_liteimportLogger,LogLevels,KafkaSinkOptionskafka_sink=Logger.get_kafka_sink(options=KafkaSinkOptions(level=LogLevels.TRACE,bootstrap_servers=['localhost:9092'],sink_topic='log_topic'))logger.add(kafka_sink)logger.info('Test log message')LICENSEMITAUTHOR:Dmitry Amanov
Package: loguru-logging-intercept
Loguru Logging InterceptCode to integrateLoguruwith Python's standardloggingmoduleLoguruis a great alternative logging library for
Python. However, if you use (potentially external) code that already integrates with
Python's default logger, you'll get a combination of the two logging styles. This code
provides a function that sets up an intercept handler to route calls to Python's
defaultloggingmodule to Loguru.UsageBefore calls that use Python's defaultloggingmodule, call the providedsetup_loguru_logging_intercept()as shown below:importloggingfromloguru_logging_interceptimportsetup_loguru_logging_interceptdefmain():setup_loguru_logging_intercept(level=logging.DEBUG,modules=("foo","foo.bar","foo.baz"))# Can now call functions from foo that use getLogger(__name__)...InstallationInstall viapip:pip3installloguru-logging-intercept