2 * Copyright 2018 Intel Corporation, Inc
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 var errLogger *log.Logger
25 var warnLogger *log.Logger
26 var infoLogger *log.Logger
28 // Init will be called by sms.go before any other packages use it
29 func Init(filePath string) {
31 errLogger = log.New(os.Stderr, "ERROR: ", log.Lshortfile|log.LstdFlags)
32 warnLogger = log.New(os.Stdout, "WARNING: ", log.Lshortfile|log.LstdFlags)
33 infoLogger = log.New(os.Stdout, "INFO: ", log.Lshortfile|log.LstdFlags)
37 f, err := os.Create(filePath)
39 log.Println("Unable to create a log file")
41 errLogger = log.New(os.Stderr, "ERROR: ", log.Lshortfile|log.LstdFlags)
42 warnLogger = log.New(os.Stdout, "WARNING: ", log.Lshortfile|log.LstdFlags)
43 infoLogger = log.New(os.Stdout, "INFO: ", log.Lshortfile|log.LstdFlags)
45 errLogger = log.New(f, "ERROR: ", log.Lshortfile|log.LstdFlags)
46 warnLogger = log.New(f, "WARNING: ", log.Lshortfile|log.LstdFlags)
47 infoLogger = log.New(f, "INFO: ", log.Lshortfile|log.LstdFlags)
51 // WriteError writes output to the writer we have
52 // defined durint its creation with ERROR prefix
53 func WriteError(msg string) {
55 errLogger.Println(msg)
59 // WriteWarn writes output to the writer we have
60 // defined durint its creation with WARNING prefix
61 func WriteWarn(msg string) {
62 if warnLogger != nil {
63 warnLogger.Println(msg)
67 // WriteInfo writes output to the writer we have
68 // defined durint its creation with INFO prefix
69 func WriteInfo(msg string) {
70 if infoLogger != nil {
71 infoLogger.Println(msg)