mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Adopt to new loggin api
This commit is contained in:
@ -17,7 +17,6 @@ import docspell.store.queries.QLogin
|
||||
import docspell.store.records._
|
||||
import docspell.totp.{OnetimePassword, Totp}
|
||||
|
||||
import org.log4s.getLogger
|
||||
import org.mindrot.jbcrypt.BCrypt
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
@ -41,8 +40,6 @@ trait Login[F[_]] {
|
||||
}
|
||||
|
||||
object Login {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
case class Config(
|
||||
serverSecret: ByteVector,
|
||||
sessionValid: Duration,
|
||||
@ -93,7 +90,7 @@ object Login {
|
||||
def apply[F[_]: Async](store: Store[F], totp: Totp): Resource[F, Login[F]] =
|
||||
Resource.pure[F, Login[F]](new Login[F] {
|
||||
|
||||
private val logF = Logger.log4s(logger)
|
||||
private val logF = docspell.logging.getLogger[F]
|
||||
|
||||
def loginExternal(config: Config)(accountId: AccountId): F[Result] =
|
||||
for {
|
||||
@ -124,7 +121,7 @@ object Login {
|
||||
case Right(acc) =>
|
||||
for {
|
||||
data <- store.transact(QLogin.findUser(acc))
|
||||
_ <- Sync[F].delay(logger.trace(s"Account lookup: $data"))
|
||||
_ <- logF.trace(s"Account lookup: $data")
|
||||
res <-
|
||||
if (data.exists(check(up.pass))) doLogin(config, acc, up.rememberMe)
|
||||
else Result.invalidAuth.pure[F]
|
||||
|
@ -12,6 +12,7 @@ import cats.effect._
|
||||
import docspell.common._
|
||||
import docspell.ftsclient.FtsClient
|
||||
import docspell.ftsclient.TextData
|
||||
import docspell.logging.Logger
|
||||
import docspell.store.Store
|
||||
import docspell.store.queries.QAttachment
|
||||
import docspell.store.queries.QItem
|
||||
|
@ -14,6 +14,7 @@ import cats.implicits._
|
||||
import docspell.backend.fulltext.CreateIndex
|
||||
import docspell.backend.ops.OItem
|
||||
import docspell.common._
|
||||
import docspell.logging.Logger
|
||||
import docspell.store.Store
|
||||
import docspell.store.queries.QCustomField
|
||||
import docspell.store.queries.QCustomField.FieldValue
|
||||
|
@ -37,11 +37,9 @@ trait OClientSettings[F[_]] {
|
||||
}
|
||||
|
||||
object OClientSettings {
|
||||
private[this] val logger = org.log4s.getLogger
|
||||
|
||||
def apply[F[_]: Async](store: Store[F]): Resource[F, OClientSettings[F]] =
|
||||
Resource.pure[F, OClientSettings[F]](new OClientSettings[F] {
|
||||
val log = Logger.log4s[F](logger)
|
||||
val log = docspell.logging.getLogger[F]
|
||||
|
||||
private def getUserId(account: AccountId): OptionT[F, Ident] =
|
||||
OptionT(store.transact(RUser.findByAccount(account))).map(_.uid)
|
||||
|
@ -31,7 +31,6 @@ import docspell.store.records.RCustomFieldValue
|
||||
import docspell.store.records.RItem
|
||||
|
||||
import doobie._
|
||||
import org.log4s.getLogger
|
||||
|
||||
trait OCustomFields[F[_]] {
|
||||
|
||||
@ -153,7 +152,7 @@ object OCustomFields {
|
||||
): Resource[F, OCustomFields[F]] =
|
||||
Resource.pure[F, OCustomFields[F]](new OCustomFields[F] {
|
||||
|
||||
private[this] val logger = Logger.log4s[ConnectionIO](getLogger)
|
||||
private[this] val logger = docspell.logging.getLogger[ConnectionIO]
|
||||
|
||||
def findAllValues(itemIds: Nel[Ident]): F[List[FieldValue]] =
|
||||
store.transact(QCustomField.findAllValues(itemIds))
|
||||
@ -224,7 +223,7 @@ object OCustomFields {
|
||||
.transact(RItem.existsByIdsAndCollective(items, value.collective))
|
||||
.map(flag => if (flag) Right(()) else Left(SetValueResult.itemNotFound))
|
||||
)
|
||||
nu <- EitherT.right[SetValueResult](
|
||||
_ <- EitherT.right[SetValueResult](
|
||||
items
|
||||
.traverse(item => store.transact(RCustomField.setValue(field, item, fval)))
|
||||
.map(_.toList.sum)
|
||||
|
@ -14,7 +14,6 @@ import fs2.Stream
|
||||
import docspell.backend.JobFactory
|
||||
import docspell.backend.ops.OItemSearch._
|
||||
import docspell.common._
|
||||
import docspell.common.syntax.all._
|
||||
import docspell.ftsclient._
|
||||
import docspell.query.ItemQuery._
|
||||
import docspell.query.ItemQueryDsl._
|
||||
@ -23,8 +22,6 @@ import docspell.store.queue.JobQueue
|
||||
import docspell.store.records.RJob
|
||||
import docspell.store.{Store, qb}
|
||||
|
||||
import org.log4s.getLogger
|
||||
|
||||
trait OFulltext[F[_]] {
|
||||
|
||||
def findItems(maxNoteLen: Int)(
|
||||
@ -59,7 +56,6 @@ trait OFulltext[F[_]] {
|
||||
}
|
||||
|
||||
object OFulltext {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
case class FtsInput(
|
||||
query: String,
|
||||
@ -89,16 +85,17 @@ object OFulltext {
|
||||
joex: OJoex[F]
|
||||
): Resource[F, OFulltext[F]] =
|
||||
Resource.pure[F, OFulltext[F]](new OFulltext[F] {
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
def reindexAll: F[Unit] =
|
||||
for {
|
||||
_ <- logger.finfo(s"Re-index all.")
|
||||
_ <- logger.info(s"Re-index all.")
|
||||
job <- JobFactory.reIndexAll[F]
|
||||
_ <- queue.insertIfNew(job) *> joex.notifyAllNodes
|
||||
} yield ()
|
||||
|
||||
def reindexCollective(account: AccountId): F[Unit] =
|
||||
for {
|
||||
_ <- logger.fdebug(s"Re-index collective: $account")
|
||||
_ <- logger.debug(s"Re-index collective: $account")
|
||||
exist <- store.transact(
|
||||
RJob.findNonFinalByTracker(DocspellSystem.migrationTaskTracker)
|
||||
)
|
||||
@ -123,7 +120,7 @@ object OFulltext {
|
||||
FtsQuery.HighlightSetting(ftsQ.highlightPre, ftsQ.highlightPost)
|
||||
)
|
||||
for {
|
||||
_ <- logger.ftrace(s"Find index only: ${ftsQ.query}/$batch")
|
||||
_ <- logger.trace(s"Find index only: ${ftsQ.query}/$batch")
|
||||
folders <- store.transact(QFolder.getMemberFolders(account))
|
||||
ftsR <- fts.search(fq.withFolders(folders))
|
||||
ftsItems = ftsR.results.groupBy(_.itemId)
|
||||
|
@ -16,6 +16,7 @@ import docspell.backend.fulltext.CreateIndex
|
||||
import docspell.backend.item.Merge
|
||||
import docspell.common._
|
||||
import docspell.ftsclient.FtsClient
|
||||
import docspell.logging.Logger
|
||||
import docspell.notification.api.Event
|
||||
import docspell.store.queries.{QAttachment, QItem, QMoveAttachment}
|
||||
import docspell.store.queue.JobQueue
|
||||
@ -23,7 +24,6 @@ import docspell.store.records._
|
||||
import docspell.store.{AddResult, Store, UpdateResult}
|
||||
|
||||
import doobie.implicits._
|
||||
import org.log4s.getLogger
|
||||
|
||||
trait OItem[F[_]] {
|
||||
|
||||
@ -235,7 +235,7 @@ object OItem {
|
||||
otag <- OTag(store)
|
||||
oorg <- OOrganization(store)
|
||||
oequip <- OEquipment(store)
|
||||
logger <- Resource.pure[F, Logger[F]](Logger.log4s(getLogger))
|
||||
logger <- Resource.pure[F, Logger[F]](docspell.logging.getLogger[F])
|
||||
oitem <- Resource.pure[F, OItem[F]](new OItem[F] {
|
||||
|
||||
def merge(
|
||||
|
@ -59,7 +59,7 @@ object OJob {
|
||||
pubsub: PubSubT[F]
|
||||
): Resource[F, OJob[F]] =
|
||||
Resource.pure[F, OJob[F]](new OJob[F] {
|
||||
private[this] val logger = Logger.log4s(org.log4s.getLogger(OJob.getClass))
|
||||
private[this] val logger = docspell.logging.getLogger[F]
|
||||
|
||||
def queueState(collective: Ident, maxResults: Int): F[CollectiveQueueState] =
|
||||
store
|
||||
|
@ -9,13 +9,10 @@ package docspell.backend.ops
|
||||
import cats.effect.{Async, Resource}
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common.syntax.all._
|
||||
import docspell.common.{Ident, LenientUri, NodeType}
|
||||
import docspell.store.Store
|
||||
import docspell.store.records.RNode
|
||||
|
||||
import org.log4s._
|
||||
|
||||
trait ONode[F[_]] {
|
||||
|
||||
def register(appId: Ident, nodeType: NodeType, uri: LenientUri): F[Unit]
|
||||
@ -24,20 +21,19 @@ trait ONode[F[_]] {
|
||||
}
|
||||
|
||||
object ONode {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def apply[F[_]: Async](store: Store[F]): Resource[F, ONode[F]] =
|
||||
Resource.pure[F, ONode[F]](new ONode[F] {
|
||||
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
def register(appId: Ident, nodeType: NodeType, uri: LenientUri): F[Unit] =
|
||||
for {
|
||||
node <- RNode(appId, nodeType, uri)
|
||||
_ <- logger.finfo(s"Registering node ${node.id.id}")
|
||||
_ <- logger.info(s"Registering node ${node.id.id}")
|
||||
_ <- store.transact(RNode.set(node))
|
||||
} yield ()
|
||||
|
||||
def unregister(appId: Ident): F[Unit] =
|
||||
logger.finfo(s"Unregister app ${appId.id}") *>
|
||||
logger.info(s"Unregister app ${appId.id}") *>
|
||||
store.transact(RNode.delete(appId)).map(_ => ())
|
||||
})
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
|
||||
package docspell.backend.ops
|
||||
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
|
||||
import cats.data.OptionT
|
||||
import cats.data.{NonEmptyList => Nel}
|
||||
import cats.effect._
|
||||
@ -17,6 +14,7 @@ import cats.implicits._
|
||||
import docspell.backend.ops.ONotification.Hook
|
||||
import docspell.common._
|
||||
import docspell.jsonminiq.JsonMiniQuery
|
||||
import docspell.logging.{Level, LogEvent, Logger}
|
||||
import docspell.notification.api._
|
||||
import docspell.store.AddResult
|
||||
import docspell.store.Store
|
||||
@ -75,14 +73,13 @@ trait ONotification[F[_]] {
|
||||
}
|
||||
|
||||
object ONotification {
|
||||
private[this] val logger = org.log4s.getLogger
|
||||
|
||||
def apply[F[_]: Async](
|
||||
store: Store[F],
|
||||
notMod: NotificationModule[F]
|
||||
): Resource[F, ONotification[F]] =
|
||||
Resource.pure[F, ONotification[F]](new ONotification[F] {
|
||||
val log = Logger.log4s[F](logger)
|
||||
val log = docspell.logging.getLogger[F]
|
||||
|
||||
def withUserId[A](
|
||||
account: AccountId
|
||||
@ -129,9 +126,9 @@ object ONotification {
|
||||
.map {
|
||||
case Right(res) => res
|
||||
case Left(ex) =>
|
||||
val ps = new StringWriter()
|
||||
ex.printStackTrace(new PrintWriter(ps))
|
||||
SendTestResult(false, Vector(s"${ex.getMessage}\n$ps"))
|
||||
val ev =
|
||||
LogEvent.of(Level.Error, "Failed sending sample event").addError(ex)
|
||||
SendTestResult(false, Vector(ev))
|
||||
}
|
||||
|
||||
def listChannels(account: AccountId): F[Vector[Channel]] =
|
||||
@ -316,5 +313,5 @@ object ONotification {
|
||||
} yield h
|
||||
}
|
||||
|
||||
final case class SendTestResult(success: Boolean, logMessages: Vector[String])
|
||||
final case class SendTestResult(success: Boolean, logEvents: Vector[LogEvent])
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ object OShare {
|
||||
emil: Emil[F]
|
||||
): OShare[F] =
|
||||
new OShare[F] {
|
||||
private[this] val logger = Logger.log4s[F](org.log4s.getLogger)
|
||||
private[this] val logger = docspell.logging.getLogger[F]
|
||||
|
||||
def findAll(
|
||||
collective: Ident,
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
package docspell.backend.ops
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
@ -14,8 +15,6 @@ import docspell.store.records.{RTotp, RUser}
|
||||
import docspell.store.{AddResult, Store, UpdateResult}
|
||||
import docspell.totp.{Key, OnetimePassword, Totp}
|
||||
|
||||
import org.log4s.getLogger
|
||||
|
||||
trait OTotp[F[_]] {
|
||||
|
||||
/** Return whether TOTP is enabled for this account or not. */
|
||||
@ -38,8 +37,6 @@ trait OTotp[F[_]] {
|
||||
}
|
||||
|
||||
object OTotp {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
sealed trait OtpState {
|
||||
def isEnabled: Boolean
|
||||
def isDisabled = !isEnabled
|
||||
@ -86,7 +83,7 @@ object OTotp {
|
||||
|
||||
def apply[F[_]: Async](store: Store[F], totp: Totp): Resource[F, OTotp[F]] =
|
||||
Resource.pure[F, OTotp[F]](new OTotp[F] {
|
||||
val log = Logger.log4s[F](logger)
|
||||
val log = docspell.logging.getLogger[F]
|
||||
|
||||
def initialize(accountId: AccountId): F[InitResult] =
|
||||
for {
|
||||
|
@ -14,13 +14,10 @@ import fs2.Stream
|
||||
|
||||
import docspell.backend.JobFactory
|
||||
import docspell.common._
|
||||
import docspell.common.syntax.all._
|
||||
import docspell.store.Store
|
||||
import docspell.store.queue.JobQueue
|
||||
import docspell.store.records._
|
||||
|
||||
import org.log4s._
|
||||
|
||||
trait OUpload[F[_]] {
|
||||
|
||||
def submit(
|
||||
@ -56,8 +53,6 @@ trait OUpload[F[_]] {
|
||||
}
|
||||
|
||||
object OUpload {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
case class File[F[_]](
|
||||
name: Option[String],
|
||||
advertisedMime: Option[MimeType],
|
||||
@ -117,7 +112,7 @@ object OUpload {
|
||||
joex: OJoex[F]
|
||||
): Resource[F, OUpload[F]] =
|
||||
Resource.pure[F, OUpload[F]](new OUpload[F] {
|
||||
|
||||
private[this] val logger = docspell.logging.getLogger[F]
|
||||
def submit(
|
||||
data: OUpload.UploadData[F],
|
||||
account: AccountId,
|
||||
@ -155,7 +150,7 @@ object OUpload {
|
||||
if (data.multiple) files.map(f => ProcessItemArgs(meta, List(f)))
|
||||
else Vector(ProcessItemArgs(meta, files.toList))
|
||||
jobs <- right(makeJobs(args, account, data.priority, data.tracker))
|
||||
_ <- right(logger.fdebug(s"Storing jobs: $jobs"))
|
||||
_ <- right(logger.debug(s"Storing jobs: $jobs"))
|
||||
res <- right(submitJobs(notifyJoex)(jobs))
|
||||
_ <- right(
|
||||
store.transact(
|
||||
@ -194,7 +189,7 @@ object OUpload {
|
||||
notifyJoex: Boolean
|
||||
)(jobs: Vector[RJob]): F[OUpload.UploadResult] =
|
||||
for {
|
||||
_ <- logger.fdebug(s"Storing jobs: $jobs")
|
||||
_ <- logger.debug(s"Storing jobs: $jobs")
|
||||
_ <- queue.insertAll(jobs)
|
||||
_ <- if (notifyJoex) joex.notifyAllNodes else ().pure[F]
|
||||
} yield UploadResult.Success
|
||||
@ -203,7 +198,7 @@ object OUpload {
|
||||
private def saveFile(
|
||||
accountId: AccountId
|
||||
)(file: File[F]): F[Option[ProcessItemArgs.File]] =
|
||||
logger.finfo(s"Receiving file $file") *>
|
||||
logger.info(s"Receiving file $file") *>
|
||||
file.data
|
||||
.through(
|
||||
store.fileRepo.save(
|
||||
|
@ -11,12 +11,10 @@ import cats.implicits._
|
||||
|
||||
import docspell.backend.PasswordCrypt
|
||||
import docspell.common._
|
||||
import docspell.common.syntax.all._
|
||||
import docspell.store.records.{RCollective, RInvitation, RUser}
|
||||
import docspell.store.{AddResult, Store}
|
||||
|
||||
import doobie.free.connection.ConnectionIO
|
||||
import org.log4s.getLogger
|
||||
|
||||
trait OSignup[F[_]] {
|
||||
|
||||
@ -29,10 +27,10 @@ trait OSignup[F[_]] {
|
||||
}
|
||||
|
||||
object OSignup {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def apply[F[_]: Async](store: Store[F]): Resource[F, OSignup[F]] =
|
||||
Resource.pure[F, OSignup[F]](new OSignup[F] {
|
||||
private[this] val logger = docspell.logging.getLogger[F]
|
||||
|
||||
def newInvite(cfg: Config)(password: Password): F[NewInviteResult] =
|
||||
if (cfg.mode == Config.Mode.Invite)
|
||||
@ -66,7 +64,7 @@ object OSignup {
|
||||
_ <-
|
||||
if (retryInvite(res))
|
||||
logger
|
||||
.fdebug(
|
||||
.debug(
|
||||
s"Adding account failed ($res). Allow retry with invite."
|
||||
) *> store
|
||||
.transact(
|
||||
|
Reference in New Issue
Block a user