{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ECS.Types.LogConfiguration
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ECS.Types.LogConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ECS.Types.LogDriver
import Amazonka.ECS.Types.Secret
import qualified Amazonka.Prelude as Prelude

-- | The log configuration for the container. This parameter maps to
-- @LogConfig@ in the
-- <https://docs.docker.com/engine/api/v1.35/#operation/ContainerCreate Create a container>
-- section of the
-- <https://docs.docker.com/engine/api/v1.35/ Docker Remote API> and the
-- @--log-driver@ option to
-- <https://docs.docker.com/engine/reference/commandline/run/ docker run> .
--
-- By default, containers use the same logging driver that the Docker
-- daemon uses. However, the container might use a different logging driver
-- than the Docker daemon by specifying a log driver configuration in the
-- container definition. For more information about the options for
-- different supported log drivers, see
-- <https://docs.docker.com/engine/admin/logging/overview/ Configure logging drivers>
-- in the Docker documentation.
--
-- Understand the following when specifying a log configuration for your
-- containers.
--
-- -   Amazon ECS currently supports a subset of the logging drivers
--     available to the Docker daemon (shown in the valid values below).
--     Additional log drivers may be available in future releases of the
--     Amazon ECS container agent.
--
-- -   This parameter requires version 1.18 of the Docker Remote API or
--     greater on your container instance.
--
-- -   For tasks that are hosted on Amazon EC2 instances, the Amazon ECS
--     container agent must register the available logging drivers with the
--     @ECS_AVAILABLE_LOGGING_DRIVERS@ environment variable before
--     containers placed on that instance can use these log configuration
--     options. For more information, see
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html Amazon ECS container agent configuration>
--     in the /Amazon Elastic Container Service Developer Guide/.
--
-- -   For tasks that are on Fargate, because you don\'t have access to the
--     underlying infrastructure your tasks are hosted on, any additional
--     software needed must be installed outside of the task. For example,
--     the Fluentd output aggregators or a remote host running Logstash to
--     send Gelf logs to.
--
-- /See:/ 'newLogConfiguration' smart constructor.
data LogConfiguration = LogConfiguration'
  { -- | The configuration options to send to the log driver. This parameter
    -- requires version 1.19 of the Docker Remote API or greater on your
    -- container instance. To check the Docker Remote API version on your
    -- container instance, log in to your container instance and run the
    -- following command:
    -- @sudo docker version --format \'{{.Server.APIVersion}}\'@
    LogConfiguration -> Maybe (HashMap Text Text)
options :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The secrets to pass to the log configuration. For more information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html Specifying sensitive data>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    LogConfiguration -> Maybe [Secret]
secretOptions :: Prelude.Maybe [Secret],
    -- | The log driver to use for the container.
    --
    -- For tasks on Fargate, the supported log drivers are @awslogs@, @splunk@,
    -- and @awsfirelens@.
    --
    -- For tasks hosted on Amazon EC2 instances, the supported log drivers are
    -- @awslogs@, @fluentd@, @gelf@, @json-file@, @journald@,
    -- @logentries@,@syslog@, @splunk@, and @awsfirelens@.
    --
    -- For more information about using the @awslogs@ log driver, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html Using the awslogs log driver>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    --
    -- For more information about using the @awsfirelens@ log driver, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html Custom log routing>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    --
    -- If you have a custom driver that isn\'t listed, you can fork the Amazon
    -- ECS container agent project that\'s
    -- <https://github.com/aws/amazon-ecs-agent available on GitHub> and
    -- customize it to work with that driver. We encourage you to submit pull
    -- requests for changes that you would like to have included. However, we
    -- don\'t currently provide support for running modified copies of this
    -- software.
    LogConfiguration -> LogDriver
logDriver :: LogDriver
  }
  deriving (LogConfiguration -> LogConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LogConfiguration -> LogConfiguration -> Bool
$c/= :: LogConfiguration -> LogConfiguration -> Bool
== :: LogConfiguration -> LogConfiguration -> Bool
$c== :: LogConfiguration -> LogConfiguration -> Bool
Prelude.Eq, ReadPrec [LogConfiguration]
ReadPrec LogConfiguration
Int -> ReadS LogConfiguration
ReadS [LogConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LogConfiguration]
$creadListPrec :: ReadPrec [LogConfiguration]
readPrec :: ReadPrec LogConfiguration
$creadPrec :: ReadPrec LogConfiguration
readList :: ReadS [LogConfiguration]
$creadList :: ReadS [LogConfiguration]
readsPrec :: Int -> ReadS LogConfiguration
$creadsPrec :: Int -> ReadS LogConfiguration
Prelude.Read, Int -> LogConfiguration -> ShowS
[LogConfiguration] -> ShowS
LogConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LogConfiguration] -> ShowS
$cshowList :: [LogConfiguration] -> ShowS
show :: LogConfiguration -> String
$cshow :: LogConfiguration -> String
showsPrec :: Int -> LogConfiguration -> ShowS
$cshowsPrec :: Int -> LogConfiguration -> ShowS
Prelude.Show, forall x. Rep LogConfiguration x -> LogConfiguration
forall x. LogConfiguration -> Rep LogConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LogConfiguration x -> LogConfiguration
$cfrom :: forall x. LogConfiguration -> Rep LogConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'LogConfiguration' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'options', 'logConfiguration_options' - The configuration options to send to the log driver. This parameter
-- requires version 1.19 of the Docker Remote API or greater on your
-- container instance. To check the Docker Remote API version on your
-- container instance, log in to your container instance and run the
-- following command:
-- @sudo docker version --format \'{{.Server.APIVersion}}\'@
--
-- 'secretOptions', 'logConfiguration_secretOptions' - The secrets to pass to the log configuration. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html Specifying sensitive data>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- 'logDriver', 'logConfiguration_logDriver' - The log driver to use for the container.
--
-- For tasks on Fargate, the supported log drivers are @awslogs@, @splunk@,
-- and @awsfirelens@.
--
-- For tasks hosted on Amazon EC2 instances, the supported log drivers are
-- @awslogs@, @fluentd@, @gelf@, @json-file@, @journald@,
-- @logentries@,@syslog@, @splunk@, and @awsfirelens@.
--
-- For more information about using the @awslogs@ log driver, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html Using the awslogs log driver>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- For more information about using the @awsfirelens@ log driver, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html Custom log routing>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- If you have a custom driver that isn\'t listed, you can fork the Amazon
-- ECS container agent project that\'s
-- <https://github.com/aws/amazon-ecs-agent available on GitHub> and
-- customize it to work with that driver. We encourage you to submit pull
-- requests for changes that you would like to have included. However, we
-- don\'t currently provide support for running modified copies of this
-- software.
newLogConfiguration ::
  -- | 'logDriver'
  LogDriver ->
  LogConfiguration
newLogConfiguration :: LogDriver -> LogConfiguration
newLogConfiguration LogDriver
pLogDriver_ =
  LogConfiguration'
    { $sel:options:LogConfiguration' :: Maybe (HashMap Text Text)
options = forall a. Maybe a
Prelude.Nothing,
      $sel:secretOptions:LogConfiguration' :: Maybe [Secret]
secretOptions = forall a. Maybe a
Prelude.Nothing,
      $sel:logDriver:LogConfiguration' :: LogDriver
logDriver = LogDriver
pLogDriver_
    }

-- | The configuration options to send to the log driver. This parameter
-- requires version 1.19 of the Docker Remote API or greater on your
-- container instance. To check the Docker Remote API version on your
-- container instance, log in to your container instance and run the
-- following command:
-- @sudo docker version --format \'{{.Server.APIVersion}}\'@
logConfiguration_options :: Lens.Lens' LogConfiguration (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
logConfiguration_options :: Lens' LogConfiguration (Maybe (HashMap Text Text))
logConfiguration_options = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogConfiguration' {Maybe (HashMap Text Text)
options :: Maybe (HashMap Text Text)
$sel:options:LogConfiguration' :: LogConfiguration -> Maybe (HashMap Text Text)
options} -> Maybe (HashMap Text Text)
options) (\s :: LogConfiguration
s@LogConfiguration' {} Maybe (HashMap Text Text)
a -> LogConfiguration
s {$sel:options:LogConfiguration' :: Maybe (HashMap Text Text)
options = Maybe (HashMap Text Text)
a} :: LogConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The secrets to pass to the log configuration. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html Specifying sensitive data>
-- in the /Amazon Elastic Container Service Developer Guide/.
logConfiguration_secretOptions :: Lens.Lens' LogConfiguration (Prelude.Maybe [Secret])
logConfiguration_secretOptions :: Lens' LogConfiguration (Maybe [Secret])
logConfiguration_secretOptions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogConfiguration' {Maybe [Secret]
secretOptions :: Maybe [Secret]
$sel:secretOptions:LogConfiguration' :: LogConfiguration -> Maybe [Secret]
secretOptions} -> Maybe [Secret]
secretOptions) (\s :: LogConfiguration
s@LogConfiguration' {} Maybe [Secret]
a -> LogConfiguration
s {$sel:secretOptions:LogConfiguration' :: Maybe [Secret]
secretOptions = Maybe [Secret]
a} :: LogConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The log driver to use for the container.
--
-- For tasks on Fargate, the supported log drivers are @awslogs@, @splunk@,
-- and @awsfirelens@.
--
-- For tasks hosted on Amazon EC2 instances, the supported log drivers are
-- @awslogs@, @fluentd@, @gelf@, @json-file@, @journald@,
-- @logentries@,@syslog@, @splunk@, and @awsfirelens@.
--
-- For more information about using the @awslogs@ log driver, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html Using the awslogs log driver>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- For more information about using the @awsfirelens@ log driver, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html Custom log routing>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- If you have a custom driver that isn\'t listed, you can fork the Amazon
-- ECS container agent project that\'s
-- <https://github.com/aws/amazon-ecs-agent available on GitHub> and
-- customize it to work with that driver. We encourage you to submit pull
-- requests for changes that you would like to have included. However, we
-- don\'t currently provide support for running modified copies of this
-- software.
logConfiguration_logDriver :: Lens.Lens' LogConfiguration LogDriver
logConfiguration_logDriver :: Lens' LogConfiguration LogDriver
logConfiguration_logDriver = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogConfiguration' {LogDriver
logDriver :: LogDriver
$sel:logDriver:LogConfiguration' :: LogConfiguration -> LogDriver
logDriver} -> LogDriver
logDriver) (\s :: LogConfiguration
s@LogConfiguration' {} LogDriver
a -> LogConfiguration
s {$sel:logDriver:LogConfiguration' :: LogDriver
logDriver = LogDriver
a} :: LogConfiguration)

instance Data.FromJSON LogConfiguration where
  parseJSON :: Value -> Parser LogConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LogConfiguration"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe [Secret] -> LogDriver -> LogConfiguration
LogConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"options" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"secretOptions" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"logDriver")
      )

instance Prelude.Hashable LogConfiguration where
  hashWithSalt :: Int -> LogConfiguration -> Int
hashWithSalt Int
_salt LogConfiguration' {Maybe [Secret]
Maybe (HashMap Text Text)
LogDriver
logDriver :: LogDriver
secretOptions :: Maybe [Secret]
options :: Maybe (HashMap Text Text)
$sel:logDriver:LogConfiguration' :: LogConfiguration -> LogDriver
$sel:secretOptions:LogConfiguration' :: LogConfiguration -> Maybe [Secret]
$sel:options:LogConfiguration' :: LogConfiguration -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
options
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Secret]
secretOptions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LogDriver
logDriver

instance Prelude.NFData LogConfiguration where
  rnf :: LogConfiguration -> ()
rnf LogConfiguration' {Maybe [Secret]
Maybe (HashMap Text Text)
LogDriver
logDriver :: LogDriver
secretOptions :: Maybe [Secret]
options :: Maybe (HashMap Text Text)
$sel:logDriver:LogConfiguration' :: LogConfiguration -> LogDriver
$sel:secretOptions:LogConfiguration' :: LogConfiguration -> Maybe [Secret]
$sel:options:LogConfiguration' :: LogConfiguration -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
options
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Secret]
secretOptions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf LogDriver
logDriver

instance Data.ToJSON LogConfiguration where
  toJSON :: LogConfiguration -> Value
toJSON LogConfiguration' {Maybe [Secret]
Maybe (HashMap Text Text)
LogDriver
logDriver :: LogDriver
secretOptions :: Maybe [Secret]
options :: Maybe (HashMap Text Text)
$sel:logDriver:LogConfiguration' :: LogConfiguration -> LogDriver
$sel:secretOptions:LogConfiguration' :: LogConfiguration -> Maybe [Secret]
$sel:options:LogConfiguration' :: LogConfiguration -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"options" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
options,
            (Key
"secretOptions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Secret]
secretOptions,
            forall a. a -> Maybe a
Prelude.Just (Key
"logDriver" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= LogDriver
logDriver)
          ]
      )