Skip to content

Logger pretty newlines#320

Open
RiskoZS wants to merge 4 commits intoSinisterRectus:devfrom
RiskoZS:logger-pretty-newlines
Open

Logger pretty newlines#320
RiskoZS wants to merge 4 commits intoSinisterRectus:devfrom
RiskoZS:logger-pretty-newlines

Conversation

@RiskoZS
Copy link
Copy Markdown
Contributor

@RiskoZS RiskoZS commented Oct 23, 2021

This pull request adds a new boolean client option prettyNewlines (true by default) and a new Logger option + mutators which, when true, makes the logger pad newlines so that they align with the timestamp label. This is just a cosmetic change to make logging multi-line strings neater.

As an example, what before was:

2021-10-23 15:31:25 | [INFO]     | Hi!
This is a
multiline string!

now becomes:

2021-10-23 15:31:25 | [INFO]     | Hi!
                                 | This is a
                                 | multiline string!

line[5] = gsub(
line[5],
'\r?\n',
'%0' .. rep(' ', #line[1] + 16 - 2) .. '| ' -- Timestamp + label (10) + separators (6)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show where you get 16 from? We probably shouldn't hardcode this if it can be dynamically generated (maybe as a module local value).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label (line[3]) is always length 10. The two separators (|) (line[2] and line[4]) are both 3, so 6 total.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't hardcode this if it can be dynamically generated (maybe as a module local value).

Can you make this happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?
75018a4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants