forked from A-Rain/EmpDialogue_RecEC
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc_utils.py
29 lines (21 loc) · 829 Bytes
/
misc_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from typing import (
Any, Callable, Generic, Iterator, List, Optional, Tuple, TypeVar, Union)
import torch
from texar.torch.data import BatchingStrategy
import logging
Example = TypeVar('Example')
logger = logging.getLogger()
def init_logger(log_file=None):
log_format = logging.Formatter("[%(asctime)s %(levelname)s] %(message)s")
logger = logging.getLogger()
logger.setLevel(logging.INFO)
console_handler = logging.StreamHandler()
console_handler.setFormatter(log_format)
logger.handlers = [console_handler]
if log_file and log_file != '':
file_handler = logging.FileHandler(log_file)
file_handler.setFormatter(log_format)
logger.addHandler(file_handler)
return logger