mergifyio / daiquiri Goto Github PK
View Code? Open in Web Editor NEWPython library to easily setup basic logging functionality
License: Apache License 2.0
Python library to easily setup basic logging functionality
License: Apache License 2.0
Something like:
daiquiri.setup(outputs=('syslog', 'stderr', 'journal'))
This is an idea coming from gamesbook on: https://julien.danjou.info/blog/python-logging-easy-with-daiquiri#comment-3404269674
I'm stuck using Windows :(for work).
The ANSI escape character sequences are printed in Windows cmd.exe when outputting to stderr.
#test.py
import daiquiri
daiquiri.setup()
logger = daiquiri.getLogger()
logger.error("something went wrong")
I can workaround using colorama (the library that IPython uses).
#test_colour.py
import colorama
colorama.init()
import daiquiri
daiquiri.setup()
logger = daiquiri.getLogger()
logger.error("something went wrong")
Colours also work when script is run using ipython as colorama is being used automatically (i.e. ipython test.py
).
Is there a way to tell daiquiri not to output colour escape chars?
Even better ; ), would you consider using colorama as an optional extra?
It would be nice to keep PyPI releases and git tags in sync :)
Using this syntax:
import daiquiri, logging
daiquiri.setup()
z = daiquiri.getLogger()
z.warning('abcde')
I get colored output, but the level and message are colored the same. I can
work around it like this:
import daiquiri, logging
daiquiri.setup(outputs=(daiquiri.output.Stream(
formatter=daiquiri.formatter.ColorFormatter(
fmt="%(color)s%(levelname)s%(color_stop)s %(message)s"
)
),))
z = daiquiri.getLogger()
z.warning('abcde')
but I think it would be better to contrast the message from the level. Other
projects color the level only:
from logzero import logger
logger.warning('abcde')
or color the message only:
import coloredlogs, logging
coloredlogs.install()
logging.warning('abcde')
See DEFAULT_LOG_LEVELS in oslo.log
Hello, the library removes all existing handlers, and that is causing conflicts with third-party libraries, for example click.
When click application is started, i setup logging, and if there are any exceptions in an application, then it just shutdowns silently, because it can not report about crash.
* QA Notice: setuptools warnings detected:
*
* Usage of dash-separated 'author-email' will not be supported in future versions. Please use the underscore name 'author_email' instead
* Usage of dash-separated 'home-page' will not be supported in future versions. Please use the underscore name 'home_page' instead
Could you move the buildsystem to PEP517?
I have a HTTP request that logs using logger.info(...)
in three places (no ifs, three lines should always be logged)
I have a datadog output setup like this:
daiquiri.setup(
outputs=[
daiquiri.output.Datadog(
hostname=os.environ["LOGGING_HOST"], port=int(os.environ["LOGGING_PORT"])
),
daiquiri.output.Stream(sys.stdout),
],
level=logging.INFO,
)
logger = daiquiri.getLogger(__name__)
the last logger.info(...)
always makes it way do datadog
the first two sometimes do but most of the time don't
Now that my PR has been merged in I'd like to use it in my project through pip :)
http://logzero.readthedocs.io/
Great work, by the way.
In my app I create a logger using:
def create_logger(log_path, log_name, log_level=logging.INFO):
daiquiri.setup(
level=log_level,
outputs=(daiquiri.output.File(
directory=log_path, program_name=log_name),
daiquiri.output.STDOUT,))
return daiquiri.getLogger(program_name=log_name)
When I look at the console, I see logs for my app and also for all the packages that I use in my app, before when I used the default logger I didn't see those messages.
Can I turn it off, so that in my log I will only see my app logs?
Hey,
I really love how you can just do daiquiri.setup()
and then just Move On. However, as soon as I would like to change the formatting (ie. drop the process ID and log name as it's always the same) then I end up having something relatively ugly:
formatter = daiquiri.formatter.ColorExtrasFormatter(
fmt="%(color)s%(levelname).1s: %(message)s%(color_stop)s"
)
daiquiri.setup(outputs=(
daiquiri.output.Stream(formatter=formatter),
))
Any ideas on making this rather common use-case a bit cleaner? (Perhaps a magic kwarg to daiquiri.setup()
like fmt="..."
?
I don't think daiquiri provide a ready solution for multiprocessing context.
ref: https://stackoverflow.com/questions/641420/how-should-i-log-while-using-multiprocessing-in-python
ref: https://github.com/jruere/multiprocessing-logging
I'm not sure if I'm doing something wrong, but the following two piece of code generate a exception. I tested versions 1.5.0, 1.6.0 and then 2.1.0 in a clean venv.
daiquiri.setup(level=logging.INFO, outputs=("stdout", "journal"))
logger = daiquiri.getLogger("test", FOO="bar")
logger.info("it works")
daiquiri.setup(level=logging.INFO, outputs=("stdout", "journal"))
logger = daiquiri.getLogger("test")
logger.info("it works", FOO="bar")
The backtrace results in line 92, in emit:
for k, v in record._daiquiri_extra_keys:
ValueError: too many values to unpack (expected 2)
From what I could see, record._daiquiri_extra_keys
was just a tuple of "FOO", without a value, so not sure what's going on there.
Python 3.12 introduced a new reserved attribute taskName
, there's a patch in madzak/python-json-logger#188
This attribute could be discarded to support both patched and unpatched versions, see: jupyter/jupyter_events#100
Can this module configure a rotating file log?
logzero does it: http://logzero.readthedocs.io/en/latest/index.html?highlight=rotating#i-logzero-logfile
hi,
using Python 3 syslog :
>>> import syslog
>>> syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_LOCAL7)
>>> syslog.syslog("test")
and logs :
$ tail -f /var/log/local7.log
...
Jul 5 15:12:50 cloud-nimbus02-prp python3.4[6636]: test
i try your library using the syslog output :
>>> import daiquiri
>>> daiquiri.setup(outputs=(
... daiquiri.output.Syslog("cmdb", "LOG_LOCAL7"),
... daiquiri.output.STDERR,
... ))
>>> logger = daiquiri.getLogger("foo")
>>> logger.info("daiquiri")
There is no log in the local7.log file. Any idea ?
I have the following code:
SH_LOG = daiquiri.getLogger('sh')
SH_LOG.setLevel('WARNING')
This results in a traceback:
Traceback (most recent call last):
File "/home/lars/env/common/bin/interesting", line 6, in <module>
from interesting.main import main
File "/home/lars/projects/interesting/interesting/main.py", line 24, in <module>
SH_LOG = daiquiri.getLogger('sh')
AttributeError: 'KeywordArgumentAdapter' object has no attribute 'setLevel'
If I replace daiquiri
with logging
everything works fine.
Running Python 2.7.13.
Daiquiri would also be great to use in Jupyter.
Unfortunately, it seems in Jupyter one usually has to enforce TTY mode in order to make color work.
There does not seem to be an option for that in daiquiri?
The root logger and the root logger of the app should be able to be set differently via setup
. It's possible one wants to have only warning message for the root logger and the info/debug one for the app being ran.
Issue found and reported here: https://www.reddit.com/r/Python/comments/6lei80/easy_python_logging_with_daiquiri/
Due to default value of setup method for logging (level=logging.WARNING), all examples in the examples directory do not actually print out log statements when run. To address fix, either examples need to include setting daiquiri.setup(level=logging.INFO), or log.info statements should be changed to log.warning.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.