Fail to create log file from boot.py
-
I have set up a logging class in my main.py, being:
class Logger: file_name = None def __init__(self,file_name): self.file_name = file_name def write(self,msg): with open(self.file_name,"a") as file:#write a message to log file.write(msg) file.write('\n') def clear(self): with open(self.file_name,"w")#remove closed file passIn my boot file and my main file i call on it to create logs, however it does not create any of the logs it should for the boot file -- only for the main.
Below is the boot:from machine import UART from network import LoRa from network import WLAN,Bluetooth from main import Logger import binascii import os import pycom logger = Logger("SessionLog.txt") logger.write("Booting") pycom.heartbeat(False) # Setting up the UART to dump the output to the console uart = UART(0, 115200) os.dupterm(uart) logger.write("UART enabled and console dumped") # Disable bluetooth bluetooth = Bluetooth() logger.write("Bluetooth initialized") bluetooth.deinit() logger.write("Bluetooth disabled") pycom.wifi_on_boot(False) logger.write("Wifi on boot turned off") lora = LoRa(mode=LoRa.LORAWAN, public=1, adr=0, tx_retries=0) # Getting the LoRa MAC logger.write("Lora initialized for grabbing MAC address") print("LORA MAC") logger.write("LORA MAC") print(binascii.hexlify(lora.mac())) logger.write(binascii.hexlify(lora.mac()))The same sort of routine logs are written in the main.py, and these are the only lines reflected in the SessionLog.txt file. So the issue is that the boot.py specifically does not write to the file. No error is raised.
-
-
@beelzmon
I thinkk there is a problem with the line
from main.py import Logger
in boot.py. That one causes main.py to be compiled and all statements at top level to be executed. So you get the main.py log messages eventually before the boot.py log messages in the log file.
You could try to either:- put the class logger into a separate file, or
- put the class logger into boot.py.
Since both boot.py and main.py share the same name space, the class logger would be available to both. I prefer the separate file for the logger class.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login