Skip to content

Migrate from Lwt_log to Logs #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(depends
(ocsipersist (= :version))
(lwt (>= 4.2.0))
lwt_log
logs
dbm))

(package
Expand All @@ -54,7 +54,7 @@
(ocaml (>= 4.08))
(ocsipersist (= :version))
(lwt (>= 4.2.0))
lwt_log
logs
pgocaml))

(package
Expand All @@ -72,7 +72,7 @@
(description "This library provides a SQLite backend for the unified key/value storage frontend as defined in the ocsipersist package.")
(depends
(lwt (>= 4.2.0))
lwt_log
logs
ocsipersist
sqlite3))

Expand Down
2 changes: 1 addition & 1 deletion ocsipersist-dbm.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ depends: [
"dune" {>= "2.8"}
"ocsipersist" {= version}
"lwt" {>= "4.2.0"}
"lwt_log"
"logs"
"dbm"
"odoc" {with-doc}
]
Expand Down
2 changes: 1 addition & 1 deletion ocsipersist-pgsql.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ depends: [
"ocaml" {>= "4.08"}
"ocsipersist" {= version}
"lwt" {>= "4.2.0"}
"lwt_log"
"logs"
"pgocaml"
"odoc" {with-doc}
]
Expand Down
2 changes: 1 addition & 1 deletion ocsipersist-sqlite.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
depends: [
"dune" {>= "2.8"}
"lwt" {>= "4.2.0"}
"lwt_log"
"logs"
"ocsipersist"
"sqlite3"
"odoc" {with-doc}
Expand Down
2 changes: 1 addition & 1 deletion src/dbm/dune
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ocsipersist_settings)
(libraries
dbm
lwt_log
logs
ocsipersist_dbmtypes
ocsipersist_lib
ocsipersist_dbm_settings))
Expand Down
32 changes: 17 additions & 15 deletions src/dbm/ocsipersist.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Lwt.Infix

module type TABLE = Ocsipersist_lib.Sigs.TABLE

let section = Lwt_log.Section.make "ocsigen:ocsipersist:dbm"
let section = Logs.Src.create "ocsigen:ocsipersist:dbm"

exception Ocsipersist_error

Expand All @@ -25,9 +25,9 @@ module Db = struct
Lwt_unix.connect socket (Unix.ADDR_UNIX sname) >>= fun () ->
Lwt.return socket)
(fun _ ->
Lwt_log.ign_warning_f ~section
"Launching a new Ocsidbm process: %s on directory %s."
!Config.ocsidbm !Config.directory;
Logs.warn ~src:section (fun fmt ->
fmt "Launching a new Ocsidbm process: %s on directory %s."
!Config.ocsidbm !Config.directory);
let param = [|!Config.ocsidbm; !Config.directory|] in
let child () =
let log =
Expand Down Expand Up @@ -63,14 +63,15 @@ module Db = struct
(fun e ->
if i = 0
then (
Lwt_log.ign_error_f ~section
"Cannot connect to Ocsidbm. Will continue without persistent session support. Error message is: %s .Have a look at the logs to see if there is an error message from the Ocsidbm process."
(match e with
| Unix.Unix_error (a, b, c) ->
Printf.sprintf "%a in %s(%s)"
(fun () -> Unix.error_message)
a b c
| _ -> Printexc.to_string e);
Logs.err ~src:section (fun fmt ->
fmt
"Cannot connect to Ocsidbm. Will continue without persistent session support. Error message is: %s .Have a look at the logs to see if there is an error message from the Ocsidbm process."
(match e with
| Unix.Unix_error (a, b, c) ->
Printf.sprintf "%a in %s(%s)"
(fun () -> Unix.error_message)
a b c
| _ -> Printexc.to_string e));
Lwt.fail e)
else Lwt_unix.sleep 2.1 >>= fun () -> get_indescr (i - 1))

Expand Down Expand Up @@ -327,8 +328,9 @@ type 'value table = 'value Polymorphic.table
let init () =
if !Ocsipersist_settings.delay_loading
then
Lwt_log.ign_warning ~section "Asynchronuous initialization (may fail later)"
else Lwt_log.ign_warning ~section "Initializing ...";
Logs.warn ~src:section (fun fmt ->
fmt "Asynchronuous initialization (may fail later)")
else Logs.warn ~src:section (fun fmt -> fmt "Initializing ...");
let indescr = Db.get_indescr 2 in
if !Ocsipersist_settings.delay_loading
then (
Expand All @@ -341,4 +343,4 @@ let init () =
Ocsipersist_settings.inch := Lwt.return (Lwt_io.of_fd ~mode:Lwt_io.input r);
Ocsipersist_settings.outch :=
Lwt.return (Lwt_io.of_fd ~mode:Lwt_io.output r);
Lwt_log.ign_warning ~section "...Initialization complete"
Logs.warn ~src:section (fun fmt -> fmt "...Initialization complete")
2 changes: 1 addition & 1 deletion src/pgsql/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(public_name ocsipersist-pgsql)
(implements ocsipersist)
(modules :standard \ ocsipersist_config ocsipersist_settings)
(libraries pgocaml lwt_log ocsipersist_lib ocsipersist_pgsql_settings))
(libraries pgocaml lwt.unix logs ocsipersist_lib ocsipersist_pgsql_settings))

; Configuration functions (part of ocsipersist-pgsql package):

Expand Down
7 changes: 4 additions & 3 deletions src/pgsql/ocsipersist.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module type TABLE = Ocsipersist_lib.Sigs.TABLE

let section = Lwt_log.Section.make "ocsigen:ocsipersist:pgsql"
let section = Logs.Src.create "ocsigen:ocsipersist:pgsql"

module Lwt_thread = struct
include Lwt
Expand Down Expand Up @@ -55,10 +55,11 @@ let use_pool f =
(fun () -> f db)
(function
| PGOCaml.Error msg as e ->
Lwt_log.ign_error_f ~section "postgresql protocol error: %s" msg;
Logs.err ~src:section (fun fmt ->
fmt "postgresql protocol error: %s" msg);
PGOCaml.close db >>= fun () -> Lwt.fail e
| Lwt.Canceled as e ->
Lwt_log.ign_error ~section "thread canceled";
Logs.err ~src:section (fun fmt -> fmt "thread canceled");
PGOCaml.close db >>= fun () -> Lwt.fail e
| e -> Lwt.fail e)

Expand Down
6 changes: 4 additions & 2 deletions src/pgsql/ocsipersist_config.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
let section = Lwt_log.Section.make "ocsigen:ocsipersist:pgsql:config"
let _ = Lwt_log.ign_info ~section "Init for Ocsigen Server config file"
let section = Logs.Src.create "ocsigen:ocsipersist:pgsql:config"

let _ =
Logs.info ~src:section (fun fmt -> fmt "Init for Ocsigen Server config file")

let parse_global_config = function
| [] -> ()
Expand Down
7 changes: 6 additions & 1 deletion src/sqlite/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
(public_name ocsipersist-sqlite)
(implements ocsipersist)
(modules ocsipersist)
(libraries sqlite3 lwt_log ocsipersist_lib ocsipersist_sqlite_settings))
(libraries
sqlite3
lwt.unix
logs
ocsipersist_lib
ocsipersist_sqlite_settings))

; Configuration functions (part of ocsipersist-sqlite package):

Expand Down
4 changes: 2 additions & 2 deletions src/sqlite/ocsipersist.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module type TABLE = Ocsipersist_lib.Sigs.TABLE

let section = Lwt_log.Section.make "ocsigen:ocsipersist:sqlite"
let section = Logs.Src.create "ocsigen:ocsipersist:sqlite"

open Lwt.Infix
open Sqlite3
Expand All @@ -24,7 +24,7 @@ module Aux = struct

let close_safely db =
if not (db_close db)
then Lwt_log.ign_error ~section "Couldn't close database"
then Logs.err ~src:section (fun fmt -> fmt "Couldn't close database")

let m = Mutex.create ()

Expand Down