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
29 f, err := os.OpenFile("sms.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
31 log.Println("Unable to create a log file")
33 errLogger = log.New(os.Stderr, "ERROR: ", log.Lshortfile)
34 warnLogger = log.New(os.Stdout, "WARNING: ", log.Lshortfile)
35 infoLogger = log.New(os.Stdout, "INFO: ", log.Lshortfile)
37 errLogger = log.New(f, "ERROR: ", log.Lshortfile)
38 warnLogger = log.New(f, "WARNING: ", log.Lshortfile)
39 infoLogger = log.New(f, "INFO: ", log.Lshortfile)
43 // WriteError writes output to the writer we have
44 // defined durint its creation with ERROR prefix
45 func WriteError(msg string) {
47 errLogger.Println(msg)
51 // WriteWarn writes output to the writer we have
52 // defined durint its creation with WARNING prefix
53 func WriteWarn(msg string) {
54 if warnLogger != nil {
55 warnLogger.Println(msg)
59 // WriteInfo writes output to the writer we have
60 // defined durint its creation with INFO prefix
61 func WriteInfo(msg string) {
62 if infoLogger != nil {
63 infoLogger.Println(msg)