Move the report_foo functions into their own module.
Get the process name automatically in init_logging.
name: htsn
-version: 0.0.3
+version: 0.0.4
cabal-version: >= 1.8
author: Michael Orlitzky
maintainer: Michael Orlitzky <michael@orlitzky.com>
CommandLine
Configuration
ExitCodes
+ FeedHosts
Logging
OptionalConfiguration
+ Report
Terminal
- TSN.FeedHosts
- TSN.Xml
Unix
+ Xml
ghc-options:
-Wall
.PHONY : dist hlint
-$(BIN): src/*.hs src/TSN/*.hs
+$(BIN): src/*.hs
runghc Setup.hs clean
runghc Setup.hs configure --user --prefix=/
runghc Setup.hs build
import qualified OptionalConfiguration as OC (
OptionalConfiguration(..),
merge_maybes )
-import TSN.FeedHosts (FeedHosts(..))
+import FeedHosts (FeedHosts(..))
-- | The main configuration data type. This will be passed to most of
-- the important functions once it has been created.
-- instance is specific to TSN, even though otherwise it's just a
-- list of strings.
--
-module TSN.FeedHosts
+module FeedHosts
where
-- DC is needed only for the DCT.Configured instance of String.
where
import Control.Monad ( when )
+import System.Environment ( getProgName )
import System.Log.Formatter ( simpleLogFormatter )
import System.Log.Handler ( setFormatter )
import System.Log.Handler.Simple ( GenericHandler, fileHandler )
sl_handler' <- openlog rootLoggerName [] USER sl_level
-- Syslog should output the date by itself.
- let sl_formatter = simpleLogFormatter "htsn[$pid] $prio: $msg"
+ program_name <- getProgName
+ let sl_formatter = simpleLogFormatter $
+ program_name ++ "[$pid] $prio: $msg"
let sl_handler = setFormatter sl_handler' sl_formatter
updateGlobalLogger rootLoggerName (addHandler sl_handler)
exit_no_password,
exit_no_username,
exit_pidfile_exists )
-import Logging (
- init_logging,
- log_debug,
- log_error,
- log_info,
- log_warning )
+import FeedHosts ( FeedHosts(..) )
+import Logging ( init_logging )
import qualified OptionalConfiguration as OC (
OptionalConfiguration(..),
from_rc )
-import Terminal (
- display_debug,
- display_error,
- display_info,
- display_sent,
- display_warning )
-import TSN.FeedHosts ( FeedHosts(..) )
-import TSN.Xml ( parse_xmlfid )
+import Report (
+ report_debug,
+ report_info,
+ report_warning,
+ report_error )
+import Terminal ( display_sent )
+import Xml ( parse_xmlfid )
import Unix ( full_daemonize )
--- | Display and log debug information. WARNING! This does not
--- automatically append a newline. The output is displayed/logged
--- as-is, for, you know, debug purposes.
-report_debug :: String -> IO ()
-report_debug s = do
- display_debug s
- log_debug s
-
-
--- | Display and log an error condition. This will prefix the error
--- with "ERROR: " when displaying (but not logging) it so that it
--- stands out.
---
-report_error :: String -> IO ()
-report_error s = do
- display_error $ "ERROR: " ++ s
- log_error s
-
-
--- | Display and log an informational (status) message.
---
-report_info :: String -> IO ()
-report_info s = do
- display_info s
- log_info s
-
-
--- | Display and log a warning. This will prefix the warning with
--- "WARNING: " when displaying (but not logging) it so that it
--- stands out.
---
-report_warning :: String -> IO ()
-report_warning s = do
- display_warning $ "WARNING: " ++ s
- log_warning s
-
-- | Receive a single line of text from a Handle, and send it to the
-- debug log.
import System.IO.Error ( catchIOError )
import System.Log ( Priority(..) )
+import FeedHosts ( FeedHosts(..) )
import Logging ( log_error ) -- Can't import report_error from Main
import Terminal ( display_error ) -- 'cause of circular imports.
-import TSN.FeedHosts ( FeedHosts(..) )
-- Derive standalone instances of Data and Typeable for Priority. This
--- /dev/null
+-- | Convenience functions for reporting (display and/or logging)
+-- status messages.
+--
+module Report (
+ report_debug,
+ report_error,
+ report_info,
+ report_warning )
+where
+
+import Logging (
+ log_debug,
+ log_error,
+ log_info,
+ log_warning )
+import Terminal (
+ display_debug,
+ display_error,
+ display_info,
+ display_warning )
+
+
+-- | Display and log debug information. WARNING! This does not
+-- automatically append a newline. The output is displayed/logged
+-- as-is, for, you know, debug purposes.
+report_debug :: String -> IO ()
+report_debug s = do
+ display_debug s
+ log_debug s
+
+
+-- | Display and log an error condition. This will prefix the error
+-- with "ERROR: " when displaying (but not logging) it so that it
+-- stands out.
+--
+report_error :: String -> IO ()
+report_error s = do
+ display_error $ "ERROR: " ++ s
+ log_error s
+
+
+-- | Display and log an informational (status) message.
+--
+report_info :: String -> IO ()
+report_info s = do
+ display_info s
+ log_info s
+
+
+-- | Display and log a warning. This will prefix the warning with
+-- "WARNING: " when displaying (but not logging) it so that it
+-- stands out.
+--
+report_warning :: String -> IO ()
+report_warning s = do
+ display_warning $ "WARNING: " ++ s
+ log_warning s
-- | Minimal XML functionality needed to parse each document's
-- XML_File_ID.
--
-module TSN.Xml (
+module Xml (
parse_xmlfid,
xml_tests )
where
import Test.Tasty ( TestTree, defaultMain )
-import TSN.Xml ( xml_tests )
+import Xml ( xml_tests )
tests :: TestTree
tests = xml_tests