-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PRESIDECMS-2715 Refactor database logging for Preside task managers
Move to separate log tables for individual log lines. This is more efficient to query and also to update with new logs. In addition, we hope to squash a behaviour we see with MySQL where disk space used is vastly greater than the data in the logs (we believe due to continuous updates to a clob field for the log lines).
- Loading branch information
1 parent
7131d33
commit cc1d231
Showing
12 changed files
with
281 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
system/preside-objects/taskmanager/taskmanager_adhoc_task_log_line.cfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Represents a line in a task manager task log | ||
* | ||
* @versioned false | ||
* @useCache false | ||
* @noLabel true | ||
* @nodatemodified true | ||
* @nodatecreated true | ||
*/ | ||
component extends="preside.system.base.SystemPresideObject" { | ||
property name="id" required=true type="numeric" dbtype="bigint" generator="increment"; | ||
|
||
property name="task" relationship="many-to-one" relatedto="taskmanager_adhoc_task" required=true ondelete="cascade"; | ||
|
||
property name="ts" required=true type="numeric" dbtype="bigint"; | ||
property name="severity" required=true type="numeric" dbtype="tinyint"; | ||
property name="line" required=true type="string" dbtype="longtext"; | ||
} |
18 changes: 18 additions & 0 deletions
18
system/preside-objects/taskmanager/taskmanager_task_history_log_line.cfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Represents a line in a task manager task log | ||
* | ||
* @versioned false | ||
* @useCache false | ||
* @noLabel true | ||
* @nodatemodified true | ||
* @nodatecreated true | ||
*/ | ||
component extends="preside.system.base.SystemPresideObject" { | ||
property name="id" required=true type="numeric" dbtype="bigint" generator="increment"; | ||
|
||
property name="history" relationship="many-to-one" relatedto="taskmanager_task_history" required=true ondelete="cascade"; | ||
|
||
property name="ts" required=true type="numeric" dbtype="bigint"; | ||
property name="severity" required=true type="numeric" dbtype="tinyint"; | ||
property name="line" required=true type="string" dbtype="longtext"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
component extends="coldbox.system.logging.AbstractAppender" { | ||
|
||
// CONSTRUCTOR | ||
public any function init( | ||
required string name | ||
, struct properties = {} | ||
, string layout = "" | ||
, numeric levelMin = 0 | ||
, numeric levelMax = 4 | ||
) output=false { | ||
return super.init( argumentCollection = arguments ); | ||
} | ||
|
||
// PUBLIC API METHODS | ||
public void function logMessage( required any logEvent ) output=false { | ||
var extraInfo = arguments.logEvent.getExtraInfo(); | ||
var taskRunId = extraInfo.taskRunId ?: ""; | ||
|
||
if ( !Len( Trim( taskRunId ) ) || !_setup( extraInfo ) ) { | ||
return; | ||
} | ||
|
||
var q = new Query(); | ||
q.setDatasource( variables._logInfo.dsn ); | ||
q.setSQL( variables._logInfo.sql ); | ||
q.addParam( name="task" , value=taskRunId , cfsqltype="cf_sql_varchar" ); | ||
q.addParam( name="ts" , value=_ts( arguments.logEvent.getTimestamp() ), cfsqltype="cf_sql_bigint" ); | ||
q.addParam( name="severity", value=arguments.logEvent.getSeverity() , cfsqltype="cf_sql_int" ); | ||
q.addParam( name="line" , value=arguments.logEvent.getMessage() , cfsqltype="cf_sql_varchar" ); | ||
q.execute(); | ||
} | ||
|
||
// private helpers | ||
private function _setup( extraInfo ) { | ||
if ( !StructKeyExists( variables, "_logInfo" ) ) { | ||
if ( !StructKeyExists( arguments.extraInfo, "taskHistoryDao" ) ) { | ||
return false; | ||
} | ||
|
||
var taskHistoryDao = arguments.extraInfo.taskHistoryDao ?: ""; | ||
var adapter = taskHistoryDao.getDbAdapter(); | ||
var tableName = adapter.escapeEntity( taskHistoryDao.getTableName() ); | ||
var taskCol = adapter.escapeEntity( "task" ); | ||
var tsCol = adapter.escapeEntity( "ts" ); | ||
var severityCol = adapter.escapeEntity( "severity" ); | ||
var lineCol = adapter.escapeEntity( "line" ); | ||
|
||
variables._logInfo = { | ||
sql = "insert into #tableName# ( #taskCol#, #tsCol#, #severityCol#, #lineCol# ) values ( :task, :ts, :severity, :line )" | ||
, dsn = taskHistoryDao.getDsn() | ||
}; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private function _ts( datetime ) { | ||
return DateDiff( 's', '1970-01-01 00:00:00', arguments.datetime ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.