@@ -4,17 +4,17 @@ import (
44 "context"
55 `encoding/json`
66 "fmt"
7+ "github.com/techrail/bark/config"
8+ "github.com/techrail/bark/resources"
9+ "github.com/techrail/bark/services/dbLogWriter"
10+ "github.com/techrail/bark/services/ingestion"
11+ "github.com/techrail/bark/utils"
712 "io"
813 "log/slog"
914 "os"
1015 "strings"
1116 "time"
1217
13- "github.com/techrail/bark/resources"
14- "github.com/techrail/bark/services/dbLogWriter"
15- "github.com/techrail/bark/services/ingestion"
16- "github.com/techrail/bark/utils"
17-
1818 "github.com/techrail/bark/appRuntime"
1919 "github.com/techrail/bark/constants"
2020 "github.com/techrail/bark/models"
@@ -607,13 +607,29 @@ func NewClient(url, defaultLogLvl, svcName, svcInstName string, enableSlog bool,
607607 }
608608}
609609
610- // NewClientWithServer returns a client config which performs the job of the server as well
610+ // NewClientWithServer returns a client config which performs the job of the server as well.
611+ // It is a wrapper around NewDirectToDbClientCustomSchemaTable with schema name set to a blank string
612+ func NewClientWithServer (dbUrl , defaultLogLvl , svcName , svcInstName string , enableSlog bool ) * Config {
613+ return NewDirectToDbClient (dbUrl , defaultLogLvl , svcName , svcInstName , enableSlog )
614+ }
615+
616+ func NewDirectToDbClient (dbUrl , defaultLogLvl , svcName , svcInstName string , enableSlog bool ) * Config {
617+ return NewDirectToDbClientCustomSchemaTable (dbUrl , "" , "" , defaultLogLvl , svcName , svcInstName , enableSlog )
618+ }
619+
620+ // NewDirectToDbClientCustomSchemaTable returns a client config which performs the job of the server as well
611621// It differs from NewClient in two main ways: it does not have the option to do bulk inserts (they are not needed)
612622// and it accepts the database URL instead of server URL.
613623//
614- // The url parameter is the database URL where the logs will be stored.
624+ // The dbUrl parameter is the database URL where the logs will be stored.
615625// It must be a valid postgresql protocol string.
616626//
627+ // The schemaName is the name of the schema (optional) where the postgresql table resides.
628+ // If the table is accessible without a schema name using the dbUrl connection, this can be left blank.
629+ //
630+ // The tableName is the name of the table where the logs are to be stored.
631+ // This is supposed to be set if your table is named anything other than `app_log`.
632+ //
617633// The defaultLogLvl parameter is the log level for logging. It must be one of the constants
618634// defined in the constants package, such as INFO, WARN, ERROR, etc. If an invalid value
619635// is given, the function will print a warning message and use INFO as the default level.
@@ -629,7 +645,7 @@ func NewClient(url, defaultLogLvl, svcName, svcInstName string, enableSlog bool,
629645// The enableSlog parameter is a boolean flag that indicates whether to enable slog logging
630646// to standard output. If true, the function will create and assign a new slog.Logger object
631647// to the Config object. If false, the Config object will have a nil Slogger field.
632- func NewClientWithServer (dbUrl , defaultLogLvl , svcName , svcInstName string , enableSlog bool ) * Config {
648+ func NewDirectToDbClientCustomSchemaTable (dbUrl , schemaName , tableName , defaultLogLvl , svcName , svcInstName string , enableSlog bool ) * Config {
633649 if ! isValid (defaultLogLvl ) {
634650 fmt .Printf ("L#1M1XXN - %v is not an acceptable log level. %v will be used as the default log level" , defaultLogLvl , constants .DefaultLogLevel )
635651 defaultLogLvl = constants .DefaultLogLevel
@@ -645,6 +661,9 @@ func NewClientWithServer(dbUrl, defaultLogLvl, svcName, svcInstName string, enab
645661 fmt .Printf ("L#1M1XZH - Blank instance name supplied. Using %v as Service Instance Name" , svcInstName )
646662 }
647663
664+ config .SetDbSchemaName (schemaName )
665+ config .SetDbTableName (tableName )
666+
648667 var slogger * slog.Logger
649668
650669 if enableSlog {
@@ -667,7 +686,7 @@ func NewClientWithServer(dbUrl, defaultLogLvl, svcName, svcInstName string, enab
667686 bld := models .NewBarkLogDao ()
668687 err = bld .InsertServerStartedLog ()
669688 if err != nil {
670- panic ("P#1LQ2YQ - Bark server start failed: " + err .Error ())
689+ panic ("P#20JFKK - Bark server start failed: " + err .Error ())
671690 }
672691
673692 // Start the server side
0 commit comments