Logging support module
Notes
- Uses Winston module for logging to file
- Uses Morgan for logging express web http requests
- Source:
- Copyright:
- 5/7/19
Methods
(inner) aliasWinstonLogger(categoryNew, categoryOld)
- Source:
Alias an existing category winston logger to another name. This can be useful when we want to mark different categories of log messages for POTENTIALLY different targets but use the same file for the time being
Parameters:
Name | Type | Description |
---|---|---|
categoryNew |
string | |
categoryOld |
string |
(private, inner) calcLogFilePath(fileSuffix)
- Source:
Given a base filename (typically the app or service name) and an optional suffix (when an app wants multiple log files for different purposes), calculate its full file path by adding base directory and .log extension.
Parameters:
Name | Type | Description |
---|---|---|
fileSuffix |
string |
Returns:
full file path
(private, inner) createLogFileObj(type, message, extraData, mergeData)
- Source:
Convert the parameters to an object suitable for logging. Merge in some of these fields and handle message differently depending on whether it is a string or object.
Parameters:
Name | Type | Description |
---|---|---|
type |
string | |
message |
string | (or object) |
extraData |
map | |
mergeData |
map |
Returns:
object to log
(private, inner) createWinstonLoggerObject(filename)
- Source:
Create a winston logger with out parameters and the filename suffix
Parameters:
Name | Type | Description |
---|---|---|
filename |
string |
Returns:
the new winston logger object
(private, inner) getWinstonCategoryLogger(category)
- Source:
Look up winston logger stored by category. Create it if it doesn't yet exist (and the store it)
Parameters:
Name | Type | Description |
---|---|---|
category |
string |
Returns:
the winston logger associated with this cateogry
(inner) log(category, …args)
- Source:
Passthrough log function to winston logger, to log an item to file created for a specific cateogry; creating category logger if it does not yet exist
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
category |
string |
|
|
args |
* |
<repeatable> |
Returns:
result of winston log command
(inner) logDefaultError(err)
- Source:
Simple default error log that sets category and type to error useful for calling from sources that don't know what to specify
Parameters:
Name | Type | Description |
---|---|---|
err |
string |
(inner) logExceptionError(category, err)
- Source:
Shortcut for logging an exception error
Parameters:
Name | Type | Description |
---|---|---|
category |
string | |
err |
error |
(inner) logExceptionErrorWithMessage(category, err, type, message, extraData, mergeData)
- Source:
Shortcut for logging an exception error, along with extra original message and parameters referenced by it
Parameters:
Name | Type | Description |
---|---|---|
category |
string | |
err |
error | |
type |
string | |
message |
string | (or object) |
extraData |
map | |
mergeData |
map |
(inner) logMessage(category, type, message, extraData, mergeData)
- Source:
Log a standard set of fields to a catgory. These are standard fields that our caller will use to log both to db and to file. We have a way of taking these fields and converting them to an object.
Parameters:
Name | Type | Description |
---|---|---|
category |
string | |
type |
string | in dot notation |
message |
string | (or object) |
extraData |
map | |
mergeData |
map |
(inner) logObject(category, obj)
- Source:
Main work function that asks the winston logger referred to by the category to log the object
Notes
- We always use the "info" level when writing to winston logs instead of winston logging level system; we use our own way to filter logs
Parameters:
Name | Type | Description |
---|---|---|
category |
string | |
obj |
object |
(inner) setup(iserviceName, ilogDir)
- Source:
Initialize values for the logging system to use
Parameters:
Name | Type | Description |
---|---|---|
iserviceName |
string | name of the application or process, for use in filename and console messages |
ilogDir |
string | base directory where log files should be created |
(inner) setupMorganMiddlewareForExpressWebAccessLogging()
- Source:
Setup the morgan logging middleware for express web framework, which is create an access file (like apache access log). Called by our server setup code when registering express middleware.
Returns:
the morgan middleware object to register with express
(inner) setupWinstonLogger(category, filenameSuffix)
- Source:
Setp the winston logging module and register our custom levels, etc. Save it in our local hash winstonCategoryLoggers where it can be referenced by category name
Parameters:
Name | Type | Description |
---|---|---|
category |
string | the category to store the new logger under |
filenameSuffix |
string | base filename (suffix added to our stored logfilename) |
Returns:
a winston logging object