• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

klahnakoski / mo-logs / 13617929038

02 Mar 2025 05:58PM UTC coverage: 65.638% (+0.06%) from 65.576%
13617929038

push

github

klahnakoski
updates from other projects

11 of 15 new or added lines in 7 files covered. (73.33%)

1 existing line in 1 file now uncovered.

957 of 1458 relevant lines covered (65.64%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/mo_logs/log_usingStream.py
1
# encoding: utf-8
2
#
3
#
4
# This Source Code Form is subject to the terms of the Mozilla Public
5
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
6
# You can obtain one at https://www.mozilla.org/en-US/MPL/2.0/.
7
#
8
# Contact: Kyle Lahnakoski (kyle@lahnakoski.com)
9
#
10
from mo_future import allocate_lock, STDERR, STDOUT
×
11

12
from mo_logs.log_usingNothing import StructuredLogger
×
13
from mo_logs.strings import CR, expand_template
×
14

15

16
class StructuredLogger_usingStream(StructuredLogger):
×
17
    def __init__(self, stream):
×
18
        try:
×
19
            self.locker = allocate_lock()
×
20
            self.flush = stream.flush
×
21
            if stream in (STDOUT, STDERR):
×
22
                try:
×
23
                    stream = stream.buffer
×
24
                except Exception:
×
25
                    # SOMETIMES STDOUT IS REPLACED BY SOMETHING ELSE
26
                    pass
×
27
            self.writer = _UTF8Encoder(stream).write
×
28
        except Exception as _:
×
29
            import sys
×
30

31
            sys.stderr.write("can not handle")
×
32

33
    def write(self, template, params):
×
34
        value = expand_template(template, params)
×
35
        with self.locker:
×
36
            self.writer(value + CR)
×
37
            try:
×
38
                self.flush()
×
39
            except Exception:
×
40
                pass
×
41

42
    def stop(self):
×
43
        try:
×
44
            self.flush()
×
45
        except Exception:
×
46
            pass
×
47

48

NEW
49
class _UTF8Encoder:
×
50
    def __init__(self, stream):
×
51
        self.stream = stream
×
52

53
    def write(self, v):
×
54
        try:
×
55
            self.stream.write(v.encode("utf8"))
×
56
            self.stream.flush()
×
57
        except Exception:
×
58
            import sys
×
59

60
            sys.stderr.write("can not handle")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc