Comments (4)
Re #124 (comment):
The verbosity of logs before flags are parsed (via absl.app.run(main)
) is WARNING
, so only WARNING/ERROR/CRITICAL logs are logged. After absl.app.run(main)
, the verbosity is INFO
. Example:
$ cat t.py
from absl import app
from absl import logging
# Logging before flags are parsed (or app.run is called)
logging.info("info before")
logging.warning("warning before")
def main(argv):
del argv # Unused.
# Logging after flags are parsed from app.run(main)
logging.info("info after")
logging.warning("warning after")
if __name__ == "__main__":
app.run(main)
$ python t.py
WARNING:absl:warning before
I1202 20:37:36.482917 4517098944 t.py:13] info after
W1202 20:37:36.483098 4517098944 t.py:14] warning after
Re #124 (comment):
Again, this must be done inside the main
function, otherwise the format always defaults to the standard logging module:
$ cat t.py
import logging
from absl import app
from absl import logging as logger
def main(argv):
del argv # Unused.
fmt = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
formatter = logging.Formatter(fmt)
logger.get_absl_handler().setFormatter(formatter)
logger.set_verbosity("debug")
a = 3434
logger.info("{}".format(a))
if __name__ == "__main__":
app.run(main)
$ python t.py
[INFO 2019-12-02 20:40:29,394 t.py:15] 3434
from abseil-py.
The log format is fixed (and includes the file / line number) unless you override the formatter. Are you asking how to change the format so it doesn't include the line numbers?
Examples of logs:
abseil-py/absl/logging/tests/logging_functional_test.py
Lines 56 to 69 in 62b0407
from abseil-py.
Simply python script does not print anything, why?:
[10:44:27] fagjin:~ $ python a.py
[10:44:29] fagjin:~ $ cat a.py
from absl import logging as logger
a = 3434
logger.info('{}'.format(a))
from abseil-py.
I am really confusing right now:
from absl import logging as logger
import logging
fmt = '[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s'
formatter = logging.Formatter(fmt)
logger.get_absl_handler().setFormatter(formatter)
logger.set_verbosity('debug')
a = 3434
logger.info('{}'.format(a))
Doesn't applied format...........
from abseil-py.
Related Issues (20)
- avoid DuplicateFlagError during debugging HOT 3
- Logging disappeared after switching from app.run(main) to main() HOT 5
- 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 HOT 1
- Absl Installation on Virtual Environment HOT 1
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.