• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.0
/src/logger/FileLogger.ts
1
import { FileLoggerOptions, LoggerOptions } from "./LoggerOptions"
2
import { LogLevel, LogMessage } from "./Logger"
3
import appRootPath from "app-root-path"
1✔
4
import { QueryRunner } from "../query-runner/QueryRunner"
5
import { PlatformTools } from "../platform/PlatformTools"
1✔
6
import { AbstractLogger } from "./AbstractLogger"
1✔
7

8
/**
9
 * Performs logging of the events in TypeORM.
10
 * This version of logger logs everything into ormlogs.log file.
11
 */
12
export class FileLogger extends AbstractLogger {
1✔
13
    // -------------------------------------------------------------------------
14
    // Constructor
15
    // -------------------------------------------------------------------------
16

17
    constructor(
18
        options?: LoggerOptions,
19
        private fileLoggerOptions?: FileLoggerOptions,
1✔
20
    ) {
21
        super(options)
1✔
22
    }
23

24
    // -------------------------------------------------------------------------
25
    // Protected Methods
26
    // -------------------------------------------------------------------------
27

28
    /**
29
     * Write log to specific output.
30
     */
31
    protected writeLog(
32
        level: LogLevel,
33
        logMessage: LogMessage | LogMessage[],
34
        queryRunner?: QueryRunner,
35
    ) {
UNCOV
36
        const messages = this.prepareLogMessages(logMessage, {
×
37
            highlightSql: false,
38
            addColonToPrefix: false,
39
        })
40

UNCOV
41
        const strings: string[] = []
×
42

UNCOV
43
        for (const message of messages) {
×
UNCOV
44
            switch (message.type ?? level) {
×
45
                case "log":
46
                    strings.push(`[LOG]: ${message.message}`)
×
47
                    break
×
48

49
                case "schema-build":
50
                case "migration":
UNCOV
51
                    strings.push(String(message.message))
×
UNCOV
52
                    break
×
53

54
                case "info":
55
                    strings.push(`[INFO]: ${message.message}`)
×
56
                    break
×
57

58
                case "query":
UNCOV
59
                    strings.push(`[QUERY]: ${message.message}`)
×
UNCOV
60
                    break
×
61

62
                case "warn":
UNCOV
63
                    strings.push(`[WARN]: ${message.message}`)
×
UNCOV
64
                    break
×
65

66
                case "query-slow":
67
                    if (message.prefix === "execution time") {
×
68
                        continue
×
69
                    }
70

71
                    this.write(
×
72
                        `[SLOW QUERY: ${message.additionalInfo?.time} ms]: ${message.message}`,
73
                    )
74
                    break
×
75

76
                case "error":
77
                case "query-error":
78
                    if (message.prefix === "query failed") {
×
79
                        strings.push(`[FAILED QUERY]: ${message.message}`)
×
80
                    } else if (message.type === "query-error") {
×
81
                        strings.push(`[QUERY ERROR]: ${message.message}`)
×
82
                    } else {
83
                        strings.push(`[ERROR]: ${message.message}`)
×
84
                    }
85
                    break
×
86
            }
87
        }
88

UNCOV
89
        this.write(strings)
×
90
    }
91

92
    /**
93
     * Writes given strings into the log file.
94
     */
95
    protected write(strings: string | string[]) {
UNCOV
96
        strings = Array.isArray(strings) ? strings : [strings]
×
UNCOV
97
        const basePath = appRootPath.path + "/"
×
UNCOV
98
        let logPath = "ormlogs.log"
×
UNCOV
99
        if (this.fileLoggerOptions && this.fileLoggerOptions.logPath) {
×
UNCOV
100
            logPath = PlatformTools.pathNormalize(
×
101
                this.fileLoggerOptions.logPath,
102
            )
103
        }
UNCOV
104
        strings = (strings as string[]).map(
×
UNCOV
105
            (str) => "[" + new Date().toISOString() + "]" + str,
×
106
        )
UNCOV
107
        PlatformTools.appendFileSync(
×
108
            basePath + logPath,
109
            strings.join("\r\n") + "\r\n",
110
        ) // todo: use async or implement promises?
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc