serverlog

package module
v0.0.0-...-594c4c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2016 License: MIT Imports: 10 Imported by: 10

README

Server Log v1.2.0

A thread safe logging system for servers. Serverlog can log to files and to the console(with pretty colours) depending on what you specify. Logfiles will be separated by dates and can also manage how many logfiles you want on the server at any one time.

Import

Go get the package like this

go get github.com/canopener/serverlog

Import like this

import "github.com/canopener/serverlog"

Usage

The package needs to be initialized. Use the Init function for this.

  1. Set the first parameter to true to enable logging to the console.

  2. Set the second Parameter to true to enable logging to a file.

  3. The third parameter represents the maximum amount of logfiles you wish to have at any one time. the logfiles are separated by days e.g "20-12-2015.csrv.log", "21-12-2015.csrv.log" etc.. Set to anything less than 1 if you want there to be no limit. The oldest logfiles will be deleted as new ones are created in order have only the amount of logfiles you specify here in the directory at any one time.

  4. The fourth parameter is the path to the directory in wich you wish to store the logfiles. You need to have read and write permissions to the directory in order for Serverlog to work. Serverlog needs to delete old logfiles to make sure that the third parameter is satisfied so make sure you dont put anything of value within this directory as it has a chance of being deleted

Note: if the second parameter is set to false the third and fourth can be random as they wont even be evaluated by serverlog.

serverlog.Init(true, true, 7, "/home/joe/logs/myServerLogs")

4 logging functions are available.

serverlog.Startup("server listening on port:", PORT) // for startup logging

serverlog.General("Accepted connection from:", conn.IP) // for general logging

serverlog.Warning(conn.IP, "sending lots of data, possibly DOS attack?")

serverlog.Fatal(conn.IP, "crashed the server! Kill all") // This will terminate the program with an exit code of 1

The logger can be terminated with :

serverlog.Kill()

When this happens the serverlog package needs to be initialized before it can log again.

Demo

Console Console Demo

Logfile File Demo

Log Directory Directory Demo

License

MIT License

Use however you want. A reference would be nice but not mandatory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fatal

func Fatal(args ...interface{})

Fatal is used to log something a server killing circumstance same as log.Fatalln() This will terminate the process with an exit code of 1

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf is used to log something a server killing circumstance Formats the text before sending it

func General

func General(args ...interface{})

General is used to log general stuff

func Generalf

func Generalf(format string, args ...interface{})

Generalf is used to log general stuff Formats the text before sending it

func Init

func Init(consolLog, fileLog bool, maxLogDays int, pathToLogDir string)

Init initialises the srvlog package. if either consoleLog or fileLog is true it will start the logger in another gorutine ready to log

func Kill

func Kill()

Kill will terminate the listener and logFileOverseer

func Startup

func Startup(args ...interface{})

Startup used to log the startup message example "Startup("Server listening on port:", PORT)"

func Startupf

func Startupf(format string, args ...interface{})

Startupf used to log the startup message Formats the text before sending it

func Warning

func Warning(args ...interface{})

Warning is used to log warnings

func Warningf

func Warningf(format string, args ...interface{})

Warningf is used to log warnings Formats the text before sending it

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL