...
 
Commits (2)
......@@ -438,7 +438,7 @@ func getRelatedPosts(db *sql.DB, postsIDArray []string) map[string][]map[string]
relatedPosts := make(map[string][]map[string]string, 0)
queryIDs := strings.Join(postsIDArray, ", ")
query := `SELECT blog_post.title, blog_post.slug, blog_category.slug,
blog_post_related_posts.from_post_id
blog_post_related_posts.to_post_id
FROM blog_post_related_posts
INNER JOIN blog_post
ON blog_post_related_posts.from_post_id = blog_post.id
......
......@@ -40,29 +40,36 @@ func main() {
prometheus.MustRegister(metrics.ResolverDurations)
/*
* Log everything to /var/log/graphql/all.log
* Logging
*/
log.SetFormatter(&log.JSONFormatter{})
file, err := os.OpenFile("/var/log/graphql/all.log", os.O_CREATE|os.O_WRONLY, 0666)
if err == nil {
log.SetOutput(file)
} else {
log.Info("Failed to log to file, using default stderr")
}
log.SetOutput(file)
log.SetLevel(log.DebugLevel)
var hostname string
b, err := ioutil.ReadFile("/etc/hostname")
if err != nil {
hostname = "no hostname"
if os.Getenv("LOG_OUTPUT") == "file" {
file, err := os.OpenFile("/var/log/graphql/all.log", os.O_CREATE|os.O_WRONLY, 0666)
if err == nil {
log.SetOutput(file)
} else {
log.Info("Failed to log to file, using default stderr")
}
log.SetOutput(file)
var hostname string
b, err := ioutil.ReadFile("/etc/hostname")
if err != nil {
hostname = "no hostname"
} else {
hostname = string(b)
hostname = hostname[0 : len(hostname)-2]
}
logging.Log = log.WithFields(log.Fields{
"hostname": hostname,
"service": "graphql",
})
} else {
hostname = string(b)
hostname = hostname[0 : len(hostname)-2]
log.SetOutput(os.Stdout)
logging.Log = log.WithFields(log.Fields{
"service": "graphql",
})
}
logging.Log = log.WithFields(log.Fields{
"hostname": hostname,
"service": "graphql",
})
/*
* Handle requests
......