Comments (12)
I have to say that even that this lib comes from Google guys, is not UX friendly. Guys, please add some examples how to use it! I'm working with ml-metadata and they are using your crappy stuff and I have no idea how to enabling logging. And please, add the example with absl.run()! Only thanks to @eshijia I'm able to see what's up not you, creators.
from abseil-py.
Without using app.run
, the default verbosity is WARNING
, i.e. only WARNING
and more severe logs are logged, that's why your info/debug
logs are not written. If you call logging.warning('warning')
, it should be there.
You can e.g. call logging.set_verbosity(logging.INFO)
to make the verbosity INFO
.
When using app.run
, the default is INFO
. The the reason why without app.run
the default is WARNING
: it matches standard logging's behavior, when you haven't configured logging, only WARNING
and more severe logs are written to stderr.
Hope it helps.
from abseil-py.
I have solved the problem. The key point is that if you do not use app.run()
, you need to add logging.use_absl_handler()
at the beginning of the code.
This code does not work:
import os
import absl
from absl import logging
if not os.path.exists('./'):
os.makedirs('./')
logging.get_absl_handler().use_absl_log_file('absl_logging', './')
absl.flags.FLAGS.mark_as_parsed()
logging.set_verbosity(logging.INFO)
logging.info('test')
But this code works:
import os
import absl
from absl import logging
logging.use_absl_handler()
if not os.path.exists('./'):
os.makedirs('./')
logging.get_absl_handler().use_absl_log_file('absl_logging', './')
absl.flags.FLAGS.mark_as_parsed()
logging.set_verbosity(logging.INFO)
logging.info('test')
from abseil-py.
The absl.logging
package defines a few command line flags from absl.flags
, so that it has special logic to check whether flags are parsed or not. For example, you can control the log directory via the --log_dir
flag define here
Flag parsing is typically done by calling absl.app.run
, and your server's main could be modified to use it.
But if you do not want command line flags parsing (i.e. always use the default flag values), you can try to call absl.flags.FLAGS.mark_as_parsed()
, after that, logs should go to files.
Let me know if this works for you.
from abseil-py.
@stefanistrate This is only mentioned in the --verbosity
flag's help string.
from abseil-py.
Is this your exact code? Note that logs before the absl.app.run(main)
call are logged to stderr (only WARN and more severe levels, others are not logged).
Like #83 (comment), you need to call use_absl_log_file
inside your main
function.
from abseil-py.
yes, that is my code to test.
I got the answer, log will write to file from the function after calling absl.app.run(<function>)
is there any way to write in file without calling absl.app.run(<function>)
because for server side service, sometimes it is required
from abseil-py.
I have tried with following code, but it does not write into files
import os
import absl
from absl import logging
if not os.path.exists('./'):
os.makedirs('./')
logging.get_absl_handler().use_absl_log_file('absl_logging', './')
absl.flags.FLAGS.mark_as_parsed()
logging.info('test')
logging.debug('test debug')
from abseil-py.
Thank you @yilei
Now it works, my code is
import os
import absl
from absl import logging
if not os.path.exists('./'):
os.makedirs('./')
logging.get_absl_handler().use_absl_log_file('absl_logging', './')
absl.flags.FLAGS.mark_as_parsed()
logging.set_verbosity(logging.INFO)
logging.info('test')
from abseil-py.
Without using
app.run
, the default verbosity isWARNING
, i.e. onlyWARNING
and more severe logs are logged, that's why yourinfo/debug
logs are not written. If you calllogging.warning('warning')
, it should be there.You can e.g. call
logging.set_verbosity(logging.INFO)
to make the verbosityINFO
.When using
app.run
, the default isINFO
. The the reason why withoutapp.run
the default isWARNING
: it matches standard logging's behavior, when you haven't configured logging, onlyWARNING
and more severe logs are written to stderr.Hope it helps.
Hi @yilei! Is this behaviour referenced anywhere in the abseil documentation? Thanks!
from abseil-py.
Thank you @yilei
Now it works, my code is
import os import absl from absl import logging if not os.path.exists('./'): os.makedirs('./') logging.get_absl_handler().use_absl_log_file('absl_logging', './') absl.flags.FLAGS.mark_as_parsed() logging.set_verbosity(logging.INFO) logging.info('test')
I tried that code, and it did not work. There was only INFO:absl:test
in the command window. I can't see anything in the file.
from abseil-py.
@eshijia do you have a minimal but complete reproducible example? snippets aren't great since how/when they are executed is important.
from abseil-py.
Related Issues (20)
- 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
- 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
- Python version of absl::Status
- pip install mypy mypy absl HOT 1
- Fin HOT 3
- absl.testing not compatbile with python unittest discover
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.