Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
flog.py [TODO1]
10-31-2017, 10:26 AM
Post: #1
flog.py [TODO1]
A Python library implements flog http://tab.d-thinker.org/showthread.php?tid=8242 .

Under cod://utilib/flog.py

Functions:

flog(msg) # print the message and behave in the way (respect the same environment variables, and etc.) as http://tab.d-thinker.org/showthread.php?tid=8242 .

An usage example (from drep-service):

Code:
# flog environment
os.environ['flog_also_stderr'] = "True"
os.environ['progname'] = "drep-service"
os.environ['flog_enable_timestamp'] = 'True'

utilib = '/thinker/local/forest/util/utilib'
sys.path.insert(0, utilib)
from flog import flog

...

flog("To start drep-service daemon.")

pseudocode
Quote:if environment variable "flog_also_stderr" == "True":
.. write msg to stdout
if log_pfn is None:
.. try to set log_pfn from environment variables
.. if failed to set log_pfn:
.... shut error then exit
if log_pfn is not None:
.. validate log_pfn and write $msg to log_pfn
call `mayday add msg` if msg start with "panic" (case insensitive"
-----
20180202/rayluk: Bug fix for flog_also_stderr
Quote this message in a reply
11-21-2017, 11:27 AM (This post was last modified: 11-21-2017 11:28 AM by lingu.)
Post: #2
RE: flog.py
(10-31-2017 10:26 AM)zma Wrote:  A Python library implements flog http://tab.d-thinker.org/newthread.php?fid=480 .

flog(msg) # print the message and behave in the way as http://tab.d-thinker.org/showthread.php?tid=8242 .

Great to have this. Pls list some key info like the code location and usage info like how to include the lib. I slightly prefer to making it a class and changing the name to be Flog.
Find all posts by this user
Quote this message in a reply
11-21-2017, 11:55 AM
Post: #3
RE: flog.py
(11-21-2017 11:27 AM)lingu Wrote:  Pls list some key info like the code location and usage info like how to include the lib. I slightly prefer to making it a class and changing the name to be Flog.

Revised the main post a little bit with an example.

A class may be better for Python as it can do initialization in its initializer. But it will look a little different from its Bash counterpart. I think we may do that later when we add more functions to the Python library.
Quote this message in a reply
02-02-2018, 11:16 AM
Post: #4
RE: flog.py [TODO1]
@zma

The currently pseudocode is
Quote:if log_pfn is None:
.. try to set log_pfn from environment variables
.. if failed to set log_pfn:
.... shut error then exit
if log_pfn is not None:
.. validate log_pfn and write $msg to log_pfn
.. if environment variable "flog_also_stderr" == "True":
.... write msg to stdout


Currenly if flog_also_stderr is True but log_pfn is None, no message would be writing to stderr.

I think this is a bug and I suggest fixing it by

Quote:if environment variable "flog_also_stderr" == "True":
.. write msg to stdout

if log_pfn is None:
.. try to set log_pfn from environment variables
.. if failed to set log_pfn:
.... shut error then exit
if log_pfn is not None:
.. validate log_pfn and write $msg to log_pfn
.. if environment variable "flog_also_stderr" == "True":
.... write msg to stdout
Find all posts by this user
Quote this message in a reply
02-02-2018, 11:22 AM
Post: #5
RE: flog.py [TODO1]
Quote:if environment variable "flog_also_stderr" == "True":
.. write msg to stdout


should write to stderr.
Find all posts by this user
Quote this message in a reply
02-02-2018, 11:24 AM
Post: #6
RE: flog.py [TODO1]
(02-02-2018 11:22 AM)lingu Wrote:  
Quote:if environment variable "flog_also_stderr" == "True":
.. write msg to stdout


should write to stderr.

sorry, it is a typo. it should be stderr.
Find all posts by this user
Quote this message in a reply
02-02-2018, 11:26 AM
Post: #7
RE: flog.py [TODO1]
(02-02-2018 11:16 AM)rayluk Wrote:  @zma

The currently pseudocode is
Quote:if log_pfn is None:
.. try to set log_pfn from environment variables
.. if failed to set log_pfn:
.... shut error then exit
if log_pfn is not None:
.. validate log_pfn and write $msg to log_pfn
.. if environment variable "flog_also_stderr" == "True":
.... write msg to stdout


Currenly if flog_also_stderr is True but log_pfn is None, no message would be writing to stderr.

I think this is a bug and I suggest fixing it by

Quote:if environment variable "flog_also_stderr" == "True":
.. write msg to stdout

if log_pfn is None:
.. try to set log_pfn from environment variables
.. if failed to set log_pfn:
.... shut error then exit
if log_pfn is not None:
.. validate log_pfn and write $msg to log_pfn
.. if environment variable "flog_also_stderr" == "True":
.... write msg to stdout

The logic follows http://tab.d-thinker.org/showthread.php?tid=8242 .

Your proposal looks good except:

'write msg to stdout' -> 'write msg to stderr'

Please update both logging library's logic.
Quote this message in a reply
06-01-2018, 03:26 PM
Post: #8
RE: flog.py [TODO1]
(10-31-2017 10:26 AM)zma Wrote:  TODO: implement mayday support.

I am going to add mayday support for flog.
Quote this message in a reply
Post Reply 


Forum Jump: