{-# 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.AppMesh.Types.FileAccessLog
-- 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.AppMesh.Types.FileAccessLog where

import Amazonka.AppMesh.Types.LoggingFormat
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | An object that represents an access log file.
--
-- /See:/ 'newFileAccessLog' smart constructor.
data FileAccessLog = FileAccessLog'
  { -- | The specified format for the logs. The format is either @json_format@ or
    -- @text_format@.
    FileAccessLog -> Maybe LoggingFormat
format :: Prelude.Maybe LoggingFormat,
    -- | The file path to write access logs to. You can use @\/dev\/stdout@ to
    -- send access logs to standard out and configure your Envoy container to
    -- use a log driver, such as @awslogs@, to export the access logs to a log
    -- storage service such as Amazon CloudWatch Logs. You can also specify a
    -- path in the Envoy container\'s file system to write the files to disk.
    --
    -- >  <note> <p>The Envoy process must have write permissions to the path that you specify here. Otherwise, Envoy fails to bootstrap properly.</p> </note>
    FileAccessLog -> Text
path :: Prelude.Text
  }
  deriving (FileAccessLog -> FileAccessLog -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileAccessLog -> FileAccessLog -> Bool
$c/= :: FileAccessLog -> FileAccessLog -> Bool
== :: FileAccessLog -> FileAccessLog -> Bool
$c== :: FileAccessLog -> FileAccessLog -> Bool
Prelude.Eq, ReadPrec [FileAccessLog]
ReadPrec FileAccessLog
Int -> ReadS FileAccessLog
ReadS [FileAccessLog]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FileAccessLog]
$creadListPrec :: ReadPrec [FileAccessLog]
readPrec :: ReadPrec FileAccessLog
$creadPrec :: ReadPrec FileAccessLog
readList :: ReadS [FileAccessLog]
$creadList :: ReadS [FileAccessLog]
readsPrec :: Int -> ReadS FileAccessLog
$creadsPrec :: Int -> ReadS FileAccessLog
Prelude.Read, Int -> FileAccessLog -> ShowS
[FileAccessLog] -> ShowS
FileAccessLog -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FileAccessLog] -> ShowS
$cshowList :: [FileAccessLog] -> ShowS
show :: FileAccessLog -> String
$cshow :: FileAccessLog -> String
showsPrec :: Int -> FileAccessLog -> ShowS
$cshowsPrec :: Int -> FileAccessLog -> ShowS
Prelude.Show, forall x. Rep FileAccessLog x -> FileAccessLog
forall x. FileAccessLog -> Rep FileAccessLog x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FileAccessLog x -> FileAccessLog
$cfrom :: forall x. FileAccessLog -> Rep FileAccessLog x
Prelude.Generic)

-- |
-- Create a value of 'FileAccessLog' 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:
--
-- 'format', 'fileAccessLog_format' - The specified format for the logs. The format is either @json_format@ or
-- @text_format@.
--
-- 'path', 'fileAccessLog_path' - The file path to write access logs to. You can use @\/dev\/stdout@ to
-- send access logs to standard out and configure your Envoy container to
-- use a log driver, such as @awslogs@, to export the access logs to a log
-- storage service such as Amazon CloudWatch Logs. You can also specify a
-- path in the Envoy container\'s file system to write the files to disk.
--
-- >  <note> <p>The Envoy process must have write permissions to the path that you specify here. Otherwise, Envoy fails to bootstrap properly.</p> </note>
newFileAccessLog ::
  -- | 'path'
  Prelude.Text ->
  FileAccessLog
newFileAccessLog :: Text -> FileAccessLog
newFileAccessLog Text
pPath_ =
  FileAccessLog'
    { $sel:format:FileAccessLog' :: Maybe LoggingFormat
format = forall a. Maybe a
Prelude.Nothing,
      $sel:path:FileAccessLog' :: Text
path = Text
pPath_
    }

-- | The specified format for the logs. The format is either @json_format@ or
-- @text_format@.
fileAccessLog_format :: Lens.Lens' FileAccessLog (Prelude.Maybe LoggingFormat)
fileAccessLog_format :: Lens' FileAccessLog (Maybe LoggingFormat)
fileAccessLog_format = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FileAccessLog' {Maybe LoggingFormat
format :: Maybe LoggingFormat
$sel:format:FileAccessLog' :: FileAccessLog -> Maybe LoggingFormat
format} -> Maybe LoggingFormat
format) (\s :: FileAccessLog
s@FileAccessLog' {} Maybe LoggingFormat
a -> FileAccessLog
s {$sel:format:FileAccessLog' :: Maybe LoggingFormat
format = Maybe LoggingFormat
a} :: FileAccessLog)

-- | The file path to write access logs to. You can use @\/dev\/stdout@ to
-- send access logs to standard out and configure your Envoy container to
-- use a log driver, such as @awslogs@, to export the access logs to a log
-- storage service such as Amazon CloudWatch Logs. You can also specify a
-- path in the Envoy container\'s file system to write the files to disk.
--
-- >  <note> <p>The Envoy process must have write permissions to the path that you specify here. Otherwise, Envoy fails to bootstrap properly.</p> </note>
fileAccessLog_path :: Lens.Lens' FileAccessLog Prelude.Text
fileAccessLog_path :: Lens' FileAccessLog Text
fileAccessLog_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FileAccessLog' {Text
path :: Text
$sel:path:FileAccessLog' :: FileAccessLog -> Text
path} -> Text
path) (\s :: FileAccessLog
s@FileAccessLog' {} Text
a -> FileAccessLog
s {$sel:path:FileAccessLog' :: Text
path = Text
a} :: FileAccessLog)

instance Data.FromJSON FileAccessLog where
  parseJSON :: Value -> Parser FileAccessLog
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FileAccessLog"
      ( \Object
x ->
          Maybe LoggingFormat -> Text -> FileAccessLog
FileAccessLog'
            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
"format")
            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
"path")
      )

instance Prelude.Hashable FileAccessLog where
  hashWithSalt :: Int -> FileAccessLog -> Int
hashWithSalt Int
_salt FileAccessLog' {Maybe LoggingFormat
Text
path :: Text
format :: Maybe LoggingFormat
$sel:path:FileAccessLog' :: FileAccessLog -> Text
$sel:format:FileAccessLog' :: FileAccessLog -> Maybe LoggingFormat
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LoggingFormat
format
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
path

instance Prelude.NFData FileAccessLog where
  rnf :: FileAccessLog -> ()
rnf FileAccessLog' {Maybe LoggingFormat
Text
path :: Text
format :: Maybe LoggingFormat
$sel:path:FileAccessLog' :: FileAccessLog -> Text
$sel:format:FileAccessLog' :: FileAccessLog -> Maybe LoggingFormat
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe LoggingFormat
format seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
path

instance Data.ToJSON FileAccessLog where
  toJSON :: FileAccessLog -> Value
toJSON FileAccessLog' {Maybe LoggingFormat
Text
path :: Text
format :: Maybe LoggingFormat
$sel:path:FileAccessLog' :: FileAccessLog -> Text
$sel:format:FileAccessLog' :: FileAccessLog -> Maybe LoggingFormat
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"format" 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 LoggingFormat
format,
            forall a. a -> Maybe a
Prelude.Just (Key
"path" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
path)
          ]
      )