package logger

import (
	"log"
	"os"
)

func Logger(s string) bool {
	var h string
	h, err := os.UserHomeDir()
	if err != nil {
		log.Fatal(err)
	}
	if s == "test" {
		os.Create("/var/tmp/PGMLOGTEST")
		file, err := os.OpenFile("/var/tmp/PGMLOGTEST", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
		if err != nil {
			log.Fatal(err)
		}
		log.SetOutput(file)
		log.Println("Hello world!")
		os.Remove("/var/tmp/PGMLOGTEST")
		return true
	}
	file, err := os.OpenFile(h + "/.pgm/logs/log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		log.Fatal(err)
		return false
	}

	log.SetOutput(file)
	log.Println(s)
	return true
}