about summary refs log tree commit diff stats
path: root/src/utils/eprint.nim
blob: b58bae77340c0db05d77f6ec9d8fda89e50db3ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{.used.}

template eprint0(s: varargs[string]) =
  {.cast(noSideEffect), cast(tags: []), cast(raises: []).}:
    var o = ""
    for i in 0 ..< s.len:
      if i != 0:
        o &= ' '
      o &= s[i]
    when nimVm:
      echo o
    else:
      o &= '\n'
      stderr.write(o)

when defined(release):
  func eprint*(s: varargs[string, `$`])
      {.deprecated: "eprint is for debugging only".} =
    eprint0(s)
else:
  func eprint*(s: varargs[string, `$`]) =
    eprint0(s)

func elog*(s: varargs[string, `$`]) =
  {.cast(noSideEffect), cast(tags: []), cast(raises: []).}:
    var f: File
    if not open(f, "a", fmAppend):
      return
    var o = ""
    for i in 0 ..< s.len:
      if i != 0:
        o &= ' '
      o &= s[i]
    o &= '\n'
    f.write(o)
    close(f)