Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DCSG2900-ThreatTotal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Johannes Barstad
DCSG2900-ThreatTotal
Commits
aa528a75
Commit
aa528a75
authored
2 years ago
by
Odin K. Henriksen
Browse files
Options
Downloads
Patches
Plain Diff
Commenting
parent
d4c84aff
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
logs/logging.go
+41
-39
41 additions, 39 deletions
logs/logging.go
with
41 additions
and
39 deletions
logs/logging.go
+
41
−
39
View file @
aa528a75
package
logging
import
(
"log"
//"log/syslog"
"os"
"log"
//"log/syslog"
"os"
)
//Function to handle logging of errors to errorlog file with message
func
Logerror
(
err
error
,
msg
string
)
{
// log to custom file
LOG_FILE
:=
"./logs/errorlog"
// open log file
logFile
,
err
:=
os
.
OpenFile
(
LOG_FILE
,
os
.
O_APPEND
|
os
.
O_RDWR
|
os
.
O_CREATE
,
0644
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
defer
logFile
.
Close
()
// log to custom file
LOG_FILE
:=
"./logs/errorlog"
// open log file
logFile
,
err
:=
os
.
OpenFile
(
LOG_FILE
,
os
.
O_APPEND
|
os
.
O_RDWR
|
os
.
O_CREATE
,
0644
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
defer
logFile
.
Close
()
// Set log out put and enjoy :)
log
.
SetOutput
(
logFile
)
// optional: log date-time, filename, and line number
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
// Set log output file
log
.
SetOutput
(
logFile
)
// log date-time, filename
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
log
.
Println
(
msg
,
err
)
}
func
Loginfo
(
msg
string
){
//Function to handle information logging to infofile
func
Loginfo
(
msg
string
)
{
LOG_FILE
:=
"./logs/infolog"
// open log file
logFile
,
err
:=
os
.
OpenFile
(
LOG_FILE
,
os
.
O_APPEND
|
os
.
O_RDWR
|
os
.
O_CREATE
,
0644
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
defer
logFile
.
Close
()
// open log file
logFile
,
err
:=
os
.
OpenFile
(
LOG_FILE
,
os
.
O_APPEND
|
os
.
O_RDWR
|
os
.
O_CREATE
,
0644
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
defer
logFile
.
Close
()
// Set log out
put
and enjoy :)
log
.
SetOutput
(
logFile
)
// Set log output
log
.
SetOutput
(
logFile
)
// optional:
log date-time, filename
, and line number
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
//
log date-time, filename
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
log
.
Println
(
msg
)
}
//Function to handle error message display to file.
func
Logerrorinfo
(
msg
string
)
{
// log to custom file
LOG_FILE
:=
"./logs/errorlog"
// open log file
logFile
,
err
:=
os
.
OpenFile
(
LOG_FILE
,
os
.
O_APPEND
|
os
.
O_RDWR
|
os
.
O_CREATE
,
0644
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
defer
logFile
.
Close
()
// log to custom file
LOG_FILE
:=
"./logs/errorlog"
// open log file
logFile
,
err
:=
os
.
OpenFile
(
LOG_FILE
,
os
.
O_APPEND
|
os
.
O_RDWR
|
os
.
O_CREATE
,
0644
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
defer
logFile
.
Close
()
// Set log out
put
and enjoy
:)
log
.
SetOutput
(
logFile
)
// Set log output
file
:)
log
.
SetOutput
(
logFile
)
// optional:
log date-time, filename
, and line number
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
//
log date-time, filename
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
log
.
Println
(
msg
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment