| Stability | experimental |
|---|---|
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
GHC.Eventlog.Socket
Description
This module exports the Haskell API for eventlog-socket.
To start streaming GHC eventlog events to a socket, use startWith with a socket address and options.
For instance, the following code starts eventlog-socket configured to wait for a connection and then stream events to /tmp/my_app.sock.
let addr =EventlogSocketUnixAddr"/tmp/my_app.sock" let opts =defaultEventlogSocketOpts{esoWait= True}startWithaddr opts
To register custom control commands, use registerNamespace and registerCommand.
For instance, the following code registers the namespace "ping" with one command at ID 1 that prints "Ping!" when called.
pingNamespace <-registerNamespace"ping" let pingId =CommandId1 let pingHandler = putStrLn "Ping!"registerCommandpingNamespace pingId pingHandler
Synopsis
- startWith :: EventlogSocketAddr -> EventlogSocketOpts -> IO ()
- data EventlogSocketAddr
- = EventlogSocketUnixAddr { }
- | EventlogSocketInetAddr { }
- data EventlogSocketOpts
- defaultEventlogSocketOpts :: EventlogSocketOpts
- startFromEnv :: IO ()
- fromEnv :: IO (Maybe (EventlogSocketAddr, EventlogSocketOpts))
- data EventlogSocketAddrError
- data Hook where
- pattern HookPostStartEventLogging :: Hook
- pattern HookPreEndEventLogging :: Hook
- type HookHandler = IO ()
- registerHook :: Hook -> HookHandler -> IO ()
- data Namespace
- newtype CommandId = CommandId Word8
- type CommandHandler = IO ()
- namespaceName :: Namespace -> IO String
- registerNamespace :: String -> IO Namespace
- registerCommand :: Namespace -> CommandId -> CommandHandler -> IO ()
- data EventlogSocketControlError
- testWorkerStatus :: IO ()
- testControlStatus :: IO ()
- startWait :: FilePath -> IO ()
- start :: FilePath -> IO ()
- wait :: IO ()
High-level API
startWith :: EventlogSocketAddr -> EventlogSocketOpts -> IO () Source #
Start an eventlog-socket writer using the given socket address and options.
Since: 0.1.2.0
Configuration types
data EventlogSocketAddr Source #
A type representing the supported eventlog socket modes.
Since: 0.1.2.0
Constructors
| EventlogSocketUnixAddr | |
Fields
| |
| EventlogSocketInetAddr | |
Fields
| |
Instances
| Show EventlogSocketAddr Source # | |
Defined in GHC.Eventlog.Socket Methods showsPrec :: Int -> EventlogSocketAddr -> ShowS # show :: EventlogSocketAddr -> String # showList :: [EventlogSocketAddr] -> ShowS # | |
| Eq EventlogSocketAddr Source # | |
Defined in GHC.Eventlog.Socket Methods (==) :: EventlogSocketAddr -> EventlogSocketAddr -> Bool # (/=) :: EventlogSocketAddr -> EventlogSocketAddr -> Bool # | |
data EventlogSocketOpts Source #
The socket options for eventlog-socket.
To construct an instance of the socket options, use defaultEventlogSocketOpts and the fields.
For instance:
myEventlogSocketOpts :: EventlogSocketOpts
myEventlogSocketOpts = defaultEventlogSocketOpts
{ esoWait = True
}
The following socket options are available:
esoWait::Bool- Whether or not to wait for a client to connect.
esoSndbuf~CInt- The size of the socket send buffer.
See the documentation for
SO_SNDBUFinsocket.h. esoLinger~CInt- The number of seconds to linger on shutdown.
See the documentation for
SO_LINGERinsocket.h.
Since: 0.1.2.0
Instances
| Show EventlogSocketOpts Source # | |
Defined in GHC.Eventlog.Socket Methods showsPrec :: Int -> EventlogSocketOpts -> ShowS # show :: EventlogSocketOpts -> String # showList :: [EventlogSocketOpts] -> ShowS # | |
| Eq EventlogSocketOpts Source # | |
Defined in GHC.Eventlog.Socket Methods (==) :: EventlogSocketOpts -> EventlogSocketOpts -> Bool # (/=) :: EventlogSocketOpts -> EventlogSocketOpts -> Bool # | |
Configuration via environment
startFromEnv :: IO () Source #
Read the eventlog socket configuration from the environment.
If this succeeds, start an eventlog-socket writer with that configuration.
Since: 0.1.2.0
fromEnv :: IO (Maybe (EventlogSocketAddr, EventlogSocketOpts)) Source #
Read the eventlog socket configuration from the environment.
Since: 0.1.2.0
data EventlogSocketAddrError Source #
The type of exceptions thrown by fromEnv.
Since: 0.1.2.0
Constructors
| EventlogSocketAddrUnixPathTooLong FilePath | The found Unix domain socket path was too long. |
| EventlogSocketAddrInetHostMissing String | No TCP/IP port number was found, but no host name was found. |
| EventlogSocketAddrInetPortMissing String | A TCP/IP host name was found, but no port number was found. |
Instances
| Exception EventlogSocketAddrError Source # | |
Defined in GHC.Eventlog.Socket | |
| Show EventlogSocketAddrError Source # | |
Defined in GHC.Eventlog.Socket Methods showsPrec :: Int -> EventlogSocketAddrError -> ShowS # show :: EventlogSocketAddrError -> String # showList :: [EventlogSocketAddrError] -> ShowS # | |
| Eq EventlogSocketAddrError Source # | |
Defined in GHC.Eventlog.Socket Methods (==) :: EventlogSocketAddrError -> EventlogSocketAddrError -> Bool # (/=) :: EventlogSocketAddrError -> EventlogSocketAddrError -> Bool # | |
Hooks
The type of eventlog-socket hooks.
Since: 0.1.3.0
Bundled Patterns
| pattern HookPostStartEventLogging :: Hook | The hook that runs after Since: 0.1.3.0 |
| pattern HookPreEndEventLogging :: Hook | The hook that runs before Since: 0.1.3.0 |
type HookHandler = IO () Source #
The type of hook handlers.
The hook handler is evaluated once each time the control socket receives a request for the associated hook.
Warning: The hook handler must not call back into the eventlog-socket API.
Since: 0.1.3.0
Arguments
| :: Hook | The hook. |
| -> HookHandler | The hook handler. |
| -> IO () |
Register an eventlog-socket hook.
Warning: Hooks cannot be unregistered and will be kept in memory until program exit.
Since: 0.1.3.0
Control commands
The type of namespaces.
Namespaces are opaque and can only be obtained using registerNamespace.
Since: 0.1.2.0
The type of command IDs.
Command IDs must be non-zero integers between 1 and 255.
Since: 0.1.2.0
type CommandHandler = IO () Source #
The type of command handlers.
The command handler is evaluated once each time the control socket receives a request for the associated command.
Warning: The command handler must not call back into the eventlog-socket API.
Since: 0.1.2.0
Register an eventlog-socket control namespace with the given name and returns an opaque Namespace object.
To avoid conflicts, the namespace should use the name of the Haskell package that registers the commands.
If the size of the given name exceeds 255 bytes, this function throws EventlogSocketControlNamespaceTooLong.
If a namespace is already registered under the given name, this function throws EventlogSocketControlNamespaceExists.
If the binary was built without support for control commands, this function throws EventlogSocketControlUnsupported.
Warning: Namespaces cannot be unregistered and will be kept in memory until program exit.
Since: 0.1.2.0
Arguments
| :: Namespace | The namespace. |
| -> CommandId | The command ID. |
| -> CommandHandler | The command handler. |
| -> IO () |
Register an eventlog-socket control command with the given ID and handler in the given namespace.
If a command is already registered under the given ID in the given namespace, this function throws EventlogSocketControlCommandExists.
If the binary was built without support for control commands, this function throws EventlogSocketControlUnsupported.
Warning: Commands cannot be unregistered and will be kept in memory until program exit.
Since: 0.1.2.0
data EventlogSocketControlError Source #
The type of exceptions thrown by registerNamespace and registerCommand.
Since: 0.1.2.0
Constructors
| EventlogSocketControlNamespaceTooLong | |
| EventlogSocketControlNamespaceExists | |
Fields
| |
| EventlogSocketControlCommandExists | |
| EventlogSocketControlUnsupported | |
Instances
| Exception EventlogSocketControlError Source # | |
Defined in GHC.Eventlog.Socket | |
| Show EventlogSocketControlError Source # | |
Defined in GHC.Eventlog.Socket Methods showsPrec :: Int -> EventlogSocketControlError -> ShowS # show :: EventlogSocketControlError -> String # showList :: [EventlogSocketControlError] -> ShowS # | |
| Eq EventlogSocketControlError Source # | |
Defined in GHC.Eventlog.Socket Methods (==) :: EventlogSocketControlError -> EventlogSocketControlError -> Bool # (/=) :: EventlogSocketControlError -> EventlogSocketControlError -> Bool # | |
Low-level API
testWorkerStatus :: IO () Source #
Test the current status of the worker thread. If it has failed, throw an IOException.
Since: 0.1.2.0
testControlStatus :: IO () Source #
Test the current status of the control thread. If it has failed, throw an IOException.
Since: 0.1.2.0
Legacy API
startWait :: FilePath -> IO () Source #
Start an eventlog-socket writer on the given Unix domain socket path and wait.
Since: 0.1.0.0