From 81fa4969ce42d7d7ab69b2dc50ff33d443f96f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Er=C3=A8be?= Date: Sat, 27 Aug 2016 18:42:38 +0200 Subject: [PATCH] Maj Logger Former-commit-id: 4f92bde65f99832c5ae24ae6698c211e9f2bde18 Former-commit-id: f12ba4b2900a22043fe76735c912ae3fa205fe21 [formerly 24f48bf30c121d1466cfe329678f3620c1a77696 [formerly 24f48bf30c121d1466cfe329678f3620c1a77696 [formerly 24f48bf30c121d1466cfe329678f3620c1a77696 [formerly 9aeb97ec347b0a65a85f75b6d0ed93e3bd54dd53]]]] Former-commit-id: 1cb3fa8c9a953dedecb7d66c94cf914312b71a77 Former-commit-id: 092df44e5d7a9a560eadb4f186a77010df215837 Former-commit-id: 2f0d76ad50d96c6477564249b5b7cba9b84d0f33 Former-commit-id: a393fbcadcf6baa7515c5dfb2d7b1a3eb2cec58b [formerly c64d29b4305ce9be62bc46030750f8a627304d95] Former-commit-id: 2cd463763ae087b60e2008ca9e2aaa26284e8a42 --- app/Main.hs | 11 +++++------ src/Logger.hs | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) 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