Skip to content

Commit

Permalink
Merge a775899 into 399af2a
Browse files Browse the repository at this point in the history
  • Loading branch information
ldesgoui committed Mar 25, 2018
2 parents 399af2a + a775899 commit 4949bb2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions coloredlogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,20 +893,18 @@ def colorize_format(self, fmt):
are part of the same whitespace separated token they'll be highlighted
together in the style defined for the `name` field.
"""
result = []
for token in fmt.split():
def replace(match):
token = match.group(0)
# Look for field names in the token.
for match in re.finditer(r'%\((\w+)\)', token):
# Check if a style is defined for the matched field name.
style = self.nn.get(self.field_styles, match.group(1))
if style:
# If a style is defined we apply it.
token = ansi_wrap(token, **style)
# The style of the first field name that has a style defined
# `wins' (within each whitespace separated token).
break
result.append(token)
return ' '.join(result)
return ansi_wrap(token, **style)
return re.sub(r'\S+', replace, fmt)

def format(self, record):
"""
Expand Down

0 comments on commit 4949bb2

Please sign in to comment.