Comments (5)
Yes, this is caused by verbosity.
The default verbosity when not using app.run(main)
is WARNING
, matching the standard logging
behavior. absl
sets its own default verbosity to INFO
here, which isn't called by your code.
So you can either set the --verbosity
flag or the root logger's verbosity explicitly.
That being said, if you only need to run main()
instead of app.run(main)
because you want to use argparse
, you can use the absl.flags.argparse_flags.ArgumentParser
drop-in replacement together with app.run
like this:
def parse_flags(argv):
parser = absl.flags.argparse_flags.ArgumentParser(...)
# Add your own argparse flags, this parser understands the flags defined using `absl.flags`.
return parser.parse_args(argv[1:])
if __name__ == "__main__":
app.run(main, flags_parser=parse_flags)
Hope this helps.
from abseil-py.
could you please provide a minimal repro with a full .py
file? there are many nuances how and when the library is imported and the functions are called, that can result in different behaviors. so a full minimal example can help here.
from abseil-py.
# !/bin/env python3
import argparse
import logging
import sys
from absl import app, flags
import absl.logging
absl.logging.use_absl_handler()
logger = logging.getLogger('test')
logger.setLevel(logging.DEBUG)
def main(args=None):
if args is None:
args = sys.argv
unparsed = flags.FLAGS(args, known_only=True) # Let absl.flags parse known flags first
parser = argparse.ArgumentParser()
args = parser.parse_args(unparsed[1:]) # Let argparse parse the rest of flags
# args = parser.parse_args(args[1:])
print('print: Finish parsing')
logging.info('logging: Finish parsing')
absl.logging.info('absl logging: Finish parsing')
logger.info('logger: Finish parsing')
if __name__ == "__main__":
# app.run(main)
main()
Thanks! This script should be able to reproduce the issue.
print: Finish parsing
I0718 13:39:39.888040 140067313977152 main.py:23] logging: Finish parsing
I0718 13:39:39.888194 140067313977152 main.py:24] absl logging: Finish parsing
I0718 13:39:39.888281 140067313977152 main.py:25] logger: Finish parsing
print: Finish parsing
I0718 13:41:15.937640 140668410611520 main.py:25] logger: Finish parsing
from abseil-py.
I think it is related to verbosity, but thought absl.logging.use_absl_handler()
already handled it in _update_logging_levels()
?
from abseil-py.
Thanks!
from abseil-py.
Related Issues (20)
- argparse_flags.ArgumentParser does not accept --flagfile if there are no flags HOT 3
- Accessing C++ flags from Python HOT 1
- Use Default Loggers/Handlers with Abseil `app.run` HOT 4
- DEFINE_enum supports Enum? HOT 3
- Fails to install absl-py in PY3.11 in windows10 HOT 3
- absltest.main() dosen't work on Windows, but work on MacOs HOT 2
- AbslTest.assertSameStructure() doesn't work with TestCase.addTypeEqualityFunc()
- Absl installation problem HOT 6
- typo
- If I use use_absl_log_file, I will get two files with the same content, what can I do to generate just one file? HOT 2
- Permission issue for 1.4.0 HOT 1
- Test cases should be parameterizable based on command-line flags (and other things) HOT 1
- Error during installation of version HOT 1
- Unintended behaviour in absltest.py
- absl.logging possibly causing PyCharm debugger to crash during tests HOT 1
- Add MODULE.bazel HOT 9
- No pyi files from pip package
- Absl Installation on Virtual Environment HOT 1
- class ArgumentParser(Generic[_T], metaclass=_ArgumentParserCache): TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abseil-py.