Git Product home page Git Product logo

Comments (12)

wpopielarski avatar wpopielarski commented on May 13, 2024 7

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.

yilei avatar yilei commented on May 13, 2024 4

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.

eshijia avatar eshijia commented on May 13, 2024 4

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.

yilei avatar yilei commented on May 13, 2024 2

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.

yilei avatar yilei commented on May 13, 2024 2

@stefanistrate This is only mentioned in the --verbosity flag's help string.

from abseil-py.

yilei avatar yilei commented on May 13, 2024 1

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.

akter-sust avatar akter-sust commented on May 13, 2024

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.

akter-sust avatar akter-sust commented on May 13, 2024

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.

akter-sust avatar akter-sust commented on May 13, 2024

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.

stefanistrate avatar stefanistrate commented on May 13, 2024

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.

Hi @yilei! Is this behaviour referenced anywhere in the abseil documentation? Thanks!

from abseil-py.

eshijia avatar eshijia commented on May 13, 2024

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.

yilei avatar yilei commented on May 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.