-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.hs
46 lines (43 loc) · 1.39 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Main
( main
) where
import qualified Data.Text as Text
import Rollbar.Client
import System.Environment (getArgs)
-- To load this example using Cabal, run:
--
-- ROLLBAR_TOKEN=<...> cabal repl --flags example client-example
--
-- Or, if using Stack, replace the Cabal part with:
--
-- stack ghci --flag rollbar-client:example rollbar-client:exe:client-example
--
-- You can then test creating a Rollbar item. If there are no arguments, the
-- example uses the 'withRollbar' function, which automatically creates a
-- Rollbar item after catching an exception:
--
-- >>> :main
-- *** Exception: Boom
-- CallStack (from HasCallStack):
-- error, called at .../rollbar-haskell/rollbar-client/example/Main.hs:39:30 in main:Main
--
-- If there are arguments, the example uses the 'runRollbar' function, which
-- allows us to create and send our own Rollbar items. In this case, we send
-- the arguments as message and change the level to warning:
--
-- >>> :main Warning!
-- ItemId "55c3e83084d943d6af3bf940e80513e1"
main :: IO ()
main = do
settings <- readSettings "rollbar.yaml"
args <- getArgs
case args of
[] ->
withRollbar settings $ error "Boom"
_ -> do
itemId <-
runRollbar settings $ do
let body = Text.pack (unwords args)
item <- mkItem (PayloadMessage (Message body mempty))
createItem item { itemLevel = Just LevelWarning }
print itemId