-
Notifications
You must be signed in to change notification settings - Fork 5
/
log.py
35 lines (23 loc) · 943 Bytes
/
log.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
30
31
32
33
34
35
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2019-2021 Patryk Obara <[email protected]>
"""
Log functions
"""
import os
import sys
PREFIX = 'boxtron:'
QUIET: bool = os.environ.get('BOXTRON_QUIET', '0') != '0'
def print_err(*value, sep=' ', end='\n', flush=False):
"""Prints the values to stderr."""
if QUIET:
return
print(*value, sep=sep, end=end, file=sys.stderr, flush=flush)
def log(*value, sep=' ', end='\n', flush=False):
"""Prints the values to stderr with prefix."""
print_err(PREFIX, *value, sep=sep, end=end, flush=flush)
def log_err(*value, sep=' ', end='\n', flush=False):
"""Prints the values to stderr with prefix and 'error:'"""
log('error:', *value, sep=sep, end=end, flush=flush)
def log_warn(*value, sep=' ', end='\n', flush=False):
"""Prints the values to stderr with prefix and 'warning:'"""
log('warning:', *value, sep=sep, end=end, flush=flush)