"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogGroup=exports.RetentionDays=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),cloudwatch=require("../../aws-cloudwatch"),iam=require("../../aws-iam"),core_1=require("../../core"),log_stream_1=require("./log-stream"),logs_generated_1=require("./logs.generated"),metric_filter_1=require("./metric-filter"),pattern_1=require("./pattern"),policy_1=require("./policy"),subscription_filter_1=require("./subscription-filter");class LogGroupBase extends core_1.Resource{addStream(id,props={}){return new log_stream_1.LogStream(this,id,{logGroup:this,...props})}addSubscriptionFilter(id,props){return new subscription_filter_1.SubscriptionFilter(this,id,{logGroup:this,...props})}addMetricFilter(id,props){return new metric_filter_1.MetricFilter(this,id,{logGroup:this,...props})}extractMetric(jsonField,metricNamespace,metricName){return new metric_filter_1.MetricFilter(this,`${metricNamespace}_${metricName}`,{logGroup:this,metricNamespace,metricName,filterPattern:pattern_1.FilterPattern.exists(jsonField),metricValue:jsonField}),new cloudwatch.Metric({metricName,namespace:metricNamespace}).attachTo(this)}grantWrite(grantee){return this.grant(grantee,"logs:CreateLogStream","logs:PutLogEvents")}grant(grantee,...actions){return iam.Grant.addToPrincipalOrResource({grantee,actions,resourceArns:[this.logGroupArn],resource:this})}logGroupPhysicalName(){return this.physicalName}addToResourcePolicy(statement){return this.policy||(this.policy=new policy_1.ResourcePolicy(this,"Policy")),this.policy.document.addStatements(statement),{statementAdded:!0,policyDependable:this.policy}}}var RetentionDays;(function(RetentionDays2){RetentionDays2[RetentionDays2.ONE_DAY=1]="ONE_DAY",RetentionDays2[RetentionDays2.THREE_DAYS=3]="THREE_DAYS",RetentionDays2[RetentionDays2.FIVE_DAYS=5]="FIVE_DAYS",RetentionDays2[RetentionDays2.ONE_WEEK=7]="ONE_WEEK",RetentionDays2[RetentionDays2.TWO_WEEKS=14]="TWO_WEEKS",RetentionDays2[RetentionDays2.ONE_MONTH=30]="ONE_MONTH",RetentionDays2[RetentionDays2.TWO_MONTHS=60]="TWO_MONTHS",RetentionDays2[RetentionDays2.THREE_MONTHS=90]="THREE_MONTHS",RetentionDays2[RetentionDays2.FOUR_MONTHS=120]="FOUR_MONTHS",RetentionDays2[RetentionDays2.FIVE_MONTHS=150]="FIVE_MONTHS",RetentionDays2[RetentionDays2.SIX_MONTHS=180]="SIX_MONTHS",RetentionDays2[RetentionDays2.ONE_YEAR=365]="ONE_YEAR",RetentionDays2[RetentionDays2.THIRTEEN_MONTHS=400]="THIRTEEN_MONTHS",RetentionDays2[RetentionDays2.EIGHTEEN_MONTHS=545]="EIGHTEEN_MONTHS",RetentionDays2[RetentionDays2.TWO_YEARS=731]="TWO_YEARS",RetentionDays2[RetentionDays2.FIVE_YEARS=1827]="FIVE_YEARS",RetentionDays2[RetentionDays2.TEN_YEARS=3653]="TEN_YEARS",RetentionDays2[RetentionDays2.INFINITE=9999]="INFINITE"})(RetentionDays=exports.RetentionDays||(exports.RetentionDays={}));class LogGroup extends LogGroupBase{constructor(scope,id,props={}){var _b;super(scope,id,{physicalName:props.logGroupName});jsiiDeprecationWarnings.aws_cdk_lib_aws_logs_LogGroupProps(props);let retentionInDays=props.retention;if(retentionInDays===void 0&&(retentionInDays=RetentionDays.TWO_YEARS),(retentionInDays===1/0||retentionInDays===RetentionDays.INFINITE)&&(retentionInDays=void 0),retentionInDays!==void 0&&!core_1.Token.isUnresolved(retentionInDays)&&retentionInDays<=0)throw new Error(`retentionInDays must be positive, got ${retentionInDays}`);const resource=new logs_generated_1.CfnLogGroup(this,"Resource",{kmsKeyId:(_b=props.encryptionKey)===null||_b===void 0?void 0:_b.keyArn,logGroupName:this.physicalName,retentionInDays});resource.applyRemovalPolicy(props.removalPolicy),this.logGroupArn=this.getResourceArnAttribute(resource.attrArn,{service:"logs",resource:"log-group",resourceName:this.physicalName,arnFormat:core_1.ArnFormat.COLON_RESOURCE_NAME}),this.logGroupName=this.getResourceNameAttribute(resource.ref)}static fromLogGroupArn(scope,id,logGroupArn){const baseLogGroupArn=logGroupArn.replace(/:\*$/,"");class Import extends LogGroupBase{constructor(){super(...arguments);this.logGroupArn=`${baseLogGroupArn}:*`,this.logGroupName=core_1.Stack.of(scope).splitArn(baseLogGroupArn,core_1.ArnFormat.COLON_RESOURCE_NAME).resourceName}}return new Import(scope,id,{environmentFromArn:baseLogGroupArn})}static fromLogGroupName(scope,id,logGroupName){const baseLogGroupName=logGroupName.replace(/:\*$/,"");class Import extends LogGroupBase{constructor(){super(...arguments);this.logGroupName=baseLogGroupName,this.logGroupArn=core_1.Stack.of(scope).formatArn({service:"logs",resource:"log-group",arnFormat:core_1.ArnFormat.COLON_RESOURCE_NAME,resourceName:baseLogGroupName+":*"})}}return new Import(scope,id)}}exports.LogGroup=LogGroup,_a=JSII_RTTI_SYMBOL_1,LogGroup[_a]={fqn:"aws-cdk-lib.aws_logs.LogGroup",version:"2.13.0"};
//# sourceMappingURL=log-group.js.map
