diff --git a/app/Main.hs b/app/Main.hs index 9c54475..5bc48a2 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -10,8 +10,8 @@ import qualified Data.ByteString.Char8 as BC import Data.Maybe (fromMaybe) import System.Console.CmdArgs import System.Environment (getArgs, withArgs) -import qualified System.Log.Logger as LOG +import qualified Logger import Tunnel import Types @@ -124,11 +124,10 @@ main = do cfg <- if null args then withArgs ["--help"] (cmdArgs cmdLine) else cmdArgs cmdLine let serverInfo = parseServerInfo (WsServerInfo False "" 0) (wsTunnelServer cfg) - LOG.updateGlobalLogger "wstunnel" (if quiet cfg - then LOG.setLevel LOG.ERROR - else if verbose cfg - then LOG.setLevel LOG.DEBUG - else LOG.setLevel LOG.INFO) + Logger.init (if quiet cfg then Logger.QUIET + else if verbose cfg + then Logger.VERBOSE + else Logger.NORMAL) if serverMode cfg diff --git a/src/Logger.hs b/src/Logger.hs index c597e64..c5b53a5 100644 --- a/src/Logger.hs +++ b/src/Logger.hs @@ -7,6 +7,14 @@ import Network.Socket (HostName, PortNumber) import qualified System.Log.Logger as LOG +data Verbosity = QUIET | VERBOSE | NORMAL + +init :: Verbosity -> IO () +init lvl = LOG.updateGlobalLogger "wstunnel" $ case lvl of + QUIET -> LOG.setLevel LOG.ERROR + VERBOSE -> LOG.setLevel LOG.DEBUG + NORMAL -> LOG.setLevel LOG.INFO + toStr :: (HostName, PortNumber) -> String toStr (host, port) = fromString host <> ":" <> show port