| 24 | |
| 25 | |
| 26 | def create_logging(log_dir, filemode): |
| 27 | os.makedirs(log_dir, exist_ok=True) |
| 28 | i1 = 0 |
| 29 | |
| 30 | while os.path.isfile(os.path.join(log_dir, "{:04d}.log".format(i1))): |
| 31 | i1 += 1 |
| 32 | |
| 33 | log_path = os.path.join(log_dir, "{:04d}.log".format(i1)) |
| 34 | logging.basicConfig( |
| 35 | level=logging.DEBUG, |
| 36 | format="%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s", |
| 37 | datefmt="%a, %d %b %Y %H:%M:%S", |
| 38 | filename=log_path, |
| 39 | filemode=filemode, |
| 40 | ) |
| 41 | |
| 42 | # Print to console |
| 43 | console = logging.StreamHandler() |
| 44 | console.setLevel(logging.INFO) |
| 45 | formatter = logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s") |
| 46 | console.setFormatter(formatter) |
| 47 | logging.getLogger("").addHandler(console) |
| 48 | |
| 49 | return logging |
| 50 | |
| 51 | |
| 52 | def float32_to_int16(x: float) -> int: |