-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
141 lines (115 loc) · 3.1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/chembl/unichem2index/extractor"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
//Driver for Oracle database
_ "github.com/godror/godror"
)
var (
version string
buildDate string
logger *zap.SugaredLogger
config *extractor.Configuration
)
func logInit(d bool, logPath string) *os.File {
// now := time.Now()
// fn := fmt.Sprintf("unichem2index_%s.log", now.Format("20060102_150405"))
fn := "unichem2index.log"
path := filepath.Join(logPath, fn)
fmt.Println("Log path ", path)
// Open file for writing
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0777)
if err != nil {
panic(err)
}
pe := zap.NewProductionEncoderConfig()
pe.EncodeTime = zapcore.ISO8601TimeEncoder
fileEncoder := zapcore.NewJSONEncoder(pe)
level := zap.InfoLevel
if d {
level = zap.DebugLevel
}
core := zapcore.NewTee(
zapcore.NewCore(fileEncoder, zapcore.AddSync(file), level),
)
l := zap.New(core)
logger = l.Sugar()
return file
}
func main() {
cn := flag.String("config", "", "Config file path, must be YAML")
d := flag.Bool("d", false, "Sets up the log level to debug, keep in mind logging will have an impact on the performance")
v := flag.Bool("v", false, "Returns the binary version and built date info")
uFlag := flag.Bool("u", false, "Updates from the last UCI indexed, ignores the range given")
eh := flag.String("eshost", "", "ElasticSearch host, Example: http://0.0.0.0:9200")
oraconn := flag.String("oraconn", "", "Oracle Database connection string: Example: 'hr/hr@localhost:1521:XE'")
flag.Parse()
var err error
config, err = extractor.LoadConfig(*cn)
if err != nil {
fmt.Println(err)
panic("Couldn't load config.yml file")
}
f := logInit(*d, config.LogPath)
defer func(f *os.File) {
err := f.Close()
if err != nil {
m := "Error closing log file"
logger.Error(m)
}
}(f)
greeting()
if len(*eh) > 0 {
config.ElasticHost = *eh
} else if len(config.ElasticHost) <= 0 {
m := "Please provide an ElasticSearch host"
logger.Panic(m)
panic(m)
}
m := fmt.Sprintf("Elastic host %s", config.ElasticHost)
logger.Info(m)
fmt.Println(m)
if len(*oraconn) > 0 {
config.OracleConn = *oraconn
} else if len(config.OracleConn) <= 0 {
m := "Please provide an Oracle Connection string"
logger.Panic(m)
panic(m)
}
m = fmt.Sprintf("Oracle connection string %s", config.OracleConn)
logger.Info(m)
fmt.Println(m)
if *v {
return
}
if *uFlag {
extractor.Init(logger, config, true)
return
}
extractor.Init(logger, config, false)
}
func greeting() {
logger.Info("--------------Init program--------------")
logger.Info(fmt.Sprintf("Version: %s Build Date: %s", version, buildDate))
logger.Infow(
"Configuration",
"ES index",
config.Index,
"ES type",
config.Type,
"Query range",
config.QueryMax,
"Bulk limit",
config.BulkLimit,
"Maximum Bulk calls",
config.MaxBulkCalls,
)
fmt.Println("--------------Init program--------------")
fmt.Printf("Version: %s Build Date: %s \n", version, buildDate)
fmt.Printf("From %d to %d \n", config.QueryMax.Start, config.QueryMax.Finish)
}