Skip to content

Commit 5bc5a00

Browse files
committed
Merge branch 'feat-memory-protocol' into feat-conn-string-builders
2 parents 50ecdf8 + dea6943 commit 5bc5a00

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

common/pattern_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ def _next(self) -> typing.Optional[Token]:
6868
is_variable = False
6969
pos: int = self._position
7070

71-
if self._pattern[pos: pos + 2] == "/%":
71+
if self._pattern[pos] == "$":
7272
is_variable = True
73-
pos += 2
73+
pos += 1
7474

75-
while pos + 1 < length:
76-
if self._pattern[pos: pos + 2] == "/%":
75+
while pos < length:
76+
if self._pattern[pos] == "$":
7777
if is_variable:
78-
pos += 2
78+
pos += 1
7979
break
8080
pos += 1
8181

common/tokens/token_factory.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
class TokenFactory:
66
tokens = {
7-
"/%appname/%": AppNameToken,
8-
"/%session/%": SessionToken,
9-
"/%hostname/%": HostNameToken,
10-
"/%title/%": TitleToken,
11-
"/%timestamp/%": TimestampToken,
12-
"/%level/%": LevelToken,
13-
"/%color/%": ColorToken,
14-
"/%logentrytype/%": LogEntryTypeToken,
15-
"/%viewerid/%": ViewerIdToken,
16-
"/%thread/%": ThreadIdToken,
17-
"/%process/%": ProcessIdToken,
7+
"$appname$": AppNameToken,
8+
"$session$": SessionToken,
9+
"$hostname$": HostNameToken,
10+
"$title$": TitleToken,
11+
"$timestamp$": TimestampToken,
12+
"$level$": LevelToken,
13+
"$color$": ColorToken,
14+
"$logentrytype$": LogEntryTypeToken,
15+
"$viewerid$": ViewerIdToken,
16+
"$thread$": ThreadIdToken,
17+
"$process$": ProcessIdToken,
1818
}
1919

2020
@staticmethod
@@ -37,30 +37,29 @@ def get_token(cls, value: str) -> Token:
3737
if length <= 2:
3838
return cls._create_literal(value)
3939

40-
if value[:2] != "/%" or value[-2:] != "/%":
40+
if value[0] != "$" or value[-1] != "$":
4141
return cls._create_literal(value)
4242

4343
original = value
4444
options = ""
4545

46-
# extract the token options: /%token{options}/%
47-
if value[-3] == "}":
46+
# extract the token options: $token{options}$
47+
if value[-2] == "}":
4848
idx = value.find("{")
4949

5050
if idx > -1:
5151
idx += 1
52-
options = value[idx: -3]
53-
value = value[:idx - 1] + value[-2:]
54-
length = len(value)
52+
options = value[idx: -2]
53+
value = value[:idx - 1] + value[-1]
5554

5655
width = ""
5756
idx = value.find(",")
5857

59-
# extract the token width: /%token, width/%
58+
# extract the token width: $token, width$
6059
if idx > -1:
6160
idx += 1
62-
width = value[idx: -2]
63-
value = value[: idx - 1] + value[length - 2:]
61+
width = value[idx: -1]
62+
value = value[: idx - 1] + value[-1]
6463

6564
value = value.lower()
6665
impl = cls.tokens.get(value)

protocols/text_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class TextProtocol(FileProtocol):
99
_HEADER: bytes = bytes((0xEF, 0xBB, 0xBF))
1010
_DEFAULT_INDENT: bool = False
11-
_DEFAULT_PATTERN: str = "[/%timestamp/%] /%level/%: /%title/%"
11+
_DEFAULT_PATTERN: str = "[$timestamp$] $level$: $title$"
1212

1313
def __init__(self) -> None:
1414
super().__init__()

0 commit comments

Comments
 (0)