|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| -import { logger } from "firebase-functions"; |
17 | 16 | import config from "./config";
|
18 |
| -import { ChangeType } from "@firebaseextensions/firestore-bigquery-change-tracker"; |
| 17 | +import { |
| 18 | + ChangeType, |
| 19 | + Logger, |
| 20 | +} from "@firebaseextensions/firestore-bigquery-change-tracker"; |
| 21 | + |
| 22 | +export const logger = new Logger(); |
19 | 23 |
|
20 | 24 | export const arrayFieldInvalid = (fieldName: string) => {
|
21 | 25 | logger.warn(`Array field '${fieldName}' does not contain an array, skipping`);
|
22 | 26 | };
|
23 | 27 |
|
24 | 28 | export const bigQueryDatasetCreated = (datasetId: string) => {
|
25 |
| - logger.log(`Created BigQuery dataset: ${datasetId}`); |
| 29 | + logger.info(`Created BigQuery dataset: ${datasetId}`); |
26 | 30 | };
|
27 | 31 |
|
28 | 32 | export const bigQueryDatasetCreating = (datasetId: string) => {
|
29 |
| - logger.log(`Creating BigQuery dataset: ${datasetId}`); |
| 33 | + logger.debug(`Creating BigQuery dataset: ${datasetId}`); |
30 | 34 | };
|
31 | 35 |
|
32 | 36 | export const bigQueryDatasetExists = (datasetId: string) => {
|
33 |
| - logger.log(`BigQuery dataset already exists: ${datasetId}`); |
| 37 | + logger.info(`BigQuery dataset already exists: ${datasetId}`); |
34 | 38 | };
|
35 | 39 |
|
36 | 40 | export const bigQueryErrorRecordingDocumentChange = (e: Error) => {
|
37 | 41 | logger.error(`Error recording document changes.`, e);
|
38 | 42 | };
|
39 | 43 |
|
40 | 44 | export const bigQueryLatestSnapshotViewQueryCreated = (query: string) => {
|
41 |
| - logger.log(`BigQuery latest snapshot view query:\n${query}`); |
| 45 | + logger.info(`BigQuery latest snapshot view query:\n${query}`); |
42 | 46 | };
|
43 | 47 |
|
44 | 48 | export const bigQueryTableAlreadyExists = (
|
45 | 49 | tableName: string,
|
46 | 50 | datasetName: string
|
47 | 51 | ) => {
|
48 |
| - logger.log( |
| 52 | + logger.info( |
49 | 53 | `BigQuery table with name ${tableName} already ` +
|
50 | 54 | `exists in dataset ${datasetName}!`
|
51 | 55 | );
|
52 | 56 | };
|
53 | 57 |
|
54 | 58 | export const bigQueryTableCreated = (tableName: string) => {
|
55 |
| - logger.log(`Created BigQuery table: ${tableName}`); |
| 59 | + logger.info(`Created BigQuery table: ${tableName}`); |
56 | 60 | };
|
57 | 61 |
|
58 | 62 | export const bigQueryTableCreating = (tableName: string) => {
|
59 |
| - logger.log(`Creating BigQuery table: ${tableName}`); |
| 63 | + logger.debug(`Creating BigQuery table: ${tableName}`); |
60 | 64 | };
|
61 | 65 |
|
62 | 66 | export const bigQueryTableUpdated = (tableName: string) => {
|
63 |
| - logger.log(`Updated existing BigQuery table: ${tableName}`); |
| 67 | + logger.info(`Updated existing BigQuery table: ${tableName}`); |
64 | 68 | };
|
65 | 69 |
|
66 | 70 | export const bigQueryTableUpdating = (tableName: string) => {
|
67 |
| - logger.log(`Updating existing BigQuery table: ${tableName}`); |
| 71 | + logger.debug(`Updating existing BigQuery table: ${tableName}`); |
68 | 72 | };
|
69 | 73 |
|
70 | 74 | export const bigQueryTableUpToDate = (tableName: string) => {
|
71 |
| - logger.log(`BigQuery table: ${tableName} is up to date`); |
| 75 | + logger.info(`BigQuery table: ${tableName} is up to date`); |
72 | 76 | };
|
73 | 77 |
|
74 | 78 | export const bigQueryTableValidated = (tableName: string) => {
|
75 |
| - logger.log(`Validated existing BigQuery table: ${tableName}`); |
| 79 | + logger.info(`Validated existing BigQuery table: ${tableName}`); |
76 | 80 | };
|
77 | 81 |
|
78 | 82 | export const bigQueryTableValidating = (tableName: string) => {
|
79 |
| - logger.log(`Validating existing BigQuery table: ${tableName}`); |
| 83 | + logger.debug(`Validating existing BigQuery table: ${tableName}`); |
80 | 84 | };
|
81 | 85 |
|
82 | 86 | export const bigQueryUserDefinedFunctionCreating = (
|
83 | 87 | functionDefinition: string
|
84 | 88 | ) => {
|
85 |
| - logger.log(`Creating BigQuery User-defined Function:\n${functionDefinition}`); |
| 89 | + logger.debug( |
| 90 | + `Creating BigQuery User-defined Function:\n${functionDefinition}` |
| 91 | + ); |
86 | 92 | };
|
87 | 93 |
|
88 | 94 | export const bigQueryUserDefinedFunctionCreated = (
|
89 | 95 | functionDefinition: string
|
90 | 96 | ) => {
|
91 |
| - logger.log(`Created BigQuery User-defined Function:\n${functionDefinition}`); |
| 97 | + logger.info(`Created BigQuery User-defined Function:\n${functionDefinition}`); |
92 | 98 | };
|
93 | 99 |
|
94 | 100 | export const bigQueryViewCreated = (viewName: string) => {
|
95 |
| - logger.log(`Created BigQuery view: ${viewName}`); |
| 101 | + logger.info(`Created BigQuery view: ${viewName}`); |
96 | 102 | };
|
97 | 103 |
|
98 | 104 | export const bigQueryViewCreating = (viewName: string) => {
|
99 |
| - logger.log(`Creating BigQuery view: ${viewName}`); |
| 105 | + logger.debug(`Creating BigQuery view: ${viewName}`); |
100 | 106 | };
|
101 | 107 |
|
102 | 108 | export const bigQueryViewAlreadyExists = (
|
103 | 109 | viewName: string,
|
104 | 110 | datasetName: string
|
105 | 111 | ) => {
|
106 |
| - logger.log( |
| 112 | + logger.info( |
107 | 113 | `View with id ${viewName} already exists in dataset ${datasetName}.`
|
108 | 114 | );
|
109 | 115 | };
|
110 | 116 |
|
111 | 117 | export const bigQueryViewUpdated = (viewName: string) => {
|
112 |
| - logger.log(`Updated existing BigQuery view: ${viewName}`); |
| 118 | + logger.info(`Updated existing BigQuery view: ${viewName}`); |
113 | 119 | };
|
114 | 120 |
|
115 | 121 | export const bigQueryViewUpdating = (viewName: string) => {
|
116 |
| - logger.log(`Updating existing BigQuery view: ${viewName}`); |
| 122 | + logger.debug(`Updating existing BigQuery view: ${viewName}`); |
117 | 123 | };
|
118 | 124 |
|
119 | 125 | export const bigQueryViewUpToDate = (viewName: string) => {
|
120 |
| - logger.log(`BigQuery view: ${viewName} is up to date`); |
| 126 | + logger.info(`BigQuery view: ${viewName} is up to date`); |
121 | 127 | };
|
122 | 128 |
|
123 | 129 | export const bigQueryViewValidated = (viewName: string) => {
|
124 |
| - logger.log(`Validated existing BigQuery view: ${viewName}`); |
| 130 | + logger.info(`Validated existing BigQuery view: ${viewName}`); |
125 | 131 | };
|
126 | 132 |
|
127 | 133 | export const bigQueryViewValidating = (viewName: string) => {
|
128 |
| - logger.log(`Validating existing BigQuery view: ${viewName}`); |
| 134 | + logger.debug(`Validating existing BigQuery view: ${viewName}`); |
129 | 135 | };
|
130 | 136 |
|
131 | 137 | export const complete = () => {
|
132 |
| - logger.log("Completed execution of extension"); |
| 138 | + logger.info("Completed execution of extension"); |
133 | 139 | };
|
134 | 140 |
|
135 | 141 | export const dataInserted = (rowCount: number) => {
|
136 |
| - logger.log(`Inserted ${rowCount} row(s) of data into BigQuery`); |
| 142 | + logger.debug(`Inserted ${rowCount} row(s) of data into BigQuery`); |
137 | 143 | };
|
138 | 144 |
|
139 | 145 | export const dataInserting = (rowCount: number) => {
|
140 |
| - logger.log(`Inserting ${rowCount} row(s) of data into BigQuery`); |
| 146 | + logger.debug(`Inserting ${rowCount} row(s) of data into BigQuery`); |
141 | 147 | };
|
142 | 148 |
|
143 | 149 | export const dataTypeInvalid = (
|
@@ -171,11 +177,11 @@ export const error = (
|
171 | 177 | };
|
172 | 178 |
|
173 | 179 | export const init = () => {
|
174 |
| - logger.log("Initializing extension with configuration", config); |
| 180 | + logger.info("Initializing extension with configuration", config); |
175 | 181 | };
|
176 | 182 |
|
177 | 183 | export const start = () => {
|
178 |
| - logger.log("Started execution of extension with configuration", config); |
| 184 | + logger.info("Started execution of extension with configuration", config); |
179 | 185 | };
|
180 | 186 |
|
181 | 187 | export const timestampMissingValue = (fieldName: string) => {
|
@@ -218,3 +224,10 @@ export const logFailedEventAction = (
|
218 | 224 | error,
|
219 | 225 | });
|
220 | 226 | };
|
| 227 | + |
| 228 | +export const failedToWriteToBigQueryImmediately = (error: Error) => { |
| 229 | + logger.warn( |
| 230 | + "Failed to write event to BigQuery Immediately. Will attempt to Enqueue to Cloud Tasks.", |
| 231 | + error |
| 232 | + ); |
| 233 | +}; |
0 commit comments