File: log.py

package info (click to toggle)
python-clickhouse-driver 0.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,516 kB
  • sloc: python: 10,950; pascal: 42; makefile: 31; sh: 3
file content (44 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (3)
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
36
37
38
39
40
41
42
43
44
import logging

logger = logging.getLogger(__name__)


log_priorities = (
    'Unknown',
    'Fatal',
    'Critical',
    'Error',
    'Warning',
    'Notice',
    'Information',
    'Debug',
    'Trace'
)


def log_block(block):
    if block is None:
        return

    column_names = [x[0] for x in block.columns_with_types]

    for row in block.get_rows():
        row = dict(zip(column_names, row))

        if 1 <= row['priority'] <= 8:
            priority = log_priorities[row['priority']]
        else:
            priority = row[0]

        # thread_number in servers prior 20.x
        thread_id = row.get('thread_id') or row['thread_number']

        logger.info(
            '[ %s ] [ %s ] {%s} <%s> %s: %s',
            row['host_name'],
            thread_id,
            row['query_id'],
            priority,
            row['source'],
            row['text']
        )