简体   繁体   中英

Create separate log stream for each file with pattern AWS Cloudwatch

I wanna create separate log streams for each fille with pattern sync- .log (for example filename sync-site1.log, stream name - server-sync-site1). There are a lot of log files with sync- .log pattern, so do it manually for each is a bad option for me. How can I do it? I'm using an older agent.

Here is my current config:

[server-sync.log] 
datetime_format = %Y-%m-%dT%H:%M:%S,%f
file = /home/ec2-user/log/sync/sync-*.log 
buffer_duration = 5000 
log_stream_name = server-sync
initial_position = end_of_file
multi_line_start_pattern = {datetime_format}
log_group_name = server

There is a well defined API Call for this purpose CreateLogStream , corresponding api call in boto3 is create_stream

response = client.create_log_stream(
    logGroupName='string',
    logStreamName='string'
)

There is a terraform resource as well named aws_cloudwatch_log_stream

resource "aws_cloudwatch_log_group" "yada" {
  name = "Yada"
}

resource "aws_cloudwatch_log_stream" "foo" {
  name           = "SampleLogStream1234"
  log_group_name = aws_cloudwatch_log_group.yada.name
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM