Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

":" in program_name and strftime of log stream name cause errors #208

Closed
SilentEroder opened this issue Sep 8, 2024 · 2 comments
Closed

Comments

@SilentEroder
Copy link
Contributor

SilentEroder commented Sep 8, 2024

Problem 1 program_name

Windows contains ":" in program_name of log stream name.
For example, C:\

log stream name should not have ":" and "*". In regex, [^:*]
So, sys.argv[0] causes an error in Windows.

Solution 1 program_name

Remove all ":" in sys.argv[0]

program_name=sys.argv[0],  # before
program_name=sys.argv[0].replace(":", ""),  # after

#207

Problem 2 strftime

strftime of log stream name contains ":" because datetime.datetime.now() contains ":"
For example, 11:22:35

log stream name should not have ":" and "*". In regex, [^:*]
So, datetime.datetime.now() causes an error in Windows.

Solution 2-1 strftime

Remove all ":" in datetime.datetime.now()

from datetime import datetime, timezone

strftime=datetime.now(timezone.utc),  # before
strftime=str(datetime.now(timezone.utc)).replace(":", "-"),  # after

However, you can't use {strftime:%Y-%m-%d %H-%M-%S} with editing.

Solution 2-2 strftime

You can use {strftime:%Y-%m-%d %H-%M-%S} without editing.

@dougfultz
Copy link

Confirming Problem 2

On Linux, Using "{machine_name}/{logger_name}/{process_id}/{thread_name}/{strftime}" results in the following error:

WatchtowerWarning: Failed to deliver logs: An error occurred (InvalidParameterException) when calling the PutLogEvents operation: 1 validation error detected:
 Value 'myhostname.local/path.to.module/12345/MainThread/2024-12-17 22:32:57.097146' at 'logStreamName' failed to satisfy constraint: Member must satisfy regular expression pattern: [^:*]*

Confirming Solution 2-2

Using "{machine_name}/{logger_name}/{process_id}/{thread_name}/{strftime:%Y-%m-%d %H-%M-%S}" appears to resolve the error and produces log streams with format:

"myhostname.local/path.to.module/12345/MainThread/2024-12-18 16-18-40"

Note

Using highly unique log stream names will likely result in throttling by CloudWatch when creating the new log streams. A good balance may be to use {strftime:%Y-%m-%d} or {strftime:%Y-%m-%d-%H}.

@kislyuk
Copy link
Owner

kislyuk commented Dec 30, 2024

Windows is unfortunately not directly supported by this library (WSL is supported). You can work around the issue with Windows program_name by not using program_name in your placeholder string.

The strftime behavior is expected. Yes, CloudWatch does not allow colons in the log stream name, and the Watchtower documentation correspondingly advises one to use a strftime format string with the strftime placeholder. I edited the documentation to more directly point out that using the default format string will result in an error.

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

No branches or pull requests

3 participants