Move import logging to line 1

move setup_logging() and all logger lines stuff to line 2

then import rest

let's see if it helps.

On 7 December 2015 at 17:50, Anil Jangam <[email protected]> wrote:

> Here is the exact outline of the python code I have on my side.
>
>   1 import sys
>   2 import os
>   3 import urllib2
>   4 import urllib
>   5 import simjsonrpc as jsonrpc
>   6 import json
>   7 import re
>   8
>   9 from simjsonrpc import HttpRequest
>  10 from settings import *
>  11 from templates import *
>  12 from http_defs import *
>  13 import time
>  14
>  15 import logging
>  16 import logging.config
>  17 import yaml
>  18
>  19 from unix_sock_http import *
>  20
>  21 # logging setup
>  22 log_cfg_path = "/script/jsonrpc_logging.yaml"
>  23
>  24 def setup_logging(default_path='jsonrpc_logging.yaml',
>  25                               default_level=logging.INFO,
>  26                               env_key='JSONRPC_LOG_CFG'):
>  27     """Setup logging configuration
>  28
>  29     """
>  30     path = default_path
>  31     value = os.getenv(env_key, None)
>  32     if value:
>  33         path = value
>  34     if os.path.exists(path):
>  35         with open(path, 'rt') as f:
>  36             config = yaml.load(f.read())
>  37         logging.config.dictConfig(config)
>  38     else:
>  39         logging.basicConfig(level = default_level)
>  40     logging.Formatter('%(asctime)s - %(message)s')
>  41
>  42 # Get to the real business
>  43 logger = logging.getLogger(__name__)
>  44 setup_logging(default_path = log_cfg_path)
>  45 logger.debug("logger initialized...")
>  46
>  47
>  48 def parse_args(r, *args, **kwargs):
>  49     <... snip ...>
>  50       # There are bunch of functions between till "def application",
> which uses logger.
>  51     <... snip ...>
>  52
>  53 def application(environ, start_response):
>  54     '''
>  55     uwsgi entry point
>  56     '''
>  57
>  58     http_method = ''
>  59     try:
>  60         http_method = environ["REQUEST_METHOD"]
>  61     except KeyError:
>  62         start_response("{0}".format(HTTP_ERROR[405]),
>  63                        [(CONTENT_TYPE_KEY,
> CONTENT_TYPE_VALUE_JSONRPC)])
>  64         return []
>  65
>  66     if "aaaLogin" not in request and "aaaRefresh" not in request:
>  67         logger.debug("{0} <=========: {1}".format(src_ip,
> "".join(result.split())))
>  68     else:
>  69         logger.debug("{0} <=========: {1}".format(src_ip, "aaa method.
> Details hidden"))
>  70
>  71    # I've snipped some of the code below.
>
>
> On Mon, Dec 7, 2015 at 2:37 PM, Mikko Ohtamaa <[email protected]>
> wrote:
>
>> Please show to full code flow of
>>
>> - starting application, your main entry point
>>
>> - how and when it calls setup_loggers()
>>
>> - how and when it imports modules
>>
>> If necessary step it through yourself in a debugger (pdb).
>>
>> On 7 December 2015 at 17:35, Anil Jangam <[email protected]> wrote:
>>
>>> Hi Mikko,
>>>
>>> Yes, I did see that. However I believe that scenario talks about
>>> multiple modules creating the logger. In my case, I just have one python
>>> file/module, which is initializing the logger. I also tried pushing the
>>> importing the two imports (1. import logging, and 2. import logging.config)
>>> as a very last imports in the sequence but not successful.
>>>
>>> I am having the below imports in my code. I am relatively new to python
>>> and complete to uwsgi. Can you suggest what should be the correct sequence?
>>> Do I have to initialize the logger inside application() function, which is
>>> starting point of uwsgi?
>>>
>>> import sys
>>> import os
>>> import urllib2
>>> import urllib
>>> import simjsonrpc as jsonrpc
>>> import json
>>> import re
>>>
>>> from simjsonrpc import HttpRequest
>>> from settings import *
>>> from templates import *
>>> from http_defs import *
>>> import time
>>>
>>> import logging
>>> import logging.config
>>> import yaml
>>>
>>> from unix_sock_http import *
>>>
>>>
>>> /anil.
>>>
>>>
>>>
>>> On Mon, Dec 7, 2015 at 2:28 PM, Mikko Ohtamaa <[email protected]>
>>> wrote:
>>>
>>>> Hi Anil,
>>>>
>>>> Did you spot my SO.com comment on the matter?
>>>>
>>>> Thanks,
>>>> Mikko
>>>>
>>>> On 7 December 2015 at 17:27, Anil Jangam <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> This is a resend of my previous post.
>>>>>
>>>>> I need to understand how python logger works under uwsgi environment?
>>>>> I have a python program used as a --wsgi-file. This python
>>>>> application internally initializes a logging.Logger instance with a 
>>>>> certain
>>>>> log config.
>>>>>
>>>>> What is happening is for the first time uwsgi process is started, it
>>>>> does not pick up the correct time format for log message as per the log
>>>>> config; however, when I restart the uwsgi process, it picks the configured
>>>>> time format.
>>>>>
>>>>> I tried few options outside the uwsgi process context but nothing
>>>>> helped. I need to know if there is anything within uwsgi framework or
>>>>> environment which influences the python logger time format?
>>>>>
>>>>> Thanks,
>>>>> /anil.
>>>>>
>>>>>
>>>>>
>>>>> On Fri, Dec 4, 2015 at 4:21 PM, Anil Jangam <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I have a python module running behind the uwsgi process launched as
>>>>>> below. I have a python logger being initialized inside the json_rpc.py
>>>>>> file.
>>>>>>
>>>>>> uwsgi -M --processes 1 --threads 2 -s /tmp/uwsgi.sock 
>>>>>> --wsgi-file=/proj/req_proc.py --daemonize /dev/null
>>>>>>
>>>>>>
>>>>>> The issue is whenever the uwsgi process is started for the first
>>>>>> time, the logger time format is not taking effect as per the log
>>>>>> configuration. However, on the second attempt, when I restart the uwsgi
>>>>>> process (after doing a kill -9 on uwsgi), the logger time format comes 
>>>>>> out
>>>>>> correct.
>>>>>>
>>>>>> I am not able to understand why this is happening and if there is
>>>>>> anything wring between python logger and uwsgi framework. Can someone
>>>>>> please comment on this?
>>>>>>
>>>>>> I posted similar question to stackoverflow and got a comment
>>>>>> indicating something wrong between the two.
>>>>>>
>>>>>> http://stackoverflow.com/questions/34053273/python-logger-not-picking-up-the-configure-time-format
>>>>>>
>>>>>> Thanks,
>>>>>> /anil.
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> uWSGI mailing list
>>>>> [email protected]
>>>>> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Mikko Ohtamaa
>>>> http://opensourcehacker.com
>>>> http://twitter.com/moo9000
>>>>
>>>>
>>>> _______________________________________________
>>>> uWSGI mailing list
>>>> [email protected]
>>>> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>>>>
>>>>
>>>
>>> _______________________________________________
>>> uWSGI mailing list
>>> [email protected]
>>> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>>>
>>>
>>
>>
>> --
>> Mikko Ohtamaa
>> http://opensourcehacker.com
>> http://twitter.com/moo9000
>>
>>
>> _______________________________________________
>> uWSGI mailing list
>> [email protected]
>> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>>
>>
>
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>
>


-- 
Mikko Ohtamaa
http://opensourcehacker.com
http://twitter.com/moo9000
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to