Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
a3d469d3
Commit
a3d469d3
authored
Jul 28, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Barebone logging interface, to ease debugging
parent
bec99432
Pipeline
#4485
passed with stages
in 13 minutes and 4 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
3 deletions
+65
-3
Main.hs
bin/gargantext-server/Main.hs
+17
-3
gargantext.cabal
gargantext.cabal
+1
-0
Logging.hs
src/Gargantext/System/Logging.hs
+47
-0
No files found.
bin/gargantext-server/Main.hs
View file @
a3d469d3
...
...
@@ -16,15 +16,18 @@ Script to start gargantext with different modes (Dev, Prod, Mock).
{-# LANGUAGE Strict #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE TypeFamilies #-}
module
Main
where
import
Data.String
(
String
)
import
Data.Text
(
unpack
)
import
Data.Version
(
showVersion
)
import
Gargantext.API
(
startGargantext
,
Mode
(
..
))
-- , startGargantextMock)
import
Gargantext.Prelude
import
Gargantext.System.Logging
import
Options.Generic
import
System.Exit
(
exitSuccess
)
import
qualified
Paths_gargantext
as
PG
-- cabal magic build module
...
...
@@ -49,14 +52,25 @@ data MyOptions w =
instance
ParseRecord
(
MyOptions
Wrapped
)
deriving
instance
Show
(
MyOptions
Unwrapped
)
-- | A plain logger in the IO monad, waiting for more serious logging solutions like
-- the one described in https://gitlab.iscpif.fr/gargantext/haskell-gargantext/issues/229
instance
HasLogger
IO
where
data
instance
Logger
IO
=
IOLogger
type
instance
InitParams
IO
=
()
type
instance
Payload
IO
=
String
initLogger
=
\
()
->
pure
IOLogger
destroyLogger
=
\
_
->
pure
()
logMsg
=
\
IOLogger
lvl
msg
->
let
pfx
=
"["
<>
show
lvl
<>
"] "
in
putStrLn
$
pfx
<>
msg
main
::
IO
()
main
=
do
main
=
withLogger
()
$
\
ioLogger
->
do
MyOptions
myMode
myPort
myIniFile
myVersion
<-
unwrapRecord
"Gargantext server"
---------------------------------------------------------------
if
myVersion
then
do
putStrLn
$
"Version: "
<>
showVersion
PG
.
version
logMsg
ioLogger
INFO
$
"Version: "
<>
showVersion
PG
.
version
System
.
Exit
.
exitSuccess
else
return
()
...
...
@@ -73,6 +87,6 @@ main = do
let
start
=
case
myMode
of
Mock
->
panic
"[ERROR] Mock mode unsupported"
_
->
startGargantext
myMode
myPort'
(
unpack
myIniFile'
)
putStrLn
$
"Starting with "
<>
show
myMode
<>
" mode."
logMsg
ioLogger
INFO
$
"Starting with "
<>
show
myMode
<>
" mode."
start
---------------------------------------------------------------
gargantext.cabal
View file @
a3d469d3
...
...
@@ -117,6 +117,7 @@ library
Gargantext.Database.Query.Table.Node.UpdateOpaleye
Gargantext.Database.Query.Table.User
Gargantext.Database.Schema.Ngrams
Gargantext.System.Logging
Gargantext.Defaults
Gargantext.Utils.Jobs
Gargantext.Utils.Jobs.Internal
...
...
src/Gargantext/System/Logging.hs
0 → 100644
View file @
a3d469d3
{-# LANGUAGE TypeFamilies #-}
module
Gargantext.System.Logging
where
import
Prelude
import
Data.Kind
(
Type
)
import
Control.Monad.Trans.Control
import
Control.Exception.Lifted
(
bracket
)
data
Level
=
-- | Debug messages
DEBUG
-- | Information
|
INFO
-- | Normal runtime conditions
|
NOTICE
-- | General Warnings
|
WARNING
-- | General Errors
|
ERROR
-- | Severe situations
|
CRITICAL
-- | Take immediate action
|
ALERT
-- | System is unusable
|
EMERGENCY
deriving
(
Show
,
Eq
,
Ord
,
Enum
,
Bounded
)
-- | This is a barebore logging interface which we
-- can extend to plug a proper logging library, without
-- the details of the logger cropping up everywhere in
-- the rest of the codebase.
class
HasLogger
m
where
data
family
Logger
m
::
Type
type
family
InitParams
m
::
Type
type
family
Payload
m
::
Type
initLogger
::
InitParams
m
->
m
(
Logger
m
)
destroyLogger
::
Logger
m
->
m
()
logMsg
::
Logger
m
->
Level
->
Payload
m
->
m
()
-- | exception-safe combinator that creates and destroys a logger.
-- Think about it like a 'bracket' function from 'Control.Exception'.
withLogger
::
(
MonadBaseControl
IO
m
,
HasLogger
m
)
=>
InitParams
m
->
(
Logger
m
->
m
a
)
->
m
a
withLogger
params
=
bracket
(
initLogger
params
)
destroyLogger
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment