python ctime_Python datetime.ctime方法代码示例

# 需要导入模块: from datetime import datetime [as 别名]

# 或者: from datetime.datetime import ctime [as 别名]

def create_logger(level=logging.NOTSET):

"""Create a logger for python-gnupg at a specific message level.

:type level: :obj:`int` or :obj:`str`

:param level: A string or an integer for the lowest level to include in

logs.

**Available levels:**

==== ======== ========================================

int str description

==== ======== ========================================

0 NOTSET Disable all logging.

9 GNUPG Log GnuPG's internal status messages.

10 DEBUG Log module level debuging messages.

20 INFO Normal user-level messages.

30 WARN Warning messages.

40 ERROR Error messages and tracebacks.

50 CRITICAL Unhandled exceptions and tracebacks.

==== ======== ========================================

"""

_test = os.path.join(os.path.join(os.getcwd(), 'gnupg'), 'test')

_now = datetime.now().strftime("%Y-%m-%d_%H%M%S")

_fn = os.path.join(_test, "%s_test_gnupg.log" % _now)

_fmt = "%(relativeCreated)-4d L%(lineno)-4d:%(funcName)-18.18s %(levelname)-7.7s %(message)s"

## Add the GNUPG_STATUS_LEVEL LogRecord to all Loggers in the module:

logging.addLevelName(GNUPG_STATUS_LEVEL, "GNUPG")

logging.Logger.status = status

if level > logging.NOTSET:

logging.basicConfig(level=level, filename=_fn,

filemode="a", format=_fmt)

logging.logThreads = True

if hasattr(logging,'captureWarnings'):

logging.captureWarnings(True)

colouriser = _ansistrm.ColorizingStreamHandler

colouriser.level_map[9] = (None, 'blue', False)

colouriser.level_map[10] = (None, 'cyan', False)

handler = colouriser(sys.stderr)

handler.setLevel(level)

formatr = logging.Formatter(_fmt)

handler.setFormatter(formatr)

else:

handler = NullHandler()

log = logging.getLogger('gnupg')

log.addHandler(handler)

log.setLevel(level)

log.info("Log opened: %s UTC" % datetime.ctime(datetime.utcnow()))

return log

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值