<menuitem id="4yhqd"><strong id="4yhqd"></strong></menuitem>

    <tbody id="4yhqd"></tbody>

      <option id="4yhqd"></option>
      1. <menuitem id="4yhqd"><dfn id="4yhqd"></dfn></menuitem>
      2. Support Logging setup

        Python Syslog Logging

        Python Syslog

        You can send Python logs over syslog using the SyslogHandler. Your syslog daemon such as rsyslog will receive these events and then forward them to Loggly. The advantage of Rsyslog is that it can send TCP events without blocking your application, can optionally encrypt the data, and even queue data to add robustness to network failure. Use this approach for the best reliability and performance on server-side apps. We will automactically parse the JSON formatted logs as JSON fields.

        Python Syslog Setup


        1. Configure Syslog Daemon

        If you haven’t already, run our automatic Configure-Syslog script below to setup rsyslog. Alternatively, you can Manually Configure Rsyslog or Syslog-ng.

        curl -O http://www.yousuo.net.cn/install/configure-linux.sh
        sudo bash configure-linux.sh -a SUBDOMAIN -u USERNAME
        

        Replace:

        • SUBDOMAIN: your account subdomain that you created when you signed up for Loggly
        • USERNAME: your Loggly username

        2. Configure Syslog Daemon for UDP Input

        Open rsyslog’s configuration file

        sudo vim /etc/rsyslog.conf
        

        Uncomment these lines to accept UDP messages on the default port 514.

        $ModLoad imudp
        $UDPServerRun 514
        
        Python Logs

        Restart the rsyslog service so the changes take effect

        sudo service rsyslog restart
        

        3. Configure SyslogHandler

        Add SyslogHandler to your source file

        import logging
        import logging.handlers
        
        logger = logging.getLogger('myLogger')
        logger.setLevel(logging.INFO)
        
        #add handler to the logger
        handler = logging.handlers.SysLogHandler('/dev/log')
        
        #add formatter to the handler
        formatter = logging.Formatter('Python: { "loggerName":"%(name)s", "timestamp":"%(asctime)s", "pathName":"%(pathname)s", "logRecordCreationTime":"%(created)f", "functionName":"%(funcName)s", "levelNo":"%(levelno)s", "lineNo":"%(lineno)d", "time":"%(msecs)d", "levelName":"%(levelname)s", "message":"%(message)s"}')
        
        handler.formatter = formatter
        logger.addHandler(handler)
        
        logger.info("Test Message")
        

        Run application and send some logs.

        4. Verify Syslog Events

        Search Loggly for events with the logtype as syslog over the past hour. It may take few minutes to index the event. If if doesn’t work, see the troubleshooting section below.

        syslog.appName:Python
        

        Advanced Python Syslog Options

        Troubleshooting Python Syslog Logs

        • Wait a few minutes in case indexing needs to catch up.
        • Check if the SyslogHandler configuration is correct
        • Run “sudo tcpdump -i lo -A udp and port 514″ to verify UDP events are being sent to localhost
        • Search or post your own Python logging syslog question in the community forum.
        Thanks for the feedback! We'll use it to improve our support documentation.


        任你懆视频 这里只有精品