Explorar o código

Do not strip the tag style any more, we can use it!

Lennart Grahl %!s(int64=6) %!d(string=hai) anos
pai
achega
40984a9c5e
Modificáronse 3 ficheiros con 6 adicións e 20 borrados
  1. 1 15
      src/helpers/logger.ts
  2. 1 1
      tests/service/log.js
  3. 4 4
      tests/ts/logger_helpers.ts

+ 1 - 15
src/helpers/logger.ts

@@ -221,23 +221,9 @@ export class MemoryLogger implements Logger {
      */
     public getRecords(): LogRecord[] {
         return this.records.map(([date, type, message, ...args]: LogRecord) => {
-            // Strip message formatting
+            // Trim first message (tag)
             if (message !== null && message !== undefined && message.constructor === String) {
-                let stripped = false;
-
-                // Strip first style formatting placeholder if any
-                message = message.replace(/%c/, () => {
-                    stripped = true;
-                    return '';
-                });
-
-                // Trim
                 message = message.trim();
-
-                // Remove next argument if stripped
-                if (stripped) {
-                    args.shift();
-                }
             }
             return [date, type, message, ...args];
         });

+ 1 - 1
tests/service/log.js

@@ -138,7 +138,7 @@ describe('LogService', function() {
                 .parse(JSON.stringify($service.memory.getRecords(), MemoryLogger.replacer))
                 .map((record) => record.slice(1))
             ).toEqual([
-                ['info', '[test]', 'test']
+                ['info', '%c[test]', style, 'test']
             ]);
         });
 

+ 4 - 4
tests/ts/logger_helpers.ts

@@ -329,11 +329,11 @@ describe('Logger Helpers', () => {
             expect(records[0]).toEqual(record);
         });
 
-        it("strips style formatting of the log record's message (tag)", () => {
+        it("trims the first log record's message (tag)", () => {
             const logger = new MemoryLogger();
 
-            // Ensure %c CSS style formatting placeholder and the following
-            // argument is being stripped.
+            // Ensure %c CSS style formatting placeholder remains but the tag
+            // is being trimmed.
             const args = [
                 null,
                 true,
@@ -347,7 +347,7 @@ describe('Logger Helpers', () => {
                 .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
                 .map((entry) => entry.slice(1));
             expect(records.length).toBe(1);
-            expect(records[0]).toEqual((['debug', 'test'] as any[]).concat(args));
+            expect(records[0]).toEqual((['debug', 'te%cst', 'color: #fff'] as any[]).concat(args));
         });
 
         it("ignores style formatting beyond the log record's message (args)", () => {