on master help sign in
Zero pad date segments
fc65653Michael Xavier
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+5−2
@@ -75,6 +75,7 @@ import qualified Data.UUID.V4 as UUID4
75import Database.Bloodhound
75import Database.Bloodhound
76import Network.HTTP.Client
76import Network.HTTP.Client
77import Network.HTTP.Types.Status
77import Network.HTTP.Types.Status
78+import Text.Printf (printf)
78-------------------------------------------------------------------------------
79-------------------------------------------------------------------------------
79import Katip.Core
80import Katip.Core
80import Katip.Scribes.ElasticSearch.Annotations
81import Katip.Scribes.ElasticSearch.Annotations
@@ -231,8 +232,10 @@ chooseIxn (IndexName ixn) p i =
231
232
232
233
233-------------------------------------------------------------------------------
234-------------------------------------------------------------------------------
234−sis :: Show a => a -> IndexNameSegment
235+sis :: Integral a => a -> IndexNameSegment
235−sis = IndexNameSegment . T.pack . show
236+sis = IndexNameSegment . T.pack . fmt
237+ where
238+ fmt = printf "%02d" . toInteger
236
239
237
240
238-------------------------------------------------------------------------------
241-------------------------------------------------------------------------------
katip-elasticsearch/test/Main.hs+4−4
@@ -100,8 +100,8 @@ esTests = testGroup "elasticsearch scribe"
100 $(logT) (ExampleCtx True) mempty InfoS "tomorrow"
100 $(logT) (ExampleCtx True) mempty InfoS "tomorrow"
101 liftIO $ do
101 liftIO $ do
102 void done
102 void done
103− todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-1-2")
103+ todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-01-02")
104− tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-1-3")
104+ tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-01-03")
105 assertBool ("todayLogs has " <> show (length todayLogs) <> " items") (length todayLogs == 1)
105 assertBool ("todayLogs has " <> show (length todayLogs) <> " items") (length todayLogs == 1)
106 assertBool ("tomorrowLogs has " <> show (length tomorrowLogs) <> " items") (length tomorrowLogs == 1)
106 assertBool ("tomorrowLogs has " <> show (length tomorrowLogs) <> " items") (length tomorrowLogs == 1)
107 let logToday = head todayLogs
107 let logToday = head todayLogs
@@ -118,8 +118,8 @@ esTests = testGroup "elasticsearch scribe"
118 $(logT) (ExampleCtx True) mempty InfoS "tomorrow"
118 $(logT) (ExampleCtx True) mempty InfoS "tomorrow"
119 liftIO $ do
119 liftIO $ do
120 void done
120 void done
121− todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-2-28") -- rounds back to previous sunday
121+ todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-02-28") -- rounds back to previous sunday
122− tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-3-6") -- is on sunday, so uses current date
122+ tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-03-06") -- is on sunday, so uses current date
123 assertBool ("todayLogs has " <> show (length todayLogs) <> " items") (length todayLogs == 1)
123 assertBool ("todayLogs has " <> show (length todayLogs) <> " items") (length todayLogs == 1)
124 assertBool ("tomorrowLogs has " <> show (length tomorrowLogs) <> " items") (length tomorrowLogs == 1)
124 assertBool ("tomorrowLogs has " <> show (length tomorrowLogs) <> " items") (length tomorrowLogs == 1)
125 let logToday = head todayLogs
125 let logToday = head todayLogs