{-# 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.AppSync.Types.LogConfig
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AppSync.Types.LogConfig where

import Amazonka.AppSync.Types.FieldLogLevel
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The CloudWatch Logs configuration.
--
-- /See:/ 'newLogConfig' smart constructor.
data LogConfig = LogConfig'
  { -- | Set to TRUE to exclude sections that contain information such as
    -- headers, context, and evaluated mapping templates, regardless of logging
    -- level.
    LogConfig -> Maybe Bool
excludeVerboseContent :: Prelude.Maybe Prelude.Bool,
    -- | The field logging level. Values can be NONE, ERROR, or ALL.
    --
    -- -   __NONE__: No field-level logs are captured.
    --
    -- -   __ERROR__: Logs the following information only for the fields that
    --     are in error:
    --
    --     -   The error section in the server response.
    --
    --     -   Field-level errors.
    --
    --     -   The generated request\/response functions that got resolved for
    --         error fields.
    --
    -- -   __ALL__: The following information is logged for all fields in the
    --     query:
    --
    --     -   Field-level tracing information.
    --
    --     -   The generated request\/response functions that got resolved for
    --         each field.
    LogConfig -> FieldLogLevel
fieldLogLevel :: FieldLogLevel,
    -- | The service role that AppSync will assume to publish to Amazon
    -- CloudWatch logs in your account.
    LogConfig -> Text
cloudWatchLogsRoleArn :: Prelude.Text
  }
  deriving (LogConfig -> LogConfig -> Bool
(LogConfig -> LogConfig -> Bool)
-> (LogConfig -> LogConfig -> Bool) -> Eq LogConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LogConfig -> LogConfig -> Bool
$c/= :: LogConfig -> LogConfig -> Bool
== :: LogConfig -> LogConfig -> Bool
$c== :: LogConfig -> LogConfig -> Bool
Prelude.Eq, ReadPrec [LogConfig]
ReadPrec LogConfig
Int -> ReadS LogConfig
ReadS [LogConfig]
(Int -> ReadS LogConfig)
-> ReadS [LogConfig]
-> ReadPrec LogConfig
-> ReadPrec [LogConfig]
-> Read LogConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LogConfig]
$creadListPrec :: ReadPrec [LogConfig]
readPrec :: ReadPrec LogConfig
$creadPrec :: ReadPrec LogConfig
readList :: ReadS [LogConfig]
$creadList :: ReadS [LogConfig]
readsPrec :: Int -> ReadS LogConfig
$creadsPrec :: Int -> ReadS LogConfig
Prelude.Read, Int -> LogConfig -> ShowS
[LogConfig] -> ShowS
LogConfig -> String
(Int -> LogConfig -> ShowS)
-> (LogConfig -> String)
-> ([LogConfig] -> ShowS)
-> Show LogConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LogConfig] -> ShowS
$cshowList :: [LogConfig] -> ShowS
show :: LogConfig -> String
$cshow :: LogConfig -> String
showsPrec :: Int -> LogConfig -> ShowS
$cshowsPrec :: Int -> LogConfig -> ShowS
Prelude.Show, (forall x. LogConfig -> Rep LogConfig x)
-> (forall x. Rep LogConfig x -> LogConfig) -> Generic LogConfig
forall x. Rep LogConfig x -> LogConfig
forall x. LogConfig -> Rep LogConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LogConfig x -> LogConfig
$cfrom :: forall x. LogConfig -> Rep LogConfig x
Prelude.Generic)

-- |
-- Create a value of 'LogConfig' 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:
--
-- 'excludeVerboseContent', 'logConfig_excludeVerboseContent' - Set to TRUE to exclude sections that contain information such as
-- headers, context, and evaluated mapping templates, regardless of logging
-- level.
--
-- 'fieldLogLevel', 'logConfig_fieldLogLevel' - The field logging level. Values can be NONE, ERROR, or ALL.
--
-- -   __NONE__: No field-level logs are captured.
--
-- -   __ERROR__: Logs the following information only for the fields that
--     are in error:
--
--     -   The error section in the server response.
--
--     -   Field-level errors.
--
--     -   The generated request\/response functions that got resolved for
--         error fields.
--
-- -   __ALL__: The following information is logged for all fields in the
--     query:
--
--     -   Field-level tracing information.
--
--     -   The generated request\/response functions that got resolved for
--         each field.
--
-- 'cloudWatchLogsRoleArn', 'logConfig_cloudWatchLogsRoleArn' - The service role that AppSync will assume to publish to Amazon
-- CloudWatch logs in your account.
newLogConfig ::
  -- | 'fieldLogLevel'
  FieldLogLevel ->
  -- | 'cloudWatchLogsRoleArn'
  Prelude.Text ->
  LogConfig
newLogConfig :: FieldLogLevel -> Text -> LogConfig
newLogConfig FieldLogLevel
pFieldLogLevel_ Text
pCloudWatchLogsRoleArn_ =
  LogConfig' :: Maybe Bool -> FieldLogLevel -> Text -> LogConfig
LogConfig'
    { $sel:excludeVerboseContent:LogConfig' :: Maybe Bool
excludeVerboseContent = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:fieldLogLevel:LogConfig' :: FieldLogLevel
fieldLogLevel = FieldLogLevel
pFieldLogLevel_,
      $sel:cloudWatchLogsRoleArn:LogConfig' :: Text
cloudWatchLogsRoleArn = Text
pCloudWatchLogsRoleArn_
    }

-- | Set to TRUE to exclude sections that contain information such as
-- headers, context, and evaluated mapping templates, regardless of logging
-- level.
logConfig_excludeVerboseContent :: Lens.Lens' LogConfig (Prelude.Maybe Prelude.Bool)
logConfig_excludeVerboseContent :: (Maybe Bool -> f (Maybe Bool)) -> LogConfig -> f LogConfig
logConfig_excludeVerboseContent = (LogConfig -> Maybe Bool)
-> (LogConfig -> Maybe Bool -> LogConfig)
-> Lens LogConfig LogConfig (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogConfig' {Maybe Bool
excludeVerboseContent :: Maybe Bool
$sel:excludeVerboseContent:LogConfig' :: LogConfig -> Maybe Bool
excludeVerboseContent} -> Maybe Bool
excludeVerboseContent) (\s :: LogConfig
s@LogConfig' {} Maybe Bool
a -> LogConfig
s {$sel:excludeVerboseContent:LogConfig' :: Maybe Bool
excludeVerboseContent = Maybe Bool
a} :: LogConfig)

-- | The field logging level. Values can be NONE, ERROR, or ALL.
--
-- -   __NONE__: No field-level logs are captured.
--
-- -   __ERROR__: Logs the following information only for the fields that
--     are in error:
--
--     -   The error section in the server response.
--
--     -   Field-level errors.
--
--     -   The generated request\/response functions that got resolved for
--         error fields.
--
-- -   __ALL__: The following information is logged for all fields in the
--     query:
--
--     -   Field-level tracing information.
--
--     -   The generated request\/response functions that got resolved for
--         each field.
logConfig_fieldLogLevel :: Lens.Lens' LogConfig FieldLogLevel
logConfig_fieldLogLevel :: (FieldLogLevel -> f FieldLogLevel) -> LogConfig -> f LogConfig
logConfig_fieldLogLevel = (LogConfig -> FieldLogLevel)
-> (LogConfig -> FieldLogLevel -> LogConfig)
-> Lens LogConfig LogConfig FieldLogLevel FieldLogLevel
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogConfig' {FieldLogLevel
fieldLogLevel :: FieldLogLevel
$sel:fieldLogLevel:LogConfig' :: LogConfig -> FieldLogLevel
fieldLogLevel} -> FieldLogLevel
fieldLogLevel) (\s :: LogConfig
s@LogConfig' {} FieldLogLevel
a -> LogConfig
s {$sel:fieldLogLevel:LogConfig' :: FieldLogLevel
fieldLogLevel = FieldLogLevel
a} :: LogConfig)

-- | The service role that AppSync will assume to publish to Amazon
-- CloudWatch logs in your account.
logConfig_cloudWatchLogsRoleArn :: Lens.Lens' LogConfig Prelude.Text
logConfig_cloudWatchLogsRoleArn :: (Text -> f Text) -> LogConfig -> f LogConfig
logConfig_cloudWatchLogsRoleArn = (LogConfig -> Text)
-> (LogConfig -> Text -> LogConfig)
-> Lens LogConfig LogConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogConfig' {Text
cloudWatchLogsRoleArn :: Text
$sel:cloudWatchLogsRoleArn:LogConfig' :: LogConfig -> Text
cloudWatchLogsRoleArn} -> Text
cloudWatchLogsRoleArn) (\s :: LogConfig
s@LogConfig' {} Text
a -> LogConfig
s {$sel:cloudWatchLogsRoleArn:LogConfig' :: Text
cloudWatchLogsRoleArn = Text
a} :: LogConfig)

instance Core.FromJSON LogConfig where
  parseJSON :: Value -> Parser LogConfig
parseJSON =
    String -> (Object -> Parser LogConfig) -> Value -> Parser LogConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LogConfig"
      ( \Object
x ->
          Maybe Bool -> FieldLogLevel -> Text -> LogConfig
LogConfig'
            (Maybe Bool -> FieldLogLevel -> Text -> LogConfig)
-> Parser (Maybe Bool)
-> Parser (FieldLogLevel -> Text -> LogConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"excludeVerboseContent")
            Parser (FieldLogLevel -> Text -> LogConfig)
-> Parser FieldLogLevel -> Parser (Text -> LogConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser FieldLogLevel
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"fieldLogLevel")
            Parser (Text -> LogConfig) -> Parser Text -> Parser LogConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"cloudWatchLogsRoleArn")
      )

instance Prelude.Hashable LogConfig

instance Prelude.NFData LogConfig

instance Core.ToJSON LogConfig where
  toJSON :: LogConfig -> Value
toJSON LogConfig' {Maybe Bool
Text
FieldLogLevel
cloudWatchLogsRoleArn :: Text
fieldLogLevel :: FieldLogLevel
excludeVerboseContent :: Maybe Bool
$sel:cloudWatchLogsRoleArn:LogConfig' :: LogConfig -> Text
$sel:fieldLogLevel:LogConfig' :: LogConfig -> FieldLogLevel
$sel:excludeVerboseContent:LogConfig' :: LogConfig -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"excludeVerboseContent" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
excludeVerboseContent,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"fieldLogLevel" Text -> FieldLogLevel -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= FieldLogLevel
fieldLogLevel),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"cloudWatchLogsRoleArn"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
cloudWatchLogsRoleArn
              )
          ]
      )