Home>

I'm a program beginner.
I am using the GPS module to measure latitude and longitude, but at first I was outputting it with a print statement, but this time I want to output latitude and longitude to the log file, and when I tried to run this error A sentence came out. I would like to know why such an error message appears.

Error message
TypeError: log () missing 1 required positional argument: 'msg'
Applicable source code
import serial
import micropyGPS
import threading
import time
import logging
#Set log output name
logger = logging.getLogger ('GPSTest')
#
logger.setLevel (10)
#
fh = logging.FileHandler ('GPS.log')
logger.addHandler (fh)
gps = micropyGPS.MicropyGPS (9, 'dd') # Create a MicroGPS object.
                                     # Arguments are time zone time difference and output format
def rungps (): # read GPS module and update GPS object
    s = serial.Serial ('/ dev/serial0', 9600, timeout = 10)
    s.readline () # discard the first line because halfway data can be read
    while True:
        sentence = s.readline (). decode ('utf-8') # Read GPS data and convert it to a string
        if sentence [0]! = '$': # throw away unless it starts with '$'
            continue
        for x in sentence: # Parse the read string and add/update data to the GPS object
           gps.update (x)
gpsthread = threading.Thread (target = rungps, args = ()) # Create a thread to execute the above function
gpsthread.daemon = True
gpsthread.start () # start thread
while True:
    if gps.clean_sentences>1: # output when some data is collected
        #h = gps.timestamp [0] if gps.timestamp [0]<24 else gps.timestamp [0]-24
        #print ('% 2d:% 02d:% 04.1f'% (h, gps.timestamp [1], gps.timestamp [2]))
        latlon = (gps.latitude [0], gps.longitude [0])
        logger.log (latlon)
        #rint ('Sea level:% f'% gps.altitude)
        #rint (gps.satellites_used)
        #rint ('Satellite Number: (Elevation, Azimuth, Signal to Noise Ratio)')
        for k, v in gps.satellite_data.items ():
            print ('% d:% s'% (k, v))
        print ('')
    time.sleep (3.0)

Since I wanted only latitude and longitude, I commented out the other output.

Supplemental information (FW/tool version etc.)

Please provide more information here.

  • Answer # 1

    logis called bylog (level, msg, * args, ** kwargs), and the log level is specified as an integer.

    logger.log (99, "!!!!!!")
    Or, using a constant,
    logger.log (logging.INFO, "something")


    Since it islogger.setLevel (10), it is output only when a value greater than10is specified.

    Level isCRITICAL>ERROR>WARNING>INFO>DEBUGSo

    logger.setLevel (logging.INFO)
    logger.error ("AAAAA") # ⇒ output
    logger.debug ("AAAAA") # ⇒ No output
    logger.log (logging.ERROR, "AAAAA") # same as logger.error ("AAAAA")


    It will be said that.

  • Answer # 2

      

    logger.log (latlon)

    What kind of argument is this log function?
    And what type does this latlon variable have?