Skip to content

Commit

Permalink
Merge pull request #25 from herp-inc/tidyup
Browse files Browse the repository at this point in the history
recordLogを削除 etc
  • Loading branch information
fumieval authored Oct 5, 2022
2 parents e5ed098 + eba7ed3 commit 3a665be
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----

* recordLogを削除

v0.2
----

Expand Down
7 changes: 3 additions & 4 deletions herp-logger.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ library
Herp.Logger
Herp.Logger.LogLevel
Herp.Logger.Payload
Herp.Logger.SentryTransport
Herp.Logger.StdoutTransport
Herp.Logger.Transport
Herp.Logger.Transport.Sentry
Herp.Logger.Transport.Stdout
Herp.Logger.Transport.Types
Herp.Logger.ANSI.Coloring
hs-source-dirs:
src
Expand Down Expand Up @@ -79,7 +79,6 @@ library
, generic-data
, monad-logger
, mtl
, proto3-suite
, raven-haskell ==0.1.4.*
, resource-pool ^>= 0.3
, safe-exceptions
Expand Down
27 changes: 2 additions & 25 deletions src/Herp/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module Herp.Logger
, defaultLoggerConfig
, logM
, logIO
, recordLog
, urgentLog
, Herp.Logger.flush
-- * Payload
Expand Down Expand Up @@ -49,12 +48,11 @@ import "resource-pool" Data.Pool
import "text" Data.Text.Encoding qualified as T
import Data.UnixTime (formatUnixTime, fromEpochTime)
import System.PosixCompat.Time (epochTime)
import "proto3-suite" Proto3.Suite.JSONPB qualified as JSONPB

import Herp.Logger.Payload as P
import Herp.Logger.LogLevel as X
import Herp.Logger.Transport as X
import Herp.Logger.StdoutTransport
import Herp.Logger.Transport.Types as X
import Herp.Logger.Transport.Stdout as X

import "text" Data.Text as Text
import "text" Data.Text.Encoding as Text
Expand Down Expand Up @@ -236,27 +234,6 @@ logM msg = do
flush :: forall r m. (MonadReader r m, HasLogger r, MonadIO m) => m ()
flush = asks toLogger >>= liftIO . loggerFlush

-- logging function for service log
recordLog :: (MonadIO m, JSONPB.ToJSONPB serviceLog) => Logger -> Text -> serviceLog -> m ()
recordLog logger msg serviceLog = do
let msgLevel = Informational -- datadogはloglevelを要求する
let Logger {push, timeCache} = logger
when (checkToLog logger msgLevel) $ do
let options =
JSONPB.jsonPBOptions
{ -- NOTE: BigQueryで扱いやすくするため、デフォルト値を省略せず、oneofは使わない
JSONPB.optEmitDefaultValuedFields = True,
JSONPB.optEmitNamedOneof = False
}
let value = JSONPB.toJSONPB serviceLog options
date <- liftIO timeCache
liftIO $ push TransportInput {
level = msgLevel
, date = BS.toShort date
, message = msg
, extra = "service" .= value
}

runLoggingT :: forall m a. Logger -> ML.LoggingT m a -> m a
runLoggingT logger (ML.LoggingT run) = run (toLoggerIO logger)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE OverloadedStrings #-}

module Herp.Logger.SentryTransport
module Herp.Logger.Transport.Sentry
( sentry
) where

Expand All @@ -18,7 +18,7 @@ import "raven-haskell" System.Log.Raven.Types
)
import "unordered-containers" Data.HashMap.Strict qualified as HashMap
import Herp.Logger.LogLevel qualified as Level (LogLevel(..))
import Herp.Logger.Transport (Transport(..), TransportInput(..))
import Herp.Logger.Transport.Types (Transport(..), TransportInput(..))


#if MIN_VERSION_aeson(2,0,0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{-# LANGUAGE CPP #-}

module Herp.Logger.StdoutTransport (
module Herp.Logger.Transport.Stdout (
stdoutTransport,
stdoutANSITransport,
) where

import Herp.Logger.LogLevel
import Herp.Logger.Transport
import Herp.Logger.Transport.Types
import "fast-logger" System.Log.FastLogger (LoggerSet, ToLogStr (toLogStr), flushLogStr, pushLogStrLn)

import "aeson" Data.Aeson ((.=))
Expand All @@ -18,13 +18,9 @@ import Data.Text.Encoding qualified as T
import Herp.Logger.ANSI.Coloring (coloringLogInfoStr)

#if MIN_VERSION_aeson(2,0,0)
import "aeson" Data.Aeson.Key (fromText)
import "aeson" Data.Aeson.KeyMap as KM
#else
import Data.HashMap.Strict qualified as KM
import Data.Text (Text)
fromText :: Text -> Text
fromText = id
#endif

stdoutTransport' :: Text -> (LoggerSet -> TransportInput -> IO ()) -> LoggerSet -> LogLevel -> Transport
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE PackageImports #-}

module Herp.Logger.Transport
module Herp.Logger.Transport.Types
( Transport(..)
, TransportInput(..)
) where
Expand Down

0 comments on commit 3a665be

Please sign in to comment.