silvi-0.0.4: A generator for different kinds of logs.

CopyrightCopyright 2017 Daniel Cartwright
LicenseBSD3
Maintainerdcartwright@layer3com.com
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

Silvi.Tutorial

Contents

Description

 

Synopsis

Introduction

This library allows you to generate random logs, as well as easily construct any sort of log you might yourself want.

In general, when using silvi, you'll want the following language extensions:

{--}
{--}
{--}

And the following imports:

import Silvi.Random
import Silvi.Record

Defining Log Formats

-- It is easy to define a log. 
-- A log is represented as a type-level list consisting of different fields.

-- 'SimpleLog' represents a Log consisting of just an IPv4 address and a URL.
type SimpleLog = '[ FieldIp
                  , FieldUrl
                  ]

Generating Random Logs

-- 'randSimpleLog' now contains a SimpleLog with randomised inhabitants of the IPv4 and URL types.
randSimpleLog :: Gen (Rec Value as)
randSimpleLog = randLog @SimpleLog

-- 'main' will print out 1000 'SimpleLog's.
main :: IO ()
main = printMany 1000 randSimpleLog