Navigation Menu

Skip to content

Commit

Permalink
Move logChannel to package logging-hslogger
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jan 2, 2012
1 parent 36c75ed commit 0450e3f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
29 changes: 29 additions & 0 deletions logging-hslogger/src/Logging/HsLogger.hs
Expand Up @@ -17,3 +17,32 @@ hsLoggerSink m = HsLogger.logM channel level $(format "{linfo} - {message}")
INFO -> HsLogger.INFO INFO -> HsLogger.INFO
WARN -> HsLogger.WARNING WARN -> HsLogger.WARNING
ERROR -> HsLogger.ERROR ERROR -> HsLogger.ERROR

logChannel :: LogRecord -> String
logChannel m = $(format "{package}.{module_}")
where
loc = logLocation m
package = stripVersion $ locationPackage loc
module_ = locationModule loc

-- | Strip version string from given package name.
--
-- The package name @main@ is returned verbatim. If the package name is not
-- @main@, we assume that there is always a version string, delimited with a
-- @\'-\'@ from the package name. Behavior is unspecified for package names
-- that are neither @main@ nor have a version string.
--
-- Examples:
--
-- >>> stripVersion "main"
-- "main"
--
-- >>> stripVersion "foo-0.0.0"
-- "foo"
--
-- >>> stripVersion "foo-bar-0.0.0"
-- "foo-bar"
stripVersion :: String -> String
stripVersion p = case p of
"main" -> p
_ -> reverse $ tail $ dropWhile (/= '-') $ reverse p
2 changes: 0 additions & 2 deletions logging.cabal
Expand Up @@ -17,5 +17,3 @@ library
, format , format
exposed-modules: exposed-modules:
Logging Logging
other-modules:
Util
20 changes: 12 additions & 8 deletions src/Logging.hs
Expand Up @@ -5,15 +5,25 @@ module Logging (
, logInfo , logInfo
, logWarn , logWarn
, logError , logError

, LogRecord , LogRecord
, logChannel
, logLevel , logLevel
, logMessage , logMessage
, logLocation , logLocation
, formatLocation
, LogLevel (..) , LogLevel (..)

, Location
, locationFilename
, locationPackage
, locationModule
, locationLine
, locationColumn
, formatLocation

, setLogSink , setLogSink
, defaultLogSink , defaultLogSink

, error , error
, undefined , undefined
) where ) where
Expand All @@ -31,12 +41,6 @@ import Data.IORef
import Foreign (unsafePerformIO) import Foreign (unsafePerformIO)


import Text.Format (formatS, format) import Text.Format (formatS, format)
import Util (stripVersion)

-- | Compatibility function for old LogRecord format
logChannel :: LogRecord -> String
logChannel m = let loc = logLocation m in
(stripVersion $ locationPackage loc) ++ "." ++ locationModule loc


data LogLevel = TRACE | DEBUG | INFO | WARN | ERROR data LogLevel = TRACE | DEBUG | INFO | WARN | ERROR
deriving (Eq, Show) deriving (Eq, Show)
Expand Down
23 changes: 0 additions & 23 deletions src/Util.hs

This file was deleted.

8 changes: 0 additions & 8 deletions test/Main.hs

This file was deleted.

1 change: 0 additions & 1 deletion test/run.sh
Expand Up @@ -2,5 +2,4 @@


cd "`dirname $0`" cd "`dirname $0`"


runhaskell -i../src Main.hs $*
runhaskell -i../src Spec.hs $* runhaskell -i../src Spec.hs $*

0 comments on commit 0450e3f

Please sign in to comment.