facebookresearch / projectaria_tools

projectaria_tools is an C++/Python open-source toolkit to interact with Project Aria data

Home Page:https://facebookresearch.github.io/projectaria_tools/docs/intro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any method to mute the log outputs

Yongfan-Liu opened this issue · comments

Hello teams,

I'm trying to extract the data for the machine learning training. The dataset extractor opens the vrs files many times. I want to avoid the log output when a provider is created. e.g.
gt_provider = AriaDigitalTwinDataProvider(data_paths)

Its outputs always take multiple lines and make other outputs hard to find. Is there any method to mute the outputs?

Hello @Yongfan-Liu , thank you for your feedback,
This is a "known" issue, this log is coming from a third party library we are using (the vrs library).

Could you try to set an empty sync before calling your code and see if this is helpful to remove the logs:

import sys
class NullSink:
    def write(self, text):
        pass
null_sink = NullSink()
sys.stdout = null_sink

Hello @SeaOtocinclus, thank you for your help.
Unfortunately, it doesn't work on my side. Here is my sample code and it still outputs lines of logs. Please let me know if I missed something.

import os
from projectaria_tools.projects.adt import (
   AriaDigitalTwinDataProvider,
   AriaDigitalTwinDataPathsProvider
)

import sys
class NullSink:
    def write(self, text):
        pass

    def flush(self):
        pass

def main():
    sequence_path = "../ADT/Apartment_release_golden_skeleton_seq100_10s_sample"
    paths_provider = AriaDigitalTwinDataPathsProvider(sequence_path)
    all_device_serials = paths_provider.get_device_serial_numbers()
    sequence_name = os.path.basename(sequence_path)
    print("all devices for sequence ", sequence_name, ":")
    for idx, device_serial in enumerate(all_device_serials):
        print("device number - ", idx, ": ", device_serial)
    selected_device_number = 0
    data_paths = paths_provider.get_datapaths_by_device_num(selected_device_number)
    gt_provider = AriaDigitalTwinDataProvider(data_paths)

null_sink = NullSink()
sys.stdout = null_sink
main()

Currently, my solution is to print the content I focused on to a txt file. So I can avoid the logs by checking the txt file. /w\

  with open('print_output.txt', 'w') as f:
      with contextlib.redirect_stdout(f):
          main()